mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-26 11:46:31 +00:00
trying to eliminate memory leaks
This commit is contained in:
@@ -29,10 +29,16 @@ typedef struct {
|
||||
uint8_t *tmp_data;
|
||||
size_t tmp_data_allocated;
|
||||
uint64_t last_id;
|
||||
|
||||
PyObject *frame; // PyDict
|
||||
} MemsinkObject;
|
||||
|
||||
|
||||
static void MemsinkObject_destroy_internals(MemsinkObject *self) {
|
||||
if (self->frame != NULL) {
|
||||
Py_DECREF(self->frame);
|
||||
self->frame = NULL;
|
||||
}
|
||||
if (self->mem != NULL) {
|
||||
munmap(self->mem, sizeof(memsink_shared_s));
|
||||
self->mem = NULL;
|
||||
@@ -96,6 +102,10 @@ static int MemsinkObject_init(MemsinkObject *self, PyObject *args, PyObject *kwa
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((self->frame = PyDict_New()) == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@@ -201,8 +211,8 @@ static PyObject *MemsinkObject_wait_frame(MemsinkObject *self, PyObject *Py_UNUS
|
||||
return PyErr_SetFromErrno(PyExc_OSError);
|
||||
}
|
||||
|
||||
PyObject *frame = PyDict_New();
|
||||
# define SET_VALUE(_field, _from, _to) PyDict_SetItemString(frame, #_field, Py##_to##_From##_from(tmp_##_field))
|
||||
PyDict_Clear(self->frame);
|
||||
# define SET_VALUE(_field, _from, _to) PyDict_SetItemString(self->frame, #_field, Py##_to##_From##_from(tmp_##_field))
|
||||
SET_VALUE(width, Long, Long);
|
||||
SET_VALUE(height, Long, Long);
|
||||
SET_VALUE(format, Long, Long);
|
||||
@@ -212,8 +222,8 @@ static PyObject *MemsinkObject_wait_frame(MemsinkObject *self, PyObject *Py_UNUS
|
||||
SET_VALUE(encode_begin_ts, Double, Float);
|
||||
SET_VALUE(encode_end_ts, Double, Float);
|
||||
# undef SET_VALUE
|
||||
PyDict_SetItemString(frame, "data", PyBytes_FromStringAndSize((const char *)self->tmp_data, tmp_used));
|
||||
return frame;
|
||||
PyDict_SetItemString(self->frame, "data", PyBytes_FromStringAndSize((const char *)self->tmp_data, tmp_used));
|
||||
return self->frame;
|
||||
}
|
||||
|
||||
static PyObject *MemsinkObject_is_opened(MemsinkObject *self, PyObject *Py_UNUSED(ignored)) {
|
||||
|
||||
Reference in New Issue
Block a user