Skip to content

Commit 490bd88

Browse files
committed
Fix reference leaks in blob filter stream and _cache_enums
Fixes #1481. Assisted-by: Kimi Code
1 parent 0ec0130 commit 490bd88

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
`Tree.diff_to_index()` on early error paths
2626
[#1480](https://github.com/libgit2/pygit2/issues/1480).
2727

28+
- Fix reference leaks in the blob filter stream callbacks and in
29+
`_cache_enums()`
30+
[#1481](https://github.com/libgit2/pygit2/issues/1481).
31+
2832

2933
# 1.20.0 (2026-08-08)
3034

src/blob.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static int blob_filter_stream_write(
190190
err = GIT_ERROR;
191191
goto done;
192192
}
193+
Py_DECREF(result);
193194
pos += chunk_size;
194195
}
195196

@@ -202,7 +203,7 @@ static int blob_filter_stream_close(git_writestream *s)
202203
{
203204
struct blob_filter_stream *stream = (struct blob_filter_stream *)s;
204205
PyGILState_STATE gil = PyGILState_Ensure();
205-
PyObject *result;
206+
PyObject *result = NULL;
206207
int err = 0;
207208

208209
/* Signal closed and then ready in that order so consumers can block on
@@ -214,13 +215,15 @@ static int blob_filter_stream_close(git_writestream *s)
214215
git_error_set(GIT_ERROR_OS, "failed to signal writer closed");
215216
err = GIT_ERROR;
216217
}
218+
Py_XDECREF(result);
217219
result = PyObject_CallMethod(stream->py_ready, "set", NULL);
218220
if (result == NULL)
219221
{
220222
PyErr_Clear();
221223
git_error_set(GIT_ERROR_OS, "failed to signal queue ready");
222224
err = GIT_ERROR;
223225
}
226+
Py_XDECREF(result);
224227

225228
PyGILState_Release(gil);
226229
return err;

src/pygit2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ _cache_enums(PyObject *self, PyObject *args)
407407

408408
#undef CACHE_PYGIT2_ENUM
409409

410+
Py_DECREF(enums);
410411
Py_RETURN_NONE;
411412

412413
fail:

0 commit comments

Comments
 (0)