24 May '13 - 18:55 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Memory leak in C Prog with BASS2.4 for linux  (Read 1178 times)
djtraumwelt
Posts: 20


« on: 25 Jul '10 - 09:46 »
Reply with quoteQuote

#include <dirent.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "bass.h"
#include "bassenc.h"
#include "bassmix.h"

HSTREAM chan1,chan2,mix,chan;
HENCODE enc1,enc2;
char file[200];
int flip=0,a=0,i=0,ende;
char buf[20000];

int main() {
   DIR *hdir;
   struct dirent *entry[500];

   hdir=opendir("/path/to/mp3");
   while(entry[i]=readdir(hdir)) i++;
   //closedir(hdir);
   ende=i;

   srand(time(0));

   BASS_Init(0,44100,0,0,0);

   mix=BASS_Mixer_StreamCreate(44100,2,BASS_MIXER_NONSTOP|BASS_STREAM_DECODE);

   while(1) {
i=rand()%ende;

sprintf(file,"/path/to/mp3/%s",entry[i]->d_name);

if (flip==0) {
chan1=BASS_StreamCreateFile(0,file,0,0,BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mix,chan1,BASS_STREAM_AUTOFREE);
flip=1;
chan=chan1;
}
else {
chan2=BASS_StreamCreateFile(0,file,0,0,BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mix,chan2,BASS_STREAM_AUTOFREE);
flip=0;
chan=chan2;
}

    if (a==0) {
a=1;
enc1=BASS_Encode_Start(mix,"lame -b 128 - -",BASS_ENCODE_AUTOFREE,0,0);
enc2=BASS_Encode_Start(mix,"aacplusenc - - 32",BASS_ENCODE_AUTOFREE,0,0);
BASS_Encode_CastInit(enc1,"localhost:8000","sax",BASS_ENCODE_TYPE_MP3,"Traumwelt Radio","http://www.djtraumwelt.de","Elektro / Minimal",0,0,128,1);
BASS_Encode_CastInit(enc2,"localhost:8010","copy",BASS_ENCODE_TYPE_AAC,"Traumwelt Radio","http://www.djtraumwelt.de","Elektro / Minimal",0,0,32,1);
    }

BASS_Encode_CastSetTitle(enc1,entry[i]->d_name,"http://www.djtraumwelt.de");
BASS_Encode_CastSetTitle(enc2,entry[i]->d_name,"http://www.djtraumwelt.de");
while (BASS_ChannelIsActive(chan) && BASS_Encode_IsActive(enc1) && BASS_Encode_IsActive(enc2)) {
BASS_ChannelGetData(mix, buf, sizeof(buf)); // process some data
}

BASS_Mixer_ChannelRemove(chan1);
BASS_Mixer_ChannelRemove(chan2);
BASS_StreamFree(chan1);
BASS_StreamFree(chan2);
if (!BASS_Encode_IsActive(enc1) || !BASS_Encode_IsActive(enc2)) {
BASS_Encode_Stop(enc1);
BASS_Encode_Stop(enc2);
BASS_StreamFree(enc1);
BASS_StreamFree(enc2);
a=0;
sleep(1);
}

   }

return 0;
}

this is my autodj and always when the next track is playing, more memory it uses. more and more and more. anyone here, who knows the reason?
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #1 on: 26 Jul '10 - 14:01 »
Reply with quoteQuote

Just to be sure, is it your process's memory usage that rises or Linux's? Linux caches files that it reads in memory, so that would explain the latter. If that's not it, how fast and when is the memory usage growing?
Logged
djtraumwelt
Posts: 20


« Reply #2 on: 26 Jul '10 - 15:38 »
Reply with quoteQuote

thats to difficult for me. go slowly, please. linux caches the files. how can i see, if thats the problem and how can i free this cache?

it uses always more memory, when the next song is played. not faster and not slower. on my server there are 512 MB memory and on starting my autodj it uses 0.3% of this space and one day later it uses 4.5%.

thanks so far and greets from germany (thats the reason for bad english, if there is some)

edit:
it is the process's memory usage, because i mean the usage of the output from 'ps xv|grep autodj' - there the system shows 0.3% and 0.7% an hour later...
« Last Edit: 26 Jul '10 - 15:40 by djtraumwelt » Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #3 on: 26 Jul '10 - 16:47 »
Reply with quoteQuote

If you run "pmap <YourProcessId>" at the start and then again later, how does the output compare? Also, to narrow down where the problem lies, does it still happen if you remove the BASSenc stuff, eg. the BASS_Encode_Start/CastInit calls?
Logged
djtraumwelt
Posts: 20


« Reply #4 on: 26 Jul '10 - 19:34 »
Reply with quoteQuote

alex@vs0922:~$ pmap 3695
3695:   /home/aac/autodj
 total        0K
alex@vs0922:~$

this both times. i tryed pmap --help and then
alex@vs0922:~$ pmap -x 3695
3695:   /home/aac/autodj
Address   Kbytes     RSS    Anon  Locked Mode   Mapping
-------- ------- ------- ------- -------
total kB       0       -       -       -
alex@vs0922:~$ 

think, that this means, there are no files in cache, right?

edit:
when i remove the bassenc stuff, that helps nothing. the problem is anywhere else
« Last Edit: 26 Jul '10 - 19:43 by djtraumwelt » Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #5 on: 27 Jul '10 - 15:52 »
Reply with quoteQuote

That pmap output is empty for some reason; it should show the memory usage of the process, something like the example shown here...

   http://compute.cnr.berkeley.edu/cgi-bin/man-cgi?pmap

I guess it is disabled in your Linux distro. Do you have another Linux system that you can do your tests on? Perhaps you could use a "Live CD" on the same system?
Logged
djtraumwelt
Posts: 20


« Reply #6 on: 27 Jul '10 - 16:25 »
Reply with quoteQuote

on my server is debian lenny5... and on my desktop at home too. on my server pmap shows nothing and on my desktop at home it show the info we need. thats very mysterious.
alex@Alex-Debian:~$ pmap 8781
8781:   autodj
08048000      4K r-x--  /home/alex/bin/autodj
08049000      4K rw---  /home/alex/bin/autodj
0804a000    240K rw---    [ anon ]
b554d000      4K -----    [ anon ]
b554e000   8192K rwx--    [ anon ]
b5d4e000      4K -----    [ anon ]
b5d4f000   8192K rwx--    [ anon ]
b654f000     64K r-x--  /lib/i686/cmov/libresolv-2.7.so
b655f000      8K rw---  /lib/i686/cmov/libresolv-2.7.so
b6561000      8K rw---    [ anon ]
b6563000     16K r-x--  /lib/i686/cmov/libnss_dns-2.7.so
b6567000      8K rw---  /lib/i686/cmov/libnss_dns-2.7.so
b6569000      8K r-x--  /lib/libnss_mdns4_minimal.so.2
b656b000      4K rw---  /lib/libnss_mdns4_minimal.so.2
b656c000     40K r-x--  /lib/i686/cmov/libnss_files-2.7.so
b6576000      8K rw---  /lib/i686/cmov/libnss_files-2.7.so
b6578000      4K -----    [ anon ]
b6579000   8192K rwx--    [ anon ]
b6d79000      4K -----    [ anon ]
b6d7a000   8192K rwx--    [ anon ]
b757a000      8K rw---    [ anon ]
b757c000    144K r-x--  /lib/i686/cmov/libm-2.7.so
b75a0000      8K rw---  /lib/i686/cmov/libm-2.7.so
b75a2000     84K r-x--  /lib/i686/cmov/libpthread-2.7.so
b75b7000      8K rw---  /lib/i686/cmov/libpthread-2.7.so
b75b9000      8K rw---    [ anon ]
b75bb000      8K r-x--  /lib/i686/cmov/libdl-2.7.so
b75bd000      8K rw---  /lib/i686/cmov/libdl-2.7.so
b75bf000   1364K r-x--  /lib/i686/cmov/libc-2.7.so
b7714000      4K r----  /lib/i686/cmov/libc-2.7.so
b7715000      8K rw---  /lib/i686/cmov/libc-2.7.so
b7717000     12K rw---    [ anon ]
b771a000     20K r-x--  /usr/lib/libbassenc.so
b771f000      4K rw---  /usr/lib/libbassenc.so
b7720000      4K rw---    [ anon ]
b7721000     32K r-x--  /usr/lib/libbassmix.so
b7729000      4K rw---  /usr/lib/libbassmix.so
b772a000    128K rw---    [ anon ]
b774a000    208K r-x--  /usr/lib/libbass.so
b777e000      4K rw---  /usr/lib/libbass.so
b777f000    216K rw---    [ anon ]
b77c7000      8K rw---    [ anon ]
b77c9000      4K r-x--    [ anon ]
b77ca000    104K r-x--  /lib/ld-2.7.so
b77e4000      8K rw---  /lib/ld-2.7.so
bffd8000    148K rwx--    [ stack ]
bfffd000      8K rw---    [ anon ]
 total    35760K
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #7 on: 27 Jul '10 - 17:36 »
Reply with quoteQuote

Please post the "pmap" output from when you start running your test and then again later for comparison. So that the comparison is like for like, it would probably be a good idea to add a pause (eg. a "getch" call) at the end of the loop, during which you can run "pmap". Also, to eliminate as many variables as possible, keep the BASSenc calls out.
Logged
djtraumwelt
Posts: 20


« Reply #8 on: 29 Jul '10 - 13:33 »
Reply with quoteQuote

i called this pmap on start and got the same output later. ps xv|grep autodj shows, that there is no memory leak on my home computer. it must be one of the libs on the server. i will contact the renter of the server, if he knows, where the problem is.
Logged
djtraumwelt
Posts: 20


« Reply #9 on: 29 Jul '10 - 19:50 »
Reply with quoteQuote

the renter of my vserver has an option "install another image" and i installed opensuse 11.0 and on this system the autodj works without memory leak. thank you very much for supporting me!
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines