segfault fix

This commit is contained in:
Devaev Maxim
2021-03-14 03:03:18 +03:00
parent bad05a6827
commit daaa488dd6

View File

@@ -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: