Skip to content

Commit c596e9e

Browse files
authored
fix(query_cursor): fix reference leak in progress callback
query_cursor_progress_callback() leaked the Python callback's return value since PyObject_IsTrue() reads the object but does not consume the reference. The result is decref'd after computing the truth value.
1 parent 4f8872d commit c596e9e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tree_sitter/binding/query_cursor.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ PyObject *query_cursor_set_containing_point_range(QueryCursor *self, PyObject *a
9797
static bool query_cursor_progress_callback(TSQueryCursorState *state) {
9898
PyObject *result =
9999
PyObject_CallFunction((PyObject *)state->payload, "I", state->current_byte_offset);
100-
return PyObject_IsTrue(result);
100+
if (result == NULL) {
101+
return false;
102+
}
103+
int truth = PyObject_IsTrue(result);
104+
Py_DECREF(result);
105+
return truth > 0;
101106
}
102107

103108
PyObject *query_cursor_matches(QueryCursor *self, PyObject *args, PyObject *kwargs) {

0 commit comments

Comments
 (0)