From 4f88840e93cc1922b79c8580dff03194fcc52b07 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 18 Dec 2014 01:45:35 +0000 Subject: [PATCH] Fix use-after-free when patch outlives diff --- src/diff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diff.c b/src/diff.c index b8fcdab..d40c3e6 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; @@ -153,8 +153,8 @@ Patch_dealloc(Patch *self) Py_CLEAR(self->hunks); Py_CLEAR(self->old_id); Py_CLEAR(self->new_id); - /* We do not have to free old_file_path and new_file_path, they will - * be freed by git_diff_list_free in Diff_dealloc */ + free(self->old_file_path); + free(self->new_file_path); PyObject_Del(self); }