Skip to content

Commit 4f88840

Browse files
committed
Fix use-after-free when patch outlives diff
1 parent ceb40ec commit 4f88840

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ wrap_patch(git_patch *patch)
7777

7878
delta = git_patch_get_delta(patch);
7979

80-
py_patch->old_file_path = delta->old_file.path;
81-
py_patch->new_file_path = delta->new_file.path;
80+
py_patch->old_file_path = strdup(delta->old_file.path);
81+
py_patch->new_file_path = strdup(delta->new_file.path);
8282
py_patch->status = git_diff_status_char(delta->status);
8383
py_patch->similarity = delta->similarity;
8484
py_patch->flags = delta->flags;
@@ -153,8 +153,8 @@ Patch_dealloc(Patch *self)
153153
Py_CLEAR(self->hunks);
154154
Py_CLEAR(self->old_id);
155155
Py_CLEAR(self->new_id);
156-
/* We do not have to free old_file_path and new_file_path, they will
157-
* be freed by git_diff_list_free in Diff_dealloc */
156+
free(self->old_file_path);
157+
free(self->new_file_path);
158158
PyObject_Del(self);
159159
}
160160

0 commit comments

Comments
 (0)