Bug 119504 - arts memory leak when playing ogg and mp3 files
Summary: arts memory leak when playing ogg and mp3 files
Status: RESOLVED FIXED
Alias: None
Product: arts
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Stefan Westerfeld
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-04 16:01 UTC by Matthew Stapleton
Modified: 2006-06-13 06:37 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Debug output of Arts playing an ogg file (1.73 KB, text/plain)
2006-01-18 06:43 UTC, Matthew Stapleton
Details
kdemultimedia_akode_fix_memory_leak.patch (797 bytes, patch)
2006-03-01 02:39 UTC, Matthew Stapleton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Stapleton 2006-01-04 16:02:21 UTC
Version:            (using KDE KDE 3.5.0)
Installed from:    Gentoo Packages
Compiler:          g++ (GCC) 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8) 
OS:                Linux

The primary artsd process is leaking memory when it plays ogg and mp3 files.  Since KDE uses ogg files for sound events, after about a week artsd is using a lot of memory which slows the system down.
The VmSize, VmRSS, and VmData all increase at the beginning of ogg playback then when it finishes playing not all of that used memory is freed.  I also noticed that when playing a long ogg file the VmRSS will constantly grow by a few kB during every second of playback.  The same thing happens with mp3 files but not as bad as with ogg files.  Playing wav files however allocates very little memory in artsd and the usage doesn't increase during playback.

How to Reproduce:
1. Play an ogg or mp3 file with artsplay, noatun, or a KDE event
2. Watch the artsd memory usage increase while it plays
3. Wait until it finishes playing or manually stop the playback
4. Notice the slightly increased memory usage of the main artsd process since before playing the file
Comment 1 Matthew Stapleton 2006-01-18 06:43:26 UTC
Created attachment 14299 [details]
Debug output of Arts playing an ogg file

Here is the arts debug log when playing a ogg file in response to a KDE
notification.  I haven't examined the source code much, but looking through the
debug log, it seems that it might be the akode arts plugin that isn't freeing
the memory properly since the memory leak doesn't seem to occur when arts plays
sound files directly (wav).
Comment 2 Stefan Gehn 2006-01-20 19:21:52 UTC
I know that this might be a bit complicated but maybe somebody can run artsd in valgrind to find some suspicious places in either artsd or akode.
Comment 3 Matthew Stapleton 2006-02-04 12:21:22 UTC
I've found out that the gradual increase in memory during sound playback is due to akode memory mapping the file so point 2 isn't a problem.  Also, getting akodeplay to play a short ogg file many times doesn't increase the memory usage.
Comment 4 Andrew Muhametshin 2006-02-21 05:14:43 UTC
Under FreeBSD-6.0

ps axww -O rss,vsz `pgrep artsd`
  PID   RSS   VSZ  TT  STAT      TIME COMMAND
47406 11096 16184  ??  S      0:02,90 /usr/local/bin/artsd -F 128 -S 8192 -a toss -m artsmessage -c drkonqi -l 3 -f

ps axww -O rss,vsz `pgrep artsd`
  PID   RSS   VSZ  TT  STAT      TIME COMMAND
47406 408580 431640  ??  S     95:49,13 /usr/local/bin/artsd -F 128 -S 8192 -a toss -m artsmessage -c drkonqi -l 3 -f
Comment 5 Richard Pace 2006-02-27 17:24:29 UTC
This bug appears to have an adverse affect on SWAP file usage.  If left alone, the SWAP file becomes full...my system begins to thrash at that point and all I can do is power down.  I've resorted to restarting ARTS whenever I see memory usage increase above 100,000 as reported in KSYSGUARD.  This action results in immediate relief in memory usage and swap file usage.  Most of my KDE sound activity comes from email notifications and KOPETE notifications.  If you run KSYSGUARD and then open KDE Control Center to System Notification, use "Play Sound" with any system notification selected and watch the memory usage increase for ARTSD
Comment 6 Matthew Stapleton 2006-03-01 02:39:52 UTC
Created attachment 14913 [details]
kdemultimedia_akode_fix_memory_leak.patch

Here is a patch to fix the memory leak.  The key to using valgrind to find the
problem was to close artsd while the akode plugin was still loaded.  Then
valgrind was able to see the library where the lost memory was from instead of
showing ???.
Comment 7 Carsten Lohrke 2006-06-12 21:52:37 UTC
Could this patch be committed to svn please?
Comment 8 Allan Sandfeld 2006-06-13 00:02:05 UTC
SVN commit 550832 by carewolf:

Commit my personal changes, so I am not the only one with an artsd that doesn't
leak *shame on me*
BUG:119504


 M  +4 -3      akodePlayObject_impl.cpp  


--- branches/KDE/3.5/kdemultimedia/akode_artsplugin/akodePlayObject_impl.cpp #550831:550832
@@ -82,6 +82,8 @@
 
 akodePlayObject_impl::~akodePlayObject_impl()
 {
+    delete m_packetQueue;
+
     unload();
 }
 
@@ -219,10 +221,9 @@
         delete bufferedDecoder;
         bufferedDecoder = 0;
     }
-#else
+#endif
     delete frameDecoder
     frameDecoder = 0;
-#endif
     decoder = 0;
     if (buffer != inBuffer)
         delete inBuffer;
@@ -301,7 +302,7 @@
 {
     arts_debug("akode: readFrame");
 
-    if (!buffer || !decoder) return false;
+    if (!inBuffer || !decoder) return false;
     if (m_bytebuffer) processQueue();
     if(!decoder->readFrame(inBuffer)) {
         if (decoder->eof()) {
Comment 9 Michael Pyne 2006-06-13 06:37:23 UTC
SVN commit 550906 by mpyne:

Make the memory leak fix compile.

CCBUG:119504


 M  +1 -1      akodePlayObject_impl.cpp  


--- branches/KDE/3.5/kdemultimedia/akode_artsplugin/akodePlayObject_impl.cpp #550905:550906
@@ -222,7 +222,7 @@
         bufferedDecoder = 0;
     }
 #endif
-    delete frameDecoder
+    delete frameDecoder;
     frameDecoder = 0;
     decoder = 0;
     if (buffer != inBuffer)