summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-11-12 19:02:28 -0800
committerBen Straub <bs@github.com>2013-11-12 19:02:28 -0800
commitb20c40a8d6127a3ee9b807b2243e41bc8e85124c (patch)
tree192113edc4da9f30b9b5ca1679db38f668ebbf96
parent9db56cc4a78ee7799450cd3838af12124ccc4e8e (diff)
downloadlibgit2-b20c40a8d6127a3ee9b807b2243e41bc8e85124c.tar.gz
Don't leak memory when duplicating a NULL signature
-rw-r--r--src/blame.c6
-rw-r--r--src/signature.c6
2 files changed, 7 insertions, 5 deletions
diff --git a/src/blame.c b/src/blame.c
index c5b7083ad..219a6bfe4 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -76,10 +76,8 @@ static git_blame_hunk* dup_hunk(git_blame_hunk *hunk)
git_oid_cpy(&newhunk->orig_commit_id, &hunk->orig_commit_id);
git_oid_cpy(&newhunk->final_commit_id, &hunk->final_commit_id);
newhunk->boundary = hunk->boundary;
- if (hunk->final_signature)
- newhunk->final_signature = git_signature_dup(hunk->final_signature);
- if (hunk->orig_signature)
- newhunk->orig_signature = git_signature_dup(hunk->orig_signature);
+ newhunk->final_signature = git_signature_dup(hunk->final_signature);
+ newhunk->orig_signature = git_signature_dup(hunk->orig_signature);
return newhunk;
}
diff --git a/src/signature.c b/src/signature.c
index 52ca2b375..ec51a42e9 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -84,8 +84,12 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
git_signature *git_signature_dup(const git_signature *sig)
{
- git_signature *new = git__calloc(1, sizeof(git_signature));
+ git_signature *new;
+ if (sig == NULL)
+ return NULL;
+
+ new = git__calloc(1, sizeof(git_signature));
if (new == NULL)
return NULL;