[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] bug, patch: surflock.c memory leak
- To: pygame-users@xxxxxxxx
- Subject: [pygame] bug, patch: surflock.c memory leak
- From: René Dudfield <renesd@xxxxxxxxx>
- Date: Tue, 26 May 2009 08:21:14 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 25 May 2009 18:21:16 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=LskINzbjQNu/qTqCe+3mnw/aIkQdjIcOqOpq4uxdlLY=; b=MDx01qYTwEInsY4x4O+tJra6PIUmFUtH265rxgN0cIZlYsXTcW3QYomOTVxoxLeNMT e3GthL2fEMbSFFiRY4U2pdqCcf+GIgeUur/gDtwlH/RsXKCZwQtr+kRZOm19pe4KLpkq 5UH+R+y7I3gJUlw3NkXdfpJFQgP6+BCCzCUEE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=LNY2b4YcnaSSjh3doFZwu49xYJdhf0Tm477JSD05FdwpVQRS7TOCAebuPcD+Hhsc2D 59CaTYweN13ghIrw9wa/kuL0H+Rr3HoWSmffIVd5mbJAdfczbXKkX3ND9GxR3QCP2GPj sdw8NLfvz8BdRLXttN9fOO6M1VcDCylBlInn4=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hi,
this patch/bug report is from Tom in bugzilla.
http://pygame.motherhamster.org/bugzilla/show_bug.cgi?id=30
I think it sounds sensible.
--------
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;
}