Memleak with mixer? Or incorrect code?
Hi,
the attached code consumes more and more memory when I run it (with alsa 1.0.3 as included in SuSE 9.1).
Why is that so? Did I forget to free something?
Both commenting out the snd_mixer_selem_register or the snd_mixer_load call will fix it, but that's not an option in real code (this is actually a stripped-down version of the code in MPlayer's ao_alsa.c)... Any hints on that??
Greetings,
Reimar Döffinger
#include <alsa/asoundlib.h>
int main() {
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
snd_mixer_class_t *class;
int err;
while (1) {
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, "default");
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_free(handle);
snd_mixer_detach(handle, "default");
snd_mixer_close(handle);// sleep(100);
}
}
At Wed, 12 Jan 2005 12:23:20 +0100,
Quoted 9 lines · Reimar Döffinger
Hi,
the attached code consumes more and more memory when I run it (with alsa 1.0.3 as included in SuSE 9.1).
Why is that so? Did I forget to free something?
Both commenting out thesnd_mixer_selem_registeror thesnd_mixer_loadcall will fix it, but that's not an option in real code (this is actually a stripped-down version of the code in MPlayer'sao_alsa.c)... Any hints on that??
Yep, it hits a memory leak bug.
The patch below should fix it.
Takashi
Index: alsa-lib/src/mixer/bag.c
===================================================================
RCS file: /suse/tiwai/cvs/alsa/alsa-lib/src/mixer/bag.c,v retrieving revision 1.4
src/mixer/bag.c +1 -0
@@ -59,6 +59,7 @@bag1_t *b =list_entry (pos, bag1_t, list);if (b->ptr == ptr) {list_del (&b->list); +free (b);return 0 ; } }
Quoted 4 lines · Takashi Iwai <tiwai <at> suse.de> writes:
At Wed, 12 Jan 2005 12:23:20 +0100,
Quoted 2 lines · Reimar Döffinger
the attached code consumes more and more memory when I run it (with alsa 1.0.3 as included in SuSE 9.1).
[...]
Quoted 4 lines
Quoted 1 line
Any hints on that??
Yep, it hits a memory leak bug.
The patch below should fix it.
Saw it is in CVS now. Thanks for fixing.
Greetings,
Reimar Döffinger
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt