@@ -71,7 +71,6 @@ static PyObject *pyBwGetHeader(pyBigWigFile_t *self, PyObject *args) {
7171 if (PyDict_SetItemString (ret , "sumSquared" , val ) == -1 ) goto error ;
7272 Py_DECREF (val );
7373
74- Py_INCREF (ret );
7574 return ret ;
7675
7776error :
@@ -104,7 +103,6 @@ static PyObject *pyBwGetChroms(pyBigWigFile_t *self, PyObject *args) {
104103 }
105104 }
106105
107- Py_INCREF (ret );
108106 return ret ;
109107
110108error :
@@ -174,7 +172,6 @@ static PyObject *pyBwGetStats(pyBigWigFile_t *self, PyObject *args, PyObject *kw
174172 for (i = 0 ; i < nBins ; i ++ ) PyList_SetItem (ret , i , (isnan (val [i ]))?Py_None :PyFloat_FromDouble (val [i ]));
175173 free (val );
176174
177- Py_INCREF (ret );
178175 return ret ;
179176}
180177
@@ -217,7 +214,6 @@ static PyObject *pyBwGetValues(pyBigWigFile_t *self, PyObject *args) {
217214 for (i = 0 ; i < o -> l ; i ++ ) PyList_SetItem (ret , i , PyFloat_FromDouble (o -> value [i ]));
218215 bwDestroyOverlappingIntervals (o );
219216
220- Py_INCREF (ret );
221217 return ret ;
222218}
223219
@@ -267,7 +263,6 @@ static PyObject *pyBwGetIntervals(pyBigWigFile_t *self, PyObject *args, PyObject
267263 }
268264
269265 bwDestroyOverlappingIntervals (intervals );
270- Py_INCREF (ret );
271266 return ret ;
272267}
273268
@@ -277,6 +272,7 @@ PyMODINIT_FUNC PyInit_pyBigWig(void) {
277272 errno = 0 ; //just in case
278273
279274 if (PyType_Ready (& bigWigFile ) < 0 ) return NULL ;
275+ if (Py_AtExit (bwCleanup )) return NULL ;
280276 if (bwInit (128000 )) return NULL ;
281277 res = PyModule_Create (& pyBigWigmodule );
282278 if (!res ) return NULL ;
@@ -290,6 +286,7 @@ PyMODINIT_FUNC PyInit_pyBigWig(void) {
290286//Python2 initialization
291287PyMODINIT_FUNC initpyBigWig (void ) {
292288 errno = 0 ; //Sometimes libpython2.7.so is missing some links...
289+ if (Py_AtExit (bwCleanup )) return NULL ;
293290 if (PyType_Ready (& bigWigFile ) < 0 ) return ;
294291 if (bwInit (128000 )) return ; //This is temporary
295292 Py_InitModule3 ("pyBigWig" , bwMethods , "A module for handling bigWig files" );
0 commit comments