mgedmin / indicator-netspeed

Stupid network speed indicator for Unity, inspired by the old netspeed GNOME applet
http://askubuntu.com/questions/30334/list-of-application-indicators/89889#89889
104 stars 47 forks source link

Memory leak #3

Closed netikras closed 10 years ago

netikras commented 10 years ago

Hello!

It's a quite nice app you have here. However you might have forgotten to free-up memory somewhere.

top - 14:16:57 up 12 days, 14:06, 11 users,  load average: 1,42, 2,07, 2,27
Tasks: 239 total,   2 running, 237 sleeping,   0 stopped,   0 zombie
%Cpu(s):  9,2 us,  3,4 sy,  0,0 ni, 86,1 id,  1,3 wa,  0,0 hi,  0,0 si,  0,0 st
KiB Mem:   1988524 total,  1754096 used,   234428 free,    37360 buffers
KiB Swap:  6835196 total,   495672 used,  6339524 free,   566900 cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND          
 6476 netikras  20   0  856m 100m  53m S   3,7  5,2   1:02.08 chromium-browse   
 2597 netikras  20   0  690m 232m 4108 S   0,4 12,0  43:59.83 indicator-netsp   
netikras@netikras-netbook ~/received $ ps aux |head -1; ps aux |grep -v grep| grep indicator-netsp
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
netikras  2597  0.2 11.9 707180 237920 ?       Sl   Geg07  44:00 /usr/bin/indicator-netspeed
netikras@netikras-netbook ~/received $ free -m
             total       used       free     shared    buffers     cached
Mem:          1941       1672        269          0         36        532
-/+ buffers/cache:       1102        838
Swap:         6674        483       6191
netikras@netikras-netbook ~/received $ uptime
 14:18:34 up 12 days, 14:07, 11 users,  load average: 0,47, 1,59, 2,08

don't really have time right now to bugfix it, maybe later.

Also I will keep it running as far as I can so if you need any more details - don't hesitate to ask.

kjyv commented 10 years ago

Thanks for reporting. I guess running valgrind will find the missing free calls. I'll check when I have time.

TobBrandt commented 10 years ago

From a quick look it seems like line 72 is the culprit:

string = g_strdup_printf("%*s%s", (int)((maxWidth-width)/spaceWidth), " ", string);

This forgets to free the old string. It should be something like:

gchar _old_string = string; string = g_strdup_printf("%_s%s", (int)((maxWidth-width)/spaceWidth), " ", string); g_free(old_string);

On 19 May 2014 13:40, Stefan Bethge notifications@github.com wrote:

Thanks for reporting. I guess running valgrind will find the missing free calls. I'll check when I have time.

— Reply to this email directly or view it on GitHubhttps://github.com/mgedmin/indicator-netspeed/issues/3#issuecomment-43491920 .

TobBrandt commented 10 years ago

I think my latest commit fixed this. Could you please confirm?

netikras commented 10 years ago

checking...

netikras commented 10 years ago

BEFORE commit:

netikras@netikras-netbook ~/received $ while :; do ps -eo pid,rss,time,args|grep -v grep|grep /usr/bin/indicator-netspeed;sleep 2; done 2597 241552 00:44:14 /usr/bin/indicator-netspeed 2597 241552 00:44:14 /usr/bin/indicator-netspeed 2597 241560 00:44:14 /usr/bin/indicator-netspeed 2597 241560 00:44:14 /usr/bin/indicator-netspeed 2597 241560 00:44:14 /usr/bin/indicator-netspeed 2597 241564 00:44:14 /usr/bin/indicator-netspeed 2597 241564 00:44:14 /usr/bin/indicator-netspeed 2597 241568 00:44:14 /usr/bin/indicator-netspeed 2597 241568 00:44:14 /usr/bin/indicator-netspeed 2597 241572 00:44:14 /usr/bin/indicator-netspeed 2597 241572 00:44:15 /usr/bin/indicator-netspeed 2597 241572 00:44:15 /usr/bin/indicator-netspeed 2597 241572 00:44:15 /usr/bin/indicator-netspeed 2597 241576 00:44:15 /usr/bin/indicator-netspeed 2597 241576 00:44:15 /usr/bin/indicator-netspeed 2597 241576 00:44:15 /usr/bin/indicator-netspeed ^C

