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 758641 - Memory leak in g_dbus_proxy_new_for_bus_sync()
Memory leak in g_dbus_proxy_new_for_bus_sync()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.46.x
Other Linux
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-11-25 10:21 UTC by Evangelos Foutras
Modified: 2016-01-05 02:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdbus-proxy-memleak test program (847 bytes, text/x-csrc)
2015-11-25 10:21 UTC, Evangelos Foutras
  Details
[PATCH] GDBusProxy: Fix a memory leak during initialization (714 bytes, patch)
2015-11-25 22:08 UTC, Evangelos Foutras
accepted-commit_now Details | Review

Description Evangelos Foutras 2015-11-25 10:21:55 UTC
Created attachment 316223 [details]
gdbus-proxy-memleak test program

Following the upgrade to glib 2.46.x, I noticed that the Xfce power manager applet process was reaching very high amounts of memory usage as the days passed (>1GB); on every battery state change, the memory usage increases by about half a MB.

After much poking around I believe this is a bug in glib and a GVariant isn't being freed correctly somewhere. While I'm not knowledgeable enough to figure out where the bug exists in the code, I have done a git bisect of the issue and came up with the following commit:

    commit f10b6550ff2ce55d06b92d6dc3e443fc007b2f7a
    Author: Dan Winship <danw@gnome.org>
    Date:   Thu Aug 2 15:46:32 2012 -0400

        gio: (belatedly) port gdbus from GSimpleAsyncResult to GTask

        https://bugzilla.gnome.org/show_bug.cgi?id=661767

I'm also attaching a simple test case for which Valgrind reports the following:

    ==8086== 763,300 (4,000 direct, 759,300 indirect) bytes in 100 blocks are definitely lost in loss record 1,133 of 1,133
    ==8086==    at 0x4C28C10: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==8086==    by 0x549ECCC: g_malloc (gmem.c:97)
    ==8086==    by 0x54B7B7A: g_slice_alloc (gslice.c:1007)
    ==8086==    by 0x54DF4C4: g_variant_alloc (gvariant-core.c:476)
    ==8086==    by 0x54DF617: g_variant_new_from_children (gvariant-core.c:565)
    ==8086==    by 0x54DB9E8: g_variant_builder_end (gvariant.c:3612)
    ==8086==    by 0x4F40EB5: parse_value_from_blob (gdbusmessage.c:1817)
    ==8086==    by 0x4F42F0B: g_dbus_message_new_from_blob (gdbusmessage.c:2144)
    ==8086==    by 0x4F4CFAC: _g_dbus_worker_do_read_cb (gdbusprivate.c:718)
    ==8086==    by 0x4ED80D1: g_task_return_now (gtask.c:1106)
    ==8086==    by 0x4ED812E: complete_in_idle_cb (gtask.c:1120)
    ==8086==    by 0x5499090: g_idle_dispatch (gmain.c:5397)
    ==8086==    by 0x54966E5: g_main_dispatch (gmain.c:3122)
    ==8086==    by 0x549751C: g_main_context_dispatch (gmain.c:3737)
    ==8086==    by 0x5497700: g_main_context_iterate (gmain.c:3808)
    ==8086==    by 0x5497B26: g_main_loop_run (gmain.c:4002)
    ==8086==    by 0x4F4AE45: gdbus_shared_thread_func (gdbusprivate.c:246)
    ==8086==    by 0x54C54FA: g_thread_proxy (gthread.c:764)
    ==8086==    by 0x57AB4A3: start_thread (in /usr/lib/libpthread-2.22.so)
    ==8086== 
    ==8086== LEAK SUMMARY:
    ==8086==    definitely lost: 4,000 bytes in 100 blocks
    ==8086==    indirectly lost: 759,300 bytes in 25,800 blocks
    ==8086==      possibly lost: 2,272 bytes in 26 blocks
    ==8086==    still reachable: 183,123 bytes in 2,757 blocks

(No memory leaks are reported when testing agaist the parent of the commit mentioned above.)
Comment 1 Evangelos Foutras 2015-11-25 22:08:55 UTC
Created attachment 316272 [details] [review]
[PATCH] GDBusProxy: Fix a memory leak during initialization

I actually managed to come up with a patch for this! Tests still pass, valgrind reports no memory leak (using the attached gdbus-proxy-memleak program) and Xfce power manager applet's memory usage remains stable.

Assuming the patch gets accepted, please also cherry-pick it into the glib-2-46 branch. (It's an important fix IMO that needs to be in the next glib 2.46.x release.)
Comment 2 Colin Walters 2015-11-25 22:33:04 UTC
Review of attachment 316272 [details] [review]:

LGTM, thanks!
Comment 4 Colin Walters 2015-11-25 22:45:35 UTC
That's a very old commit, so as far as I can tell this affects glib-2-34 and above.  I'd like to at least push to glib-2-44 and glib-2-46.  Dan, what do you think?
Comment 5 Evangelos Foutras 2015-11-25 22:56:32 UTC
Not Dan, but I can answer that question; the commit is indeed very old but was merged during the 2.46 development cycle -- first release to contain it was 2.45.1 according to 'git tag --contains'. (I should have used --format=fuller when I quoted the commit to show the commit date as well.)

I believe it only needs to be merged into the glib-2-46 branch.
Comment 6 Evangelos Foutras 2015-12-03 05:04:40 UTC
Reopening so it doesn't get missed for glib 2.46.3. Feel free to mark it as resolved again once it's also in the glib-2-46 branch (or sooner, if that's how backports are handled).

Thanks!
Comment 7 Evangelos Foutras 2016-01-05 02:27:55 UTC
Sorry to bump this, but can the commit be merged into glib-2-46 so this could be closed again? In Arch Linux, we have had the patch applied on top of 2.46.2 since 2015-11-25 with no reported issues and it is confirmed to fix the huge memory leak I was experiencing with Xfce's power manager applet.
Comment 8 Colin Walters 2016-01-05 02:52:48 UTC
Merged to 2-46 too, looks like you were right about the merge point as well.  Thanks!