Package: xfce4-panel
Version: 4.14.3-1
Severity: normal
Tags: patch

Dear Maintainer,

tl;dr: The wrapper leaks 32 bytes with every redraw event.
On my system, that means I have to reboot every other week.

First I want to convince you that there actually is an issue.
For that, I replaced /usr/lib/x86_64-linux-gnu/xfce4/panel/wrapper-2.0 by a
little script that usually exec's the real binary, but intercepts cpugraph, and
calls it through valgrind. This way I could see what the wrapper does under
"real" circumstances.

Here is the relevant valgrind log output, for xfce4-panel 4.14.3-1 with
cpugraph-plugin on "Very fast (250ms)",
killing after 1 hour:

==7077== 414,560 bytes in 12,955 blocks are definitely lost in loss record
6,679 of 6,679
==7077==    at 0x48367F3: malloc (in /usr/lib/x86_64-linux-
gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==7077==    by 0x544D1C8: g_malloc (gmem.c:102)
==7077==    by 0x54651F1: g_slice_alloc (gslice.c:1024)
==7077==    by 0x5465851: g_slice_copy (gslice.c:1075)
==7077==    by 0x5390AAF: boxed_proxy_lcopy_value (gboxed.c:267)
==7077==    by 0x4B4F530: gtk_style_context_get_valist (in
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2404.10)
==7077==    by 0x4B4F759: gtk_style_context_get (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==7077==    by 0x10CCA2: wrapper_plug_draw (wrapper-plug.c:221)
==7077==    by 0x4BF2813: ??? (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==7077==    by 0x4BFB9AF: ??? (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==7077==    by 0x4AA9C93: gtk_main_do_event (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==7077==    by 0x4F99804: ??? (in /usr/lib/x86_64-linux-
gnu/libgdk-3.so.0.2404.10)
==7077==
==7077== LEAK SUMMARY:
==7077==    definitely lost: 415,048 bytes in 12,988 blocks
==7077==    indirectly lost: 0 bytes in 0 blocks
==7077==      possibly lost: 4,720 bytes in 47 blocks
==7077==    still reachable: 1,561,423 bytes in 16,581 blocks
==7077==                       of which reachable via heuristic:
==7077==                         length64           : 4,744 bytes in 82 blocks
==7077==                         newarray           : 2,160 bytes in 55 blocks
==7077==         suppressed: 0 bytes in 0 blocks
==7077== Reachable blocks (those to which a pointer was found) are not shown.
==7077== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7077==
==7077== ERROR SUMMARY: 40 errors from 40 contexts (suppressed: 0 from 0)

That's about 70 MB per week:
https://www.wolframalpha.com/input/?i=414560+byte+*+week+%2F+hour
That matches my observations about cpugraph needing more and more memory.

wrapper-plug.c:221 fetches the background color, and from the stacktrace it
looks like a copy is made, and the caller is supposed to clean up that copy.
However, wrapper-plug does not do that.
Note that sizeof(GdkRGBA)==32 and 414560.0 / 12955.0 == 32.0, so it's
plausible.

The latest version in salsa (>4.15.0-1) doesn't help.
That makes sense because wrapper-plug.c didn't change significantly.
Here's the result after running for 10 minutes:

==6308== 65,952 bytes in 2,061 blocks are definitely lost in loss record 6,456
of 6,459
==6308==    at 0x48367F3: malloc (in /usr/lib/x86_64-linux-
gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==6308==    by 0x544F1C8: g_malloc (gmem.c:102)
==6308==    by 0x54671F1: g_slice_alloc (gslice.c:1024)
==6308==    by 0x5467851: g_slice_copy (gslice.c:1075)
==6308==    by 0x5392AAF: boxed_proxy_lcopy_value (gboxed.c:267)
==6308==    by 0x4B51530: gtk_style_context_get_valist (in
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2404.10)
==6308==    by 0x4B51759: gtk_style_context_get (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==6308==    by 0x10CCC2: wrapper_plug_draw (wrapper-plug.c:190)
==6308==    by 0x4BF4813: ??? (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==6308==    by 0x4BFD9AF: ??? (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==6308==    by 0x4AABC93: gtk_main_do_event (in /usr/lib/x86_64-linux-
gnu/libgtk-3.so.0.2404.10)
==6308==    by 0x4F9B804: ??? (in /usr/lib/x86_64-linux-
gnu/libgdk-3.so.0.2404.10)
==6308==
==6308== LEAK SUMMARY:
==6308==    definitely lost: 66,095 bytes in 2,069 blocks
==6308==    indirectly lost: 0 bytes in 0 blocks
==6308==      possibly lost: 4,696 bytes in 47 blocks
==6308==    still reachable: 1,544,097 bytes in 16,302 blocks
==6308==                       of which reachable via heuristic:
==6308==                         length64           : 4,384 bytes in 76 blocks
==6308==                         newarray           : 2,144 bytes in 54 blocks
==6308==         suppressed: 0 bytes in 0 blocks
==6308== Reachable blocks (those to which a pointer was found) are not shown.
==6308== To see them, rerun with: --leak-check=full --show-leak-kinds=all

Freeing the GdkRGBA causes no problems and fixes the leak. This is with the
patch, after 10 minutes:

==5086== LEAK SUMMARY:
==5086==    definitely lost: 143 bytes in 8 blocks
==5086==    indirectly lost: 0 bytes in 0 blocks
==5086==      possibly lost: 4,696 bytes in 47 blocks
==5086==    still reachable: 1,548,565 bytes in 16,442 blocks
==5086==                       of which reachable via heuristic:
==5086==                         length64           : 4,384 bytes in 76 blocks
==5086==                         newarray           : 2,144 bytes in 54 blocks
==5086==         suppressed: 0 bytes in 0 blocks
==5086== Reachable blocks (those to which a pointer was found) are not shown.
==5086== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==5086==
==5086== ERROR SUMMARY: 39 errors from 39 contexts (suppressed: 0 from 0)

Please find my patch attached.

I already submitted this bug upstream:
https://bugzilla.xfce.org/show_bug.cgi?id=16640
However, I'm impatient and don't want to have to restart my system / panel
plugins all the time,
and would be grateful for a 4.14.3-2 :)

Cheers,
Ben Wiederhake



-- System Information:
Debian Release: bullseye/sid
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.4.0-4-amd64 (SMP w/4 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=de_DE.utf8, LC_CTYPE=de_DE.utf8 (charmap=UTF-8), 
LANGUAGE=de_DE.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages xfce4-panel depends on:
ii  exo-utils            0.12.11-1
ii  libatk1.0-0          2.34.1-1
ii  libc6                2.30-4
ii  libcairo2            1.16.0-4
ii  libexo-2-0           0.12.11-1
ii  libgarcon-1-0        0.6.4-1
ii  libgarcon-gtk3-1-0   0.6.4-1
ii  libgdk-pixbuf2.0-0   2.40.0+dfsg-3
ii  libglib2.0-0         2.64.1-1
ii  libgtk-3-0           3.24.14-1
ii  libgtk2.0-0          2.24.32-4
ii  libpango-1.0-0       1.42.4-8
ii  libpangocairo-1.0-0  1.42.4-8
ii  libwnck-3-0          3.36.0-1
ii  libx11-6             2:1.6.9-2
ii  libxext6             2:1.3.3-1+b2
ii  libxfce4panel-2.0-4  4.14.3-1
ii  libxfce4ui-2-0       4.14.1-1+b1
ii  libxfce4util7        4.14.0-1
ii  libxfconf-0-3        4.14.1-1

xfce4-panel recommends no packages.

xfce4-panel suggests no packages.

-- no debconf information
From 963a5942673e3a547d6e08e1ef54693ad02e3877 Mon Sep 17 00:00:00 2001
From: Ben Wiederhake <benwiederhake.git...@gmx.de>
Date: Sun, 5 Apr 2020 23:25:45 +0200
Subject: [PATCH] Fix memory leak in panel plugin wrapper

---
 wrapper/wrapper-plug.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/wrapper/wrapper-plug.c b/wrapper/wrapper-plug.c
index db973bd4..90c8d6af 100644
--- a/wrapper/wrapper-plug.c
+++ b/wrapper/wrapper-plug.c
@@ -191,6 +191,7 @@ wrapper_plug_draw (GtkWidget *widget,
                                  GTK_STYLE_PROPERTY_BACKGROUND_COLOR,
                                  &rgba, NULL);
           gdk_cairo_set_source_rgba (cr, rgba);
+          gdk_rgba_free (rgba);
         }

       /* draw the background color */
--
2.25.1

Reply via email to