Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check git_signature_dup failure #5817

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'
Expand Down