Skip to content

Commit 3a5c909

Browse files
committed
BUG: Fix some incorrect reference handling
1 parent f3b4511 commit 3a5c909

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/_macosx.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,11 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
28672867
PyObject* method = info;
28682868
PyGILState_STATE gstate = PyGILState_Ensure();
28692869
PyObject* result = PyObject_CallFunction(method, NULL);
2870-
if (result==NULL) PyErr_Print();
2870+
if (result) {
2871+
Py_DECREF(result);
2872+
} else {
2873+
PyErr_Print();
2874+
}
28712875
PyGILState_Release(gstate);
28722876
}
28732877

@@ -2923,6 +2927,7 @@ static void context_cleanup(const void* info)
29232927
PyErr_SetString(PyExc_ValueError, "Cannot interpret _single attribute as True of False");
29242928
return NULL;
29252929
}
2930+
Py_DECREF(attribute);
29262931
attribute = PyObject_GetAttrString((PyObject*)self, "_on_timer");
29272932
if (attribute==NULL)
29282933
{
@@ -2942,10 +2947,10 @@ static void context_cleanup(const void* info)
29422947
timer_callback,
29432948
&context);
29442949
if (!timer) {
2950+
Py_DECREF(attribute);
29452951
PyErr_SetString(PyExc_RuntimeError, "Failed to create timer");
29462952
return NULL;
29472953
}
2948-
Py_INCREF(attribute);
29492954
if (self->timer) {
29502955
CFRunLoopTimerInvalidate(self->timer);
29512956
CFRelease(self->timer);

0 commit comments

Comments
 (0)