[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Memory leak in Rect(t1,t2)
David Clark wrote:
>
> Yup, there certainly seems to be a leak in the rect creation code. Not
> knowing any C myself, I can't fix it, but I've noted it for when Pete
> returns from Europe. If anyone can put together a patch, I'll present
> that to him on his return as well.
>
> Thanks for finding that.
Ok there is the patch. In fact two patches. Second is for
display.update([rect,rect,rect,rect]) with exactly 4 rects, leavies
exception state in python. After that [3,2,1].sort() raises TypeError
once.
HTH
Niki
--- src/rect.c 2001/03/02 22:32:57 0.9
+++ src/rect.c 2001/03/02 22:34:19
@@ -56,12 +56,12 @@
{Py_XDECREF(sub); return NULL;}
if(!ShortFromObjIndex(sub, 0, &val)) {Py_DECREF(sub); return NULL;} temp->x = val;
if(!ShortFromObjIndex(sub, 1, &val)) {Py_DECREF(sub); return NULL;} temp->y = val;
- sub = PySequence_GetItem(obj, 1);
+ Py_DECREF(sub); sub = PySequence_GetItem(obj, 1);
if(!sub || !PySequence_Check(sub) || PySequence_Length(sub)!=2)
{Py_XDECREF(sub); return NULL;}
if(!ShortFromObjIndex(sub, 0, &val)) {Py_DECREF(sub); return NULL;} temp->w = val;
if(!ShortFromObjIndex(sub, 1, &val)) {Py_DECREF(sub); return NULL;} temp->h = val;
- return temp;
+ Py_DECREF(sub); return temp;
}
if(PyTuple_Check(obj) && PyTuple_Size(obj) == 1) /*looks like an arg?*/
{
--- src/display.c 2001/03/02 23:47:03 0.9
+++ src/display.c 2001/03/02 23:47:16
@@ -569,7 +569,9 @@
else
{
gr = GameRect_FromObject(arg, &temp);
- if(gr && gr != &temp)
+ if(!gr)
+ PyErr_Clear();
+ else if(gr != &temp)
{
memcpy(&temp, gr, sizeof(temp));
gr = &temp;