astropy/astropy — pull request #914 by mdboom (2013-03-28 14:24:51+00:00)
Title: Fix reference-counting bugs caught by cpychecker

This fixes a few reference-counting bugs caught by cpychecker.

http://gcc-python-plugin.readthedocs.org/en/latest/

Before we get too excited about this tool, note it still spews out a lot of false positives, and it crashes on certain input (`INCREF` ing the pointer to an extension type, for example, which is something you have to do when defining an extension type). It also doesn't seem to understand that when assigning a `PyObject *` to a member of an extension type that you may actually want to keep an extra reference around. There doesn't seem to be an annotation for that. So it's not ready to be part of our testing regimen, for example.

However, digging through all of the output, I was able to find a few things that, upon an error condition, would cause our code to leak memory. These are pretty hard to trigger bugs -- the error conditions mainly are "if the Python interpreter gets so tight on memory that it can't allocate a 2-tuple" (so extremely unlikely, and if happening we'd have much bigger problems).

Anyway, a fun and important project nonetheless.