Ticket #78: cwiid-0.6.00.self-wiimote.patch

File cwiid-0.6.00.self-wiimote.patch, 3.2 kB (added by insomniac, 3 years ago)

Patch for memory violation after the resources are released

  • python/Wiimote.c

    diff -Naur cwiid-0.6.00/python/Wiimote.c cwiid-0.6.00.new/python/Wiimote.c
    old new  
    250250 
    251251static PyObject *Wiimote_close(Wiimote *self) 
    252252{ 
     253        if (!self->wiimote) 
     254                return NULL; 
    253255        if (cwiid_close(self->wiimote)) { 
    254256                PyErr_SetString(PyExc_RuntimeError, 
    255257                                "Error closing wiimote connection"); 
     
    266268        static char *kwlist[] = {"flags", NULL}; 
    267269        int flags; 
    268270 
     271        if (!self->wiimote) 
     272                return NULL; 
    269273        if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:cwiid.Wiimote.enable", 
    270274                                         kwlist, &flags)) { 
    271275                return NULL; 
     
    284288        static char *kwlist[] = {"flags", NULL}; 
    285289        int flags; 
    286290 
     291        if (!self->wiimote) 
     292                return NULL; 
    287293        if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:cwiid.Wiimote.disable", 
    288294                                         kwlist, &flags)) { 
    289295                return NULL; 
     
    303309{ 
    304310        PyObject *OldCallback; 
    305311 
     312        if (!self->wiimote) 
     313                return NULL; 
    306314        if (!PyCallable_Check(NewCallback)) { 
    307315                PyErr_SetString(PyExc_TypeError, "callback must be callable!"); 
    308316        } 
     
    337345        struct timespec t; 
    338346        PyObject *PyMesg; 
    339347 
     348        if (!self->wiimote) 
     349                return NULL; 
    340350        if (cwiid_get_mesg(self->wiimote, &mesg_count, &mesg, &t)) { 
    341351                if (errno == EAGAIN) { 
    342352                        Py_RETURN_NONE; 
     
    360370        struct cwiid_state state; 
    361371        PyObject *PyState; 
    362372 
     373        if (!self->wiimote) 
     374                return NULL; 
    363375        if (cwiid_get_state(self->wiimote, &state)) { 
    364376                PyErr_SetString(PyExc_IOError, "get state error"); 
    365377                return NULL; 
    366378        } 
     379        if (!self->wiimote) 
     380                return NULL; 
    367381 
    368382        PyState = Py_BuildValue("{s:B,s:B,s:B,s:B,s:i,s:i}", 
    369383                                "rpt_mode", state.rpt_mode, 
     
    529543        int ext_type; 
    530544        struct acc_cal acc_cal; 
    531545        PyObject *PyAccCal; 
    532  
     546         
     547        if (!self->wiimote) 
     548                return NULL; 
    533549        if (!PyArg_ParseTupleAndKeywords(args, kwds, 
    534550                                         "i:cwiid.Wiimote.get_acc_cal", kwlist, 
    535551                                         &ext_type)) { 
     
    566582{ 
    567583        long led; 
    568584 
     585        if (!self->wiimote) 
     586                return NULL; 
    569587        if (((led = PyInt_AsLong(PyLed)) == -1) && PyErr_Occurred()) { 
    570588                return -1; 
    571589        } 
     
    584602{ 
    585603        long rumble; 
    586604 
     605        if (!self->wiimote) 
     606                return NULL; 
    587607        if (((rumble = PyInt_AsLong(PyRumble)) == -1) && PyErr_Occurred()) { 
    588608                return -1; 
    589609        } 
     
    602622{ 
    603623        long rpt_mode; 
    604624 
     625        if (!self->wiimote) 
     626                return NULL; 
    605627        if (((rpt_mode = PyInt_AsLong(PyRptMode)) == -1) && PyErr_Occurred()) { 
    606628                return -1; 
    607629        } 
     
    640662        void *buf; 
    641663        PyObject *pyRetBuf; 
    642664 
     665        if (!self->wiimote) 
     666                return NULL; 
    643667        if (!PyArg_ParseTupleAndKeywords(args, kwds, "BII:cwiid.Wiimote.read", 
    644668                                         kwlist, &flags, &offset, &len)) { 
    645669                return NULL; 
     
    669693        void *buf; 
    670694        int len; 
    671695 
     696        if (!self->wiimote) 
     697                return NULL; 
    672698        if (!PyArg_ParseTupleAndKeywords(args, kwds, "BIt#:cwiid.Wiimote.write", 
    673699                                         kwlist, &flags, &offset, &buf, &len)) { 
    674700                return NULL; 
     
    690716        PyObject *PySelf; 
    691717        PyGILState_STATE gstate; 
    692718 
     719        if (!wiimote) 
     720                return NULL; 
    693721        gstate = PyGILState_Ensure(); 
    694722 
    695723        ArgTuple = ConvertMesgArray(mesg_count, mesg);