Commit a4803c3c by Patrick Steinhardt

grafts: fix memory leak if replacing pre-existing graft

If replacing an already existing graft in the grafts map, then we need
to free the previous `git_commit_graft` structure.
parent fd2398b2
......@@ -174,6 +174,8 @@ int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t paren
}
git_oid_cpy(&graft->oid, oid);
if ((error = git_grafts_remove(grafts, &graft->oid)) < 0 && error != GIT_ENOTFOUND)
goto cleanup;
if ((error = git_oidmap_set(grafts->commits, &graft->oid, graft)) < 0)
goto cleanup;
......@@ -198,6 +200,7 @@ int git_grafts_remove(git_grafts *grafts, const git_oid *oid)
if ((error = git_oidmap_delete(grafts->commits, oid)) < 0)
return error;
git__free(graft->parents.ptr);
git__free(graft);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment