From 4ff888bd471e8a5de2a9170aa487bf4a583b17e1 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Mon, 22 Dec 2014 18:50:24 +0000 Subject: [PATCH] Make Patch's allocation pattern more consistent Duplicate patch's filepaths instead of reusing the memory from the underlying git_patch*. --- src/diff.c | 8 ++++---- src/types.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/diff.c b/src/diff.c index 9bec1330b..7f69c920d 100644 --- a/src/diff.c +++ b/src/diff.c @@ -77,8 +77,8 @@ wrap_patch(git_patch *patch) delta = git_patch_get_delta(patch); - py_patch->old_file_path = delta->old_file.path; - py_patch->new_file_path = delta->new_file.path; + py_patch->old_file_path = strdup(delta->old_file.path); + py_patch->new_file_path = strdup(delta->new_file.path); py_patch->status = git_diff_status_char(delta->status); py_patch->similarity = delta->similarity; py_patch->flags = delta->flags; @@ -88,7 +88,6 @@ wrap_patch(git_patch *patch) git_patch_line_stats(NULL, &additions, &deletions, patch); py_patch->additions = additions; py_patch->deletions = deletions; - py_patch->patch = patch; hunk_amounts = git_patch_num_hunks(patch); py_patch->hunks = PyList_New(hunk_amounts); @@ -153,7 +152,8 @@ Patch_dealloc(Patch *self) Py_CLEAR(self->hunks); Py_CLEAR(self->old_id); Py_CLEAR(self->new_id); - git_patch_free(self->patch); + free(self->old_file_path); + free(self->new_file_path); PyObject_Del(self); } diff --git a/src/types.h b/src/types.h index f82667f3c..78747cf27 100644 --- a/src/types.h +++ b/src/types.h @@ -112,7 +112,6 @@ typedef struct { unsigned additions; unsigned deletions; unsigned flags; - git_patch* patch; } Patch; typedef struct {