Skip to content

Commit c228eca

Browse files
committed
fix memory leak in device_read_many() and device_read()
1 parent 88a0673 commit c228eca

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

evdev/input.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ device_read(PyObject *self, PyObject *args)
6464
PyObject* sec = PyLong_FromLong(event.time.tv_sec);
6565
PyObject* usec = PyLong_FromLong(event.time.tv_usec);
6666
PyObject* val = PyLong_FromLong(event.value);
67+
PyObject* py_input_event = NULL;
68+
69+
py_input_event = Py_BuildValue("OOhhO", sec, usec, event.type, event.code, val);
70+
Py_DECREF(sec);
71+
Py_DECREF(usec);
72+
Py_DECREF(val);
6773

68-
return Py_BuildValue("OOhhO", sec, usec, event.type, event.code, val);
74+
return py_input_event;
6975
}
7076

7177

@@ -103,6 +109,11 @@ device_read_many(PyObject *self, PyObject *args)
103109

104110
py_input_event = Py_BuildValue("OOhhO", sec, usec, event[i].type, event[i].code, val);
105111
PyList_Append(event_list, py_input_event);
112+
113+
Py_DECREF(py_input_event);
114+
Py_DECREF(sec);
115+
Py_DECREF(usec);
116+
Py_DECREF(val);
106117
}
107118

108119
return event_list;

0 commit comments

Comments
 (0)