GNOME Bugzilla – Bug 144627
Some async functions leak memory for the proxy
Last modified: 2011-01-16 23:36:22 UTC
I am writing an application that uses async support in gnome-vfsmm. It crashes because it passes a pointer to proxy object which is on the stack and on the c_callback methods, it reference it... I changed the code so that proxy objects are created on the heap and destroyed with the c_callback methods. It works on the cases I tested but I don't master gnome-vfs enough to consider it as ok. My solution will work iff c_callback methods are called once and only once (How gnome-vfs handles cancel calls relatively to callbacks?)
Could we see a patch, please? http://www.gtkmm.org/bugs.shtml#CreatingPatches
Created attachment 28865 [details] [review] Partial correction of the problem of proxy objects pointers in async-handle.ccg Here is the patch. Please, notice that I have tested only few methods (open, read, close). I am testing load_directory (which *seems* BTW not to work!). There is places (identified by //TODO MemoryLeak:) where I don't destroy proxy objects since I don't know how the underlying async call behaves: how to identify the last call to the callback? PS: This is my first contribution to an open source project. I hope it is ok :)
Created attachment 29075 [details] [review] patch of async-handle.ccg.
I agree that this is a problem. Well done. We need to ask on the gnome-vfs list about 1. Whether the async callbacks are called more than once. 2. Whether they are called at least once. Or, what happens if the operation is cancelled - how do we clean up the memory. New versios of the functions with destroy_callback parameters might be necessary in gnome-vfs.
It looks like you found a real problem. Thanks: http://lists.gnome.org/archives/gnome-vfs-list/2004-July/msg00009.html For now, I have appplied the patch with these changes: 1. I added comments next to every new and every delete. 2. I think that the callback given to gnome_vfs_async_find_directory will only be called once, so we can delete the proxy there. http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/gnome-vfs-20-gnome-vfs-async-ops.html#gnome-vfs-async-find-directory 3. I added g_warnings where there are leaks, so that people can decide not to use them. I think that is just Handle::transfer() and Handle::cancel(). I have attached the revised patch so you can see what I did. Please look it over and test the changes, because I am not using these methods. In fact, it would be great if you could add an example that uses them. Please make a cvs patch if you need to patch it again: http://www.gtkmm.org/bugs.shtml#CreatingPatches Thanks again.
Created attachment 29351 [details] [review] vfs_async2.patch
Closing because giomm seems like the answer to all our gnome-vfs problems.