mate-desktop / mate-applets

Applets for use with the MATE panel
http://www.mate-desktop.org
GNU General Public License v2.0
78 stars 66 forks source link

battstat applet is leaking RAM #225

Open thanatos opened 7 years ago

thanatos commented 7 years ago

The battstat applet on my system is consuming 11% of RAM, or 3.6 gigabytes:

battstat leaking RAM

PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
587 •••••      20   0 4049M 3604M  6488 S  0.0 11.2  9h17:23 /usr/lib/mate-applets/battstat-applet

(It has also used a considerable 9h of CPU time, out of 39 days of uptime; currently, only Chrome and X11 have used more.)

I'll keep the leaker in RAM for a while longer, so if there's any debug info from the running process I can attach, let me know. We'll be using swap soon, so at some point, I'll have to kill it.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/41499249-battstat-applet-is-leaking-ram?utm_campaign=plugin&utm_content=tracker%2F517519&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F517519&utm_medium=issues&utm_source=github).
thanatos commented 7 years ago

(Looking through what I hope are likely sections to try to find my leak.)

First, this function; if the call on that line to g_io_channel_read_line_string fails, it will allocate a GError and store a pointer to it in gerror; AFAICT, it is on us to call g_clear_error, which we never do (thus leaking the error should one occur). (We also ignore the return code from g_io_channel, so the requisite error handling is missing altogether from this function.)

Trying to compile mate-applets (for debug mode, to see if I can give it to valgrind), but it seems like it requires libmatepanelapplet >= 1.17.0,

configure: error: Package requirements (libmatepanelapplet-4.0 >= 1.17.0) were not met:

Requested 'libmatepanelapplet-4.0 >= 1.17.0' but version of libmate-panel-applet-4 is 1.16.0

My distro, Arch, has 1.16 as the latest version, AFAICT.

fbarriga commented 7 years ago

I have the same issue (the leak). The process is using ~500MiB of ram after an uptime of 11 days.

sbalneav commented 7 years ago

Can you try the above commit? See if that helps.

allanlaal commented 7 years ago

in 2 weeks battstat-applet grew to use 1.7GB of RAM

to be fair I have 2 of these in use - one to show battery % and the other to show time

monsta commented 6 years ago

@thanatos: if you need to rebuild the current stable release of mate-applets, you'll need to checkout to 1.18 branch first. Or just use one of tarballs.

n0rad commented 6 years ago

I Built master this morning which contain the possible fix, replaced the os installed binary with the built one and reboot.

I don't know why but with the built one, the settings menu option is not there. Anyway, it looks to still leak since It grow from 81Mb to 91Mb in few hours.

If you tell me how I can debug that, I can leave it running few days and dump/debug.

monsta commented 6 years ago

You can use valgrind, though I don't know if it could be attached to a running process (similar to gdb).

scaleoutsean commented 6 years ago

This has been annoying me for 5 months now so today I finally removed it from my panel. For those who aren't sure which applet that is:

I switched to using this poor man's battery indicator script based on https://askubuntu.com/questions/69556/how-to-check-battery-status-using-terminal. I have 2 batteries.

#!/bin/bash
upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|to\ full|percentage" 
upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep -E "state|to\ full|percentage"
praetp commented 6 years ago

It seems the issue is still present. My laptop has been up for a month and battstat-applet is using more memory than my browser.

ooxi commented 4 years ago

Still present in Ubuntu 18.04

rdiez commented 4 years ago

I am running Ubuntu 18.04.4 LTS, and I have an interesting issue with this applet.

I keep running my laptop for days in a row, but I put it to sleep overnight. Sometimes, when I wake it up, or perhaps when I connect the power cord (I do not know yet which one of these 2 actions is triggering this issue), then battstat-applet starts consuming a lot of CPU power. I can hear how the laptop fan starts running faster. I think it is using 1 CPU core at 100 %. That is process /usr/lib/mate-applets/battstat-applet .

Memory consumption is rather high, over 500 MiB of memory and over 1 GiB of virtual memory, according to MATE's "System Monitor" tool. That would be the reported memory leak. I wonder if that triggers the high CPU usage too, or if that is something entirely different.

If I kill battstat-applet, I can choose to have it restarted, and then it works fine. Until next time.

There is one more thing to report. Because I did not like the battery icon, especially the little "plug" icon when the power cord is connected, I tried briefly with another applet called "Battery Charge Monitor", but I removed it (or so I believe). The battery charge indicator is now showing in the standard "Indicator Applet Complete" version 1.20.0.

However, this battstat-applet is probably not part of the "Indicator Applet Complete", but it is in fact the "Battery Charge Monitor" applet. I think that it does not show its taskbar icon most of the time. Can someone confirm this?

How do I inspect all the applets that the panel is actually loading or trying to load? I think in earlier versions of MATE there was a panel dialog where I could see and reorder all applets, but that is now gone. It is now hard enough to find a very narrow strip on the taskbar where I can right-click and get the Panel's pop-up menu with the "+ Add to Panel" option. Right-clicking on most of the taskbar space just shows the pop-up menu for a particular applet.

All in all a rather unsatisfactory state of affairs.

ooxi commented 4 years ago

@rdiez maybe this is a red herring, but I have two battery indicators running as well

rdiez commented 4 years ago

Why do you have two?

If I remember well, I tried to add the standalone "Battery Charge Monitor" / battstat-applet because the main battery indicator on the "Indicator Applet Complete" stopped working (disappeared). But it appeared again later on by itself. This is a laptop, it always has a battery (it is in fact nondetachable).

ooxi commented 4 years ago

Why do you have two?

If I remember well, I tried to add the standalone "Battery Charge Monitor" / battstat-applet because the main battery indicator on the "Indicator Applet Complete" stopped working (disappeared). But it appeared again later on by itself. This is a laptop, it always has a battery (it is in fact nondetachable).

Exactly because of this, the indicator kept crashing? / disappearing so I added another