Le Fri, 26 Jul 2013 16:29:59 +0200, Christian Heimes <christ...@python.org> a écrit : > Coverity is able to detect some cases of refcount leaks. I don't know > if the software is able to keep track of all reference counts. But it > understands missing Py_DECREF() in error branches. > > For example: > > PyObject *n = PyLong_FromLong(0); > PyObject *u = PyUnicode_FromString("example"); > > if (u == NULL) { > return NULL; > /* Coverity detects that 'n' leaks memory */ > }
But 'n' doesn't leak memory since PyLong_FromLong(0) is statically allocated ;-) More generally, in similar cases (e.g. replace "0" with a non-small integer), you don't need any knowledge of reference counts to infer that there is a memory leak. When the code discards the only existing pointer to a heap-allocated memory area, there's a leak. What we call "refcount leaks" is generally when an area is still pointer-accessible, but failure to decrement the reference count appropriately means it will never be released. Regards Antoine. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com