Skip to content

Commit 09665df

Browse files
ch3pjwhoefling
authored andcommitted
Improve memory cleanup
1 parent 73711a8 commit 09665df

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ static int PyXmlSec_MatchCB(const char* filename) {
194194
PyGILState_Release(state);
195195
return 1;
196196
}
197+
Py_XDECREF(result);
197198
cur_cb_list_item = cur_cb_list_item->next;
198199
}
199-
// FIXME: why does having this decref of args cause a segfault?!
200200
Py_DECREF(args);
201201
PyGILState_Release(state);
202202
return 0;
@@ -228,10 +228,10 @@ static int PyXmlSec_ReadCB(void* context, char* buffer, int len) {
228228
int result;
229229
if (py_bytes_read && PyLong_Check(py_bytes_read)) {
230230
result = (int)PyLong_AsLong(py_bytes_read);
231-
Py_DECREF(py_bytes_read);
232231
} else {
233232
result = EOF;
234233
}
234+
Py_XDECREF(py_bytes_read);
235235

236236
PyGILState_Release(state);
237237
return result;
@@ -331,18 +331,22 @@ static PyObject* PyXmlSec_PyIORegisterCallbacks(PyObject *self, PyObject *args,
331331
}
332332
if (!PyCallable_Check(cb_list_item->match_cb)) {
333333
PyErr_SetString(PyExc_TypeError, "input_match_callback must be a callable");
334+
free(cb_list_item);
334335
return NULL;
335336
}
336337
if (!PyCallable_Check(cb_list_item->open_cb)) {
337338
PyErr_SetString(PyExc_TypeError, "input_open_callback must be a callable");
339+
free(cb_list_item);
338340
return NULL;
339341
}
340342
if (!PyCallable_Check(cb_list_item->read_cb)) {
341343
PyErr_SetString(PyExc_TypeError, "input_read_callback must be a callable");
344+
free(cb_list_item);
342345
return NULL;
343346
}
344347
if (!PyCallable_Check(cb_list_item->close_cb)) {
345348
PyErr_SetString(PyExc_TypeError, "input_close_callback must be a callable");
349+
free(cb_list_item);
346350
return NULL;
347351
}
348352
Py_INCREF(cb_list_item->match_cb);

0 commit comments

Comments
 (0)