1. pygame
  2. pygame
  3. pygame
  4. Issues

Issues

Issue #30 resolved

Memory leak in surflock.c

René Dudfield
created an issue

== , 2009-04-14 12:31:07 -0700

{{{ This issue is in the surflock.c, not surface.c. I diagnosed it in 1.8.1, but a quick look at subversion shows that the relevant code has not changed.

The PySurface_LockBy function is leaking a weakref.ref each time a surface is locked. The weak reference is created on line 82 of surflock.c, and then is appended to the list on line 90. PyList_Append does not steal the reference, and so the reference count remains incremented even when PySurface_LockBy returns, causing a memory leak.

The solution is to add Py_DECREF(ref) as line 91 of surflock.c, making the function read:

static int PySurface_LockBy (PyObject surfobj, PyObject lockobj) { PyObject ref; PySurfaceObject surf = (PySurfaceObject*) surfobj;

if (!surf->locklist)
{
    surf->locklist = PyList_New (0);
    if (!surf->locklist)
        return 0;
}
ref = PyWeakref_NewRef (lockobj, NULL);
if (!ref)
    return 0;
if (ref == Py_None)
{
    Py_DECREF (ref);
    return 0;
}
PyList_Append (surf->locklist, ref);
Py_DECREF(ref);

if (surf->subsurface)
    PySurface_Prep (surfobj);
if (SDL_LockSurface (surf->surf) == -1)
{
    PyErr_SetString (PyExc_RuntimeError, "error locking surface");
    return 0;
}
return 1;

} }}}


== illume, 2009-05-26 01:55:25 -0700

{{{ Thanks Tom!

Committed revision 2259. }}}


Comments (1)

  1. Log in to comment