@@ -147,6 +147,7 @@ ioctl_capabilities(PyObject *self, PyObject *args)
147147 // events e.g: {1: [272, 273, 274, 275], 2: [0, 1, 6, 8]}
148148 PyObject * capabilities = PyDict_New ();
149149 PyObject * eventcodes = NULL ;
150+ PyObject * evlong = NULL ;
150151 PyObject * capability = NULL ;
151152 PyObject * py_absinfo = NULL ;
152153 PyObject * absitem = NULL ;
@@ -181,23 +182,33 @@ ioctl_capabilities(PyObject *self, PyObject *args)
181182 absinfo .flat ,
182183 absinfo .resolution );
183184
184- absitem = Py_BuildValue ("(OO)" , PyLong_FromLong (ev_code ), py_absinfo );
185+ evlong = PyLong_FromLong (ev_code );
186+ absitem = Py_BuildValue ("(OO)" , evlong , py_absinfo );
185187
186188 // absitem -> tuple(ABS_X, (0, 255, 0, 0))
187189 PyList_Append (eventcodes , absitem );
190+
191+ Py_DECREF (absitem );
192+ Py_DECREF (py_absinfo );
188193 }
189194 else {
190- PyList_Append (eventcodes , PyLong_FromLong (ev_code ));
195+ evlong = PyLong_FromLong (ev_code );
196+ PyList_Append (eventcodes , evlong );
191197 }
198+
199+ Py_DECREF (evlong );
192200 }
193201 }
194202 // capabilities[EV_KEY] = [KEY_A, KEY_B, KEY_C, ...]
195203 // capabilities[EV_ABS] = [(ABS_X, (0, 255, 0, 0)), ...]
196204 PyDict_SetItem (capabilities , capability , eventcodes );
205+
206+ Py_DECREF (capability );
207+ Py_DECREF (eventcodes );
197208 }
198209 }
199210
200- return Py_BuildValue ( "O" , capabilities ) ;
211+ return capabilities ;
201212
202213 on_err :
203214 PyErr_SetFromErrno (PyExc_IOError );
@@ -210,7 +221,6 @@ static PyObject *
210221ioctl_devinfo (PyObject * self , PyObject * args )
211222{
212223 int fd ;
213- PyObject * capabilities = NULL ;
214224
215225 struct input_id iid ;
216226 char name [MAX_NAME_SIZE ];
@@ -224,14 +234,11 @@ ioctl_devinfo(PyObject *self, PyObject *args)
224234 if (ioctl (fd , EVIOCGID , & iid ) < 0 ) goto on_err ;
225235 if (ioctl (fd , EVIOCGNAME (sizeof (name )), name ) < 0 ) goto on_err ;
226236
227- // Get device capabilities
228- capabilities = ioctl_capabilities (self , Py_BuildValue ("(i)" , fd ));
229-
230237 // Some devices do not have a physical topology associated with them
231238 ioctl (fd , EVIOCGPHYS (sizeof (phys )), phys );
232239
233- return Py_BuildValue ("hhhhssO " , iid .bustype , iid .vendor , iid .product , iid .version ,
234- name , phys , capabilities );
240+ return Py_BuildValue ("hhhhss " , iid .bustype , iid .vendor , iid .product , iid .version ,
241+ name , phys );
235242
236243 on_err :
237244 PyErr_SetFromErrno (PyExc_IOError );
0 commit comments