Skip to content

Commit

Permalink
Make Patch's allocation pattern more consistent
Browse files Browse the repository at this point in the history
Duplicate patch's filepaths instead of reusing the memory from the underlying git_patch*.
  • Loading branch information
garious committed Dec 22, 2014
1 parent 1ddb55e commit 4ff888b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ typedef struct {
unsigned additions;
unsigned deletions;
unsigned flags;
git_patch* patch;
} Patch;

typedef struct {
Expand Down

0 comments on commit 4ff888b

Please sign in to comment.