GNOME Bugzilla – Bug 556387
FileEnumerator::next_file reference counting problems
Last modified: 2008-10-15 15:30:54 UTC
The FileEnumerator::next_file method adds an additional reference to the return value via the refreturn flag to gmmproc, but the C version g_file_enumerator_next_file() returns a new object with reference count 1, so there is no need to add an additional reference. This prevents the file enumerator from being freed correctly when the RefPtr goes out of scope. Similarly, FileEnumerator::next_files_finish() returns a list with shallow ownership, but the C documentation says "You must free the list with g_list_free() and unref the infos with g_object_unref when you're done with them." which means we need to set deep ownership for the GFileInfos to get freed correctly.
Created attachment 120631 [details] Test demonstrating the problem This demonstrates the problem: When using the C++ version of next_file, the reference count of the resulting GFileInfo object is 2, but it is only 1 using the C version.
Created attachment 120632 [details] [review] Proposed patch This patch fixes the problem by not adding an extra reference in next_file and using deep ownership for next_files_finish.
Thanks, this looks good. Feel free to commit.
Committed. 2008-10-15 Armin Burgmeier <armin@openismus.com> * gio/src/fileenumerator.hg: * gio/src/fileenumerator.ccg: Made FileEnumerator::next_file not add an additional reference to the return value, because the C version creates a new object. Also, changed ownership of the list returned by FileEnumerator::next_files_finish to be deep instead of shallow. Bug #556387.
I guess this isn't documented properly for the C function: http://library.gnome.org/devel/gio/unstable/GFileEnumerator.html#g-file-enumerator-next-file Maybe it should say "you should unreference this with g_object_unref()" or suchlike. Could you file a bug for that, please?
I filed bug #556422.