diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-03-04 09:18:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-04 09:18:30 +0000 |
commit | 80bdeca4bd1a737ea01e1f9c6f51f88bfdd8695c (patch) | |
tree | 50acc559cdc7c8e89caacf2dc00aed0c790dc0b4 | |
parent | 1bc8dec4c65ee7c7a005c2773b381272a74fc254 (diff) | |
parent | b9bfe81292bfa77513193fd4ac75e9a1ab0ddc3b (diff) | |
download | libgit2-80bdeca4bd1a737ea01e1f9c6f51f88bfdd8695c.tar.gz |
Merge pull request #5817 from mamapanda/patch-2
Check git_signature_dup failure
-rw-r--r-- | src/blame.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/blame.c b/src/blame.c index 651b7a003..10e311aee 100644 --- a/src/blame.c +++ b/src/blame.c @@ -76,6 +76,14 @@ static git_blame_hunk* new_hunk( return hunk; } +static void free_hunk(git_blame_hunk *hunk) +{ + git__free((void*)hunk->orig_path); + git_signature_free(hunk->final_signature); + git_signature_free(hunk->orig_signature); + git__free(hunk); +} + static git_blame_hunk* dup_hunk(git_blame_hunk *hunk) { git_blame_hunk *newhunk = new_hunk( @@ -90,17 +98,14 @@ 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; - git_signature_dup(&newhunk->final_signature, hunk->final_signature); - git_signature_dup(&newhunk->orig_signature, hunk->orig_signature); - return newhunk; -} -static void free_hunk(git_blame_hunk *hunk) -{ - git__free((void*)hunk->orig_path); - git_signature_free(hunk->final_signature); - git_signature_free(hunk->orig_signature); - git__free(hunk); + if (git_signature_dup(&newhunk->final_signature, hunk->final_signature) < 0 || + git_signature_dup(&newhunk->orig_signature, hunk->orig_signature) < 0) { + free_hunk(newhunk); + return NULL; + } + + return newhunk; } /* Starting with the hunk that includes start_line, shift all following hunks' |