[Python-Dev] [Python 2.4] PyInt_FromLong returning NULL (original) (raw)

Jim Fulton jim at zope.com
Tue Dec 7 20:19:43 CET 2004


Tim Peters wrote:

[Andreas Jung]

Sorry, false alarm :-( There assignment of the NULL occurs in the if-clause of the corresponding code (I have overseen the ASSIGN call): Thanks for the followup!

if (! PyIntCheck(p)) { if (PyDictCheck(p)) { if (PyStringCheck(name) || PyUnicodeCheck(name)) { ASSIGN(p, PyObjectGetItem(p, name)); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if (p == NULL) { puts("PyObject returned NULL"); PyErrClear(); } } else p = PyIntFromLong((long)1); ...doing some further investigations on that. I note that all of this is nested inside another "if (p) {...}" block. That implies the "p = PyIntFromLong((long)1);" line is at least a memory leak: it overwrites p without decref'ing p first.

The ASSIGN macro DECREFs it's first argument if it is non-NULL.

It loosly models a Python assignment, assuming that it owns the reference to the second argument.

Jim

-- Jim Fulton mailto:jim at zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org



More information about the Python-Dev mailing list