<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 26, 2013 at 7:29 AM, Christian Heimes <span dir="ltr"><<a href="mailto:christian@python.org" target="_blank">christian@python.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am <a href="tel:26.07.2013%2014" value="+12607201314">26.07.2013 14</a>:56, schrieb Eli Bendersky:<br>
<div class="im">> Just a quick question - is there a chance to convince Coverity to detect<br>
> Python refcounting leaks in C API code :-) ? This could be useful not<br>
> only for Python but for extensions too. As it stands now, Coverity's<br>
> leak detection is Python must be pretty weak because almost everything<br>
> is done via PyObject refcounts.<br>
<br>
</div>Coverity is able to detect some cases of refcount leaks. I don't know if<br>
the software is able to keep track of all reference counts. But it<br>
understands missing Py_DECREF() in error branches.<br>
<br>
For example:<br>
<br>
PyObject *n = PyLong_FromLong(0);<br>
PyObject *u = PyUnicode_FromString("example");<br>
<br>
if (u == NULL) {<br>
return NULL;<br>
/* Coverity detects that 'n' leaks memory */<br>
}<br></blockquote><div><br></div><div>Interesting. <br><br>I was thinking of something more general though. Especially if we can mark function arguments and return values as stealing references / creating new ones / etc, many many common refcount bugs can be detected with static analysis. This is definitely research-y, probably too much for our current stage of relationship with Coverity :)<br>
<br>Eli <br></div><div><br><br><br> </div></div></div></div>