After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688674 - object: Fix memory leak
object: Fix memory leak
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-11-19 20:01 UTC by Colin Walters
Modified: 2012-11-19 22:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
object: Fix memory leak (1.47 KB, patch)
2012-11-19 20:01 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2012-11-19 20:01:14 UTC
Noticed while inspecting the code for a different valgrind error.
Comment 1 Colin Walters 2012-11-19 20:01:16 UTC
Created attachment 229402 [details] [review]
object: Fix memory leak
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-11-19 20:50:23 UTC
Review of attachment 229402 [details] [review]:

This is some very messy code. I tried to write it to prevent leaks as clean as I could, but I guess I failed. Not sure if you have any suggestions.

::: gi/object.c
@@ -367,3 @@
-        old_parent = parent;
-        parent = g_object_info_get_parent(old_parent);
-        if (!parent)

All you should need to do is move this if statement under the unref(old_parent), right?
Comment 3 Colin Walters 2012-11-19 20:55:28 UTC
(In reply to comment #2)
> Review of attachment 229402 [details] [review]:
> 
> This is some very messy code. I tried to write it to prevent leaks as clean as
> I could, but I guess I failed. Not sure if you have any suggestions.

I don't have any ideas for making it simpler (well, short of the GCC cleanup macros)

> ::: gi/object.c
> @@ -367,3 @@
> -        old_parent = parent;
> -        parent = g_object_info_get_parent(old_parent);
> -        if (!parent)
> 
> All you should need to do is move this if statement under the
> unref(old_parent), right?

Yes, that would be a more minimal fix, but I think the code is clearer now; the scope of "old_parent" (now "tmp") is more constrained, and thus easier to reason about.
Comment 4 Jasper St. Pierre (not reading bugmail) 2012-11-19 21:02:06 UTC
Review of attachment 229402 [details] [review]:

OK.
Comment 5 Colin Walters 2012-11-19 22:28:54 UTC
Attachment 229402 [details] pushed as 69a2598 - object: Fix memory leak