AFTER commit:

netikras@netikras-netbook /usr/include $ while :; do ps -eo pid,rss,time,args|grep -v grep|grep indicator-netspeed;sleep 2; done 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13668 00:00:01 ./indicator-netspeed 31783 13672 00:00:01 ./indicator-netspeed 31783 13672 00:00:01 ./indicator-netspeed 31783 13672 00:00:01 ./indicator-netspeed 31783 13672 00:00:01 ./indicator-netspeed 31783 13672 00:00:01 ./indicator-netspeed 31783 13672 00:00:01 ./indicator-netspeed ^C

I see it's still trying to grow in memory but in much slower rates. Is this intended?

netikras commented 10 years ago

I guess not... There should be !at least! one more spot you forgot to call free(). What's being triggered rarely in this app? Are you buffering anything permanently?

netikras@netikras-netbook /usr/include $ ps aux | grep indicat netikras 31783 0.8 0.6 330348 13856 pts/8 Sl+ 20:59 0:03 ./indicator-netspeed

netikras@netikras-netbook /usr/include $ ps aux | grep indicat netikras 31783 0.7 0.7 330596 13996 pts/8 Sl+ 20:59 0:04 ./indicator-netspeed netikras@netikras-netbook /usr/include $

TobBrandt commented 10 years ago

Found it, will commit in a minute.

On 19 May 2014 20:12, Darius Juodokas notifications@github.com wrote:

I guess not... There should be !at least! one more spot you forgot to call free(). What's being triggered rarely in this app? i.e. not every iteration?

netikras@netikras-netbook /usr/include $ ps aux | grep indicat netikras 31783 0.8 0.6 330348 13856 pts/8 Sl+ 20:59 0:03 ./indicator-netspeed

netikras@netikras-netbook /usr/include $ ps aux | grep indicat netikras 31783 0.7 0.7 330596 13996 pts/8 Sl+ 20:59 0:04 ./indicator-netspeed netikras@netikras-netbook /usr/include $

— Reply to this email directly or view it on GitHubhttps://github.com/mgedmin/indicator-netspeed/issues/3#issuecomment-43537524 .

TobBrandt commented 10 years ago

Seems to be pretty stable now after the first minute or so. But I'll have to let it run over night to be sure.

netikras commented 10 years ago

I'm wondering what was the trouble maker? I assume push will be commited tomorrow, right?

TobBrandt commented 10 years ago

I just pushed it. The problem was a reference count that wasn't decreased. See here: https://github.com/mgedmin/indicator-netspeed/commit/ec255a4b6e365ecb2018beea9fe6d60023eee111.

netikras commented 10 years ago

ahh, nasty buggar... Easy to miss :) Waiting for test results tomorrow..

netikras commented 10 years ago

There's still something remaining.....

netikras@netikras-netbook /usr/include $ while :; do ps -eo pid,rss,time,args|grep -v grep|grep indicator-netspeed;sleep 10; done 920 13232 00:00:00 ./indicator-netspeed 920 13232 00:00:00 ./indicator-netspeed 920 13232 00:00:00 ./indicator-netspeed 920 13232 00:00:00 ./indicator-netspeed 920 13232 00:00:00 ./indicator-netspeed 920 13232 00:00:00 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:01 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:02 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:03 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:04 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:05 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13232 00:00:06 ./indicator-netspeed 920 13236 00:00:06 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13236 00:00:07 ./indicator-netspeed 920 13240 00:00:07 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:08 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed 920 13240 00:00:09 ./indicator-netspeed ^C

TobBrandt commented 10 years ago

It's OK if the memory usage increases a little bit initially. That's probably just fragmentation. As long as it settles after some time, we're fine.

I've been running it for almost an hour now, and it remains constant at 13416 KB.

TobBrandt commented 10 years ago

It has been running for 12 hours now and remains at constant memory usage. Therefore, I'm closing this ticket.

Thank you very much for your help!

mgedmin commented 10 years ago

:clap: :balloon: :tada: