Skip to content

Commit 7bccfc8

Browse files
Nico von GeysoNico von Geyso
authored andcommitted
Fixed: Memleak in diff_get_patch_byindex()
There was a memleak because of a missing Py_DECREF. Thanks to @delanne
1 parent bdff1c3 commit 7bccfc8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/diff.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
6969
int err;
7070
Hunk *py_hunk = NULL;
7171
Patch *py_patch = NULL;
72+
PyObject *py_line_origin=NULL, *py_line=NULL;
7273

7374
err = git_diff_get_patch(&patch, &delta, list, idx);
7475
if (err < 0)
@@ -108,12 +109,16 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
108109
if (err < 0)
109110
goto cleanup;
110111

112+
py_line_origin = to_unicode_n(&line_origin, 1, NULL, NULL);
113+
py_line = to_unicode_n(line, line_len, NULL, NULL);
111114
PyList_SetItem(py_hunk->lines, j,
112115
Py_BuildValue("OO",
113-
to_unicode_n(&line_origin, 1, NULL, NULL),
114-
to_unicode_n(line, line_len, NULL, NULL)
116+
py_line_origin,
117+
py_line
115118
)
116119
);
120+
Py_DECREF(py_line_origin);
121+
Py_DECREF(py_line);
117122
}
118123

119124
PyList_SetItem((PyObject*) py_patch->hunks, i,

0 commit comments

Comments
 (0)