I think I figured this out. In growl_PostDictionary (libgrowl.c), the
call PyObject_GetAttrString(pValue, "rawImageData") on line 111
results in the allocation of an image that is never freed. This simple
patch appears to fix the leak:

diff -r 2e787f50d3c7 Bindings/python/libgrowl.c
--- a/Bindings/python/libgrowl.c        Tue Jun 08 23:20:02 2010 -0700
+++ b/Bindings/python/libgrowl.c        Tue May 10 12:36:35 2011 +0300
@@ -115,9 +115,11 @@
                                CFDataRef convertedValue = 
CFDataCreate(kCFAllocatorDefault,
                                                                                
                                (const UInt8 *)PyString_AsString(lValue),
                                                                                
                                PyString_Size(lValue));
+                free(lValue);
                                CFDictionarySetValue(note, convertedKey, 
convertedValue);
                                CFRelease(convertedValue);
                        } else {
+                free(lValue);
                                CFRelease(convertedKey);
                                PyErr_SetString(PyExc_TypeError, "Icon with 
rawImageData
attribute present must ensure it is a string.");
                                goto error;

I don't have much C experience beyond a university class I took, so I
don't know if this is idiomatic code in the OS X environment, or if
there are other subtleties that might cause problems. Feel free to
educate me. :)

On May 9, 6:19 pm, ahihi <[email protected]> wrote:
> while True:
>     icon = Growl.Image.imageFromPath("some-icon.png")
>     del icon
>
> runs fine and in constant space with the patch. It does indeed leak
> without it.
>
> On May 9, 6:11 pm, Peter Hosey <[email protected]> wrote:
>
>
>
>
>
>
>
> > On May 9, 2011, at 08:06:51, ahihi wrote:
>
> > > The leaks list seems to indicate a lot of leaks coming from 
> > > PyString_FromStringAndSize. I'm completely new to Instruments, so let me 
> > > know if you need some more specific information.
>
> > Before I proceed further, can you confirm whether that patch works (at 
> > least, doesn't crash)?
>
> > I think it does fix a leak, but your program wouldn't show it because it 
> > creates one image and keeps it for its entire lifetime. Creating the image 
> > and then destroying the Python object for it (del myImage) should show it.
>
> > (The module doesn't build for me, probably because I'm in Xcode 4 right 
> > now, so I can't test any of this.)

-- 
You received this message because you are subscribed to the Google Groups 
"Growl Discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/growldiscuss?hl=en.

Reply via email to