From daaa488dd60d4ad431706a23f9e738976c759619 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sun, 14 Mar 2021 03:03:18 +0300 Subject: [PATCH] segfault fix --- python/ustreamer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/ustreamer.c b/python/ustreamer.c index e9edbbb..43deafb 100644 --- a/python/ustreamer.c +++ b/python/ustreamer.c @@ -59,10 +59,6 @@ typedef struct { static void MemsinkObject_destroy_internals(MemsinkObject *self) { - if (self->dict_frame != NULL) { - Py_DECREF(self->dict_frame); - self->dict_frame = NULL; - } if (self->mem != NULL) { munmap(self->mem, sizeof(memsink_shared_s)); self->mem = NULL; @@ -71,6 +67,10 @@ static void MemsinkObject_destroy_internals(MemsinkObject *self) { close(self->fd); self->fd = -1; } + if (self->dict_frame != NULL) { + Py_DECREF(self->dict_frame); + self->dict_frame = NULL; + } if (self->tmp_frame) { if (TMP(data)) { free(TMP(data)); @@ -108,6 +108,10 @@ static int MemsinkObject_init(MemsinkObject *self, PyObject *args, PyObject *kwa TMP(allocated) = 512 * 1024; A_REALLOC(TMP(data), TMP(allocated)); + if ((self->dict_frame = PyDict_New()) == NULL) { + goto error; + } + if ((self->fd = shm_open(self->obj, O_RDWR, 0)) == -1) { PyErr_SetFromErrno(PyExc_OSError); goto error; @@ -130,10 +134,6 @@ static int MemsinkObject_init(MemsinkObject *self, PyObject *args, PyObject *kwa goto error; } - if ((self->dict_frame = PyDict_New()) == NULL) { - goto error; - } - return 0; error: