Memory Leak

HI guys, I’m been using the SDL Library and i found out that there is a
memory leak problem, my program is a simple media player and its eating like
1k memory every 15 seconds. I thought it was my program and i downloaded
the kmtracer program and i checked out and found this bug. I was testing
out the program and this is the result of my test.

Manny.-

[root at localhost myplayer]# ktrace ./vplay /dev/video
*** glibc detected *** ./vplay: double free or corruption (!prev):
0x08376030 * **
======= Backtrace: =========
/lib/libc.so.6[0x47b9f98e]
/lib/libc.so.6(__libc_free +0x70)[0x47ba2bd0]
/lib/libc.so.6(fclose+0x124)[0x47b910f4]
/usr/lib/libktrace.so(fork+0x42)[0xb7e191ac]
/usr/lib/libesd.so.0(esd_open_sound+0x2da)[0x49821d7c]
/usr/lib/libSDL-1.2.so.0[0x4983c09a]
/usr/lib/libSDL-1.2.so.0(SDL_AudioInit+0x1e8)[0x498352cb]
/usr/lib/libSDL-1.2.so.0(SDL_InitSubSystem+0x8e)[0x4983409e]
/usr/lib/libSDL-1.2.so.0(SDL_Init+0x23)[0x4983417c]
./vplay(main+0x57)[0x8059077]
/lib/libc.so.6(__libc_start_main+0xc6)[0x47b5558e]
./vplay[0x8054cd1]

======= Memory map: ========
08048000-08307000 r-xp 00000000 03:45 98299
/root/Desktop/player/myplayer/vplay
08307000-08317000 rw-p 002be000 03:45 98299
/root/Desktop/player/myplayer/vplay
08317000-0845b000 rw-p 08317000 00:00 0 [heap]
47b25000-47b3c000 r-xp 00000000 03:45 555432 /lib/ld-2.4.90.so
47b3c000-47b3d000 r–p 00016000 03:45 555432 /lib/ld-2.4.90.so
47b3d000-47b3e000 rw-p 00017000 03:45 555432 /lib/ld-2.4.90.so
47b40000-47c60000 r-xp 00000000 03:45 555433 /lib/libc-2.4.90.so
47c60000-47c62000 r–p 00120000 03:45 555433 /lib/libc-2.4.90.so
47c62000-47c63000 rw-p 00122000 03:45 555433 /lib/libc-2.4.90.so
47c63000-47c66000 rw-p 47c63000 00:00 0
47c68000-47c8c000 r-xp 00000000 03:45 555434 /lib/libm-2.4.90.so
47c8c000-47c8d000 r–p 00023000 03:45 555434 /lib/libm-2.4.90.so
47c8d000-47c8e000 rw-p 00024000 03:45 555434 /lib/libm-2.4.90.so
47c90000-47c92000 r-xp 00000000 03:45 555436 /lib/libdl-2.4.90.so
47c92000-47c93000 r–p 00001000 03:45 555436 /lib/libdl-2.4.90.so
47c93000-47c94000 rw-p 00002000 03:45 555436 /lib/libdl-2.4.90.so============================================

leak of 2 bytes in 1 block
libc.so.6(malloc+0x26)
libX11.so.6(_XlcCreateLC+0x87)
libX11.so.6(_XldDynamicLoad+0x3b8)
libX11.so.6(_XOpenLC+0x95)
libX11.so.6(_XrmInitParseInfo+0x1e)
libX11.so.6(_XrmGetStringDatabase+0x18)
libX11.so.6(XGetDefault+0x10e)
libXcursor.so.1(_XcursorGetDisplayInfo+0x5d8)
libXcursor.so.1(XcursorSupportARGB+0x1d)
libX11.so.6(XcursorNoticeCreateBitmap+0x1f)
libX11.so.6(XCreatePixmap+0xc7)
libSDL-1.2.so.0(X11_CreateWMCursor+0x143)
libSDL-1.2.so.0(SDL_VideoInit0x22b)
libSDL-1.2.so.0(SDL_InitSubSystem+0x12f)
libSDL-1.2.so.0(SDL_init+0x23)
???(main)
libc.so.6( _lib_start_main+0xc6)

I am facing problem (Getting memory leak when I run the ffplay.cpp file ) with purify .I donot know where i am wrong .
They are as :-
[W] MLK: Memory leak of 66 bytes from 4 blocks allocated in callthreadstartex [MSVCR80.dll]
Distribution of leaked blocks
Allocation location
HeapAlloc [C:\WINDOWS\system32\KERNEL32.dll]
callthreadstartex [f:\sp\vctools\crt_bld\self_x86\crt\src\threadex.c:348]
threadstartex [f:\sp\vctools\crt_bld\self_x86\crt\src\threadex.c:326]
[W] MLK: Memory leak of 20 bytes from 1 block allocated in SDL_KillThread [SDL.dll]
Distribution of leaked blocks
Allocation location
malloc [f:\sp\vctools\crt_bld\self_x86\crt\src\malloc.c:155]
SDL_KillThread [C:\Vzphone\CheckMem\CheckMem\debug\SDL.dll]
video_refresh_timer [c:\vzphone\checkmem\checkmem\ffplay.c:1111]
event_loop [c:\vzphone\checkmem\checkmem\ffplay.c:2314]
SDL_main [c:\vzphone\checkmem\checkmem\ffplay.c:2367]
main [C:\Vzphone\CheckMem\CheckMem\debug\CheckMem.exe]
WinMain [C:\Vzphone\CheckMem\CheckMem\debug\CheckMem.exe]
??? [ip=0x0013F0EB]
_dyn_tls_init_callback [C:\Vzphone\CheckMem\CheckMem\debug\CheckMem.exe]

thanks,
Pankaj

PS : If you want the file i can send it to you also. The are in ffplay.c file

  Send a FREE SMS to your friend's mobile from Yahoo! Messenger. Get it now at http://in.messenger.yahoo.com/

[W] MLK: Memory leak of 66 bytes from 4 blocks allocated in callthreadstartex [MSVCR80.dll]

Don’t use SDL_KillThread. The thread doesn’t exit cleanly, so it doesn’t
have a chance to clean up resources it allocated.

Better to set a variable that the thread checks and then exits on its
own when asked to.

–ryan.

Thanks for the reply. I will take out SDL_KillThread for the application .> ----- Original Message -----

From: icculus@icculus.org (icculus)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, 18 April, 2007 10:21:28 PM
Subject: Re: [SDL] Memory Leak

[W] MLK: Memory leak of 66 bytes from 4 blocks allocated in callthreadstartex [MSVCR80.dll]

Don’t use SDL_KillThread. The thread doesn’t exit cleanly, so it doesn’t
have a chance to clean up resources it allocated.

Better to set a variable that the thread checks and then exits on its
own when asked to.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Send a FREE SMS to your friend's mobile from Yahoo! Messenger. Get it now at http://in.messenger.yahoo.com/

Hi ,

There is one problem i am using the SDL library ( a dll ) in which everything is built in so i do not have a choice of chosing a function . Moreover , functions like SDL_OpenAudio are giving me huge memory leaks. It seems that if i run the applicaiton once and just decode a 3 minute tralior i am getting about 1MB of leaks which is unimaginable, all i am doing is using the ffmpeg library. Though i am using Rational Purify to check for the leaks but it only points to some functions like SDL_OpenAudio() othersiwe it just gives me some potetial leaks in AVCODEC library .
It would be great if atleast i can get some pointer to find and cure the leaks . Though i have debugged the code in VC++ but nothing seems fishy there.

thanks,
Pankaj

PS: If we know that SDL_KillThread is having leaks then we can avoid using it next releases.> ----- Original Message -----

From: @Pankaj (Pankaj)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Thursday, 19 April, 2007 7:56:32 PM
Subject: Re: [SDL] Memory Leak

Thanks for the reply. I will take out SDL_KillThread for the application .

----- Original Message ----
From: icculus@icculus.org (icculus)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, 18 April, 2007 10:21:28 PM
Subject: Re: [SDL] Memory Leak

[W] MLK: Memory leak of 66 bytes from 4 blocks allocated in callthreadstartex [MSVCR80.dll]

Don’t use SDL_KillThread. The thread doesn’t exit cleanly, so it doesn’t
have a chance to clean up resources it allocated.

Better to set a variable that the thread checks and then exits on its
own when asked to.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Send a FREE SMS to your friend's mobile from Yahoo! Messenger. Get it now at http://in.messenger.yahoo.com/

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Add online presence to your web pages, find out how here - http://messenger.yahoo.com/addpresence.php

Pankaj wrote:

There is one problem i am using the SDL library ( a dll ) in which everything is built in so i do not have a choice of chosing a function . Moreover , functions like SDL_OpenAudio are giving me huge memory leaks. It seems that if i run the applicaiton once and just decode a 3 minute tralior i am getting about 1MB of leaks which is unimaginable, all i am doing is using the ffmpeg library. Though i am using Rational Purify to check for the leaks but it only points to some functions like SDL_OpenAudio() othersiwe it just gives me some potetial leaks in AVCODEC library .

Are you sure these are leaks and not buffered datas?

I know that avcodec internally keeps some static buffers for a lot of
stuff, OpenAudio creates a thread and inits one or more audio buffers
that are released only by SDL_QuitSubsystem() or SDL_Quit(), one MB
seems fair as buffering for audio/video in mpeg decoding.

If you decode for 6 minutes you have 2mb of leaks, if it doesn’t grow
with time you cannot be sure it’s a leak. Leak detection programs like
valgrind or the Rational Purify you are using are mostly useful to check
your code, it’s very difficult to use them to check code you didn’t know.–
Bye,
Gabry

I am sure about them as memory leaks because if i run the application again and again then i am able notice with task manager that the memory application is usinng increases by 1 MB and i never get it back . When we run the same application again and again in the real device then also it dries down due to lack of memory.

thanks,
Pankaj> ----- Original Message -----

From: gabriele.greco@darts.it (Gabriele Greco)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Thursday, 26 April, 2007 6:08:35 AM
Subject: Re: [SDL] [SPAM] Re: Memory Leak

Pankaj wrote:

There is one problem i am using the SDL library ( a dll ) in which everything is built in so i do not have a choice of chosing a function . Moreover , functions like SDL_OpenAudio are giving me huge memory leaks. It seems that if i run the applicaiton once and just decode a 3 minute tralior i am getting about 1MB of leaks which is unimaginable, all i am doing is using the ffmpeg library. Though i am using Rational Purify to check for the leaks but it only points to some functions like SDL_OpenAudio() othersiwe it just gives me some potetial leaks in AVCODEC library .

Are you sure these are leaks and not buffered datas?

I know that avcodec internally keeps some static buffers for a lot of
stuff, OpenAudio creates a thread and inits one or more audio buffers
that are released only by SDL_QuitSubsystem() or SDL_Quit(), one MB
seems fair as buffering for audio/video in mpeg decoding.

If you decode for 6 minutes you have 2mb of leaks, if it doesn’t grow
with time you cannot be sure it’s a leak. Leak detection programs like
valgrind or the Rational Purify you are using are mostly useful to check
your code, it’s very difficult to use them to check code you didn’t know.


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Add online presence to your web pages, find out how here - http://messenger.yahoo.com/addpresence.php

Pankaj wrote:

I am sure about them as memory leaks because if i run the application again and again then i am able notice with task manager that the memory application is usinng increases by 1 MB and i never get it back . When we run the same application again and again in the real device then also it dries down due to lack of memory.

What OS is your target? Most modern OSes free ALL the application
memory, handles, windows, resources, locks when the application exits.–
Bye,
Gabry

Hi,

We have an application that runs on windows but it runs forever so it never comes out or exits , i think due to this reason the OS does not get a chance to clean memory.

Basically ,if i know the module which is leaking then may be it can be recoded. I am just curious to know if anybody gets such a problem then what would be the typical respose and the way to debug it.

I am using both FFPLAY and SDL libraries .

Mostly we are allocating the memory for managing of packets which we are deallocating in the same function so even in the application i am not able to find anything fishy. I think i have to track all the mallocs and demallocs which seems to be my only option to get the memory leaks .

thanks,
Pankaj> ----- Original Message -----

From: gabriele.greco@darts.it (Gabriele Greco)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Thursday, 26 April, 2007 10:44:04 AM
Subject: Re: [SDL] [SPAM] Re: [SPAM] Re: Memory Leak

Pankaj wrote:

I am sure about them as memory leaks because if i run the application again and again then i am able notice with task manager that the memory application is usinng increases by 1 MB and i never get it back . When we run the same application again and again in the real device then also it dries down due to lack of memory.

What OS is your target? Most modern OSes free ALL the application
memory, handles, windows, resources, locks when the application exits.


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Add online presence to your web pages, find out how here - http://messenger.yahoo.com/addpresence.php

PS: If we know that SDL_KillThread is having leaks then we can avoid
using it next releases.

SDL_KillThread() will definitely cause at least a small leak on some
platforms. Never, never use it.

If SDL_OpenAudio() is leaking, though, it’s either a bug or the audio
device is never being closed: make sure you call SDL_Quit() before your
program terminates to do so or you will definitely “leak” memory (but,
being the end of the program, it’s not really a leak, as the OS will
free it anyhow.)

–ryan.

Hi,
i’m making my little program, kinda remake of robocop arcade bonus stage.
I noticed a memory leak when i call my function “calcular_render”, grabbing 200
kb /second. I dunno what might be the cause. Any ideas? Thanks in advance,
here’s the complete code (I’m working in DevCpp):

This is a Class i’m using:

class Csprite
{
public:
int layer;
int x0,y0;
int xactual,yactual;
int velocidad;
int idximagenes1;
int idximagenes2;
int idximagenes3;
int idximagenes4;
int idximagenes5;

SDL_TimerID spritetimer;
//SDL_NewTimerCallback
//Uint32 callbacktimerproc(Uint32 intervalo,void *param);
bool activo;
FILE *archlog;

char imagenes1[20][256];
char imagenes2[20][256];
char imagenes3[20][256];
char imagenes4[20][256];
char imagenes5[20][256];

char frameactual[256];
//char caminar[7][256];
char pegar1[13][256];

void logger_open(char spriteID[256]);
void logger_write(char* txt);
void logger_close();
void initpos(int idx){idx = 0;};
void sel_frameactual(char* factual);
//void mandar_a_mainframe(SDL_Surface mainframe,bool clsok);
void fill_image_arrays(char
img0,char* img1,char* img2,char* img3,char*
img4,char* img5,
char* img6,char* img7,char* img8,char* img9,char* img10,int vecnum);

void changespriteattr(int x,int y,int velocidad);

char diractual[256];
char wkingdir_sprites[256];
char wkingdir_sounds[256];
char wkingdir_background[256];
void setwkingdir(HWND handler);

};

This is an array of pointers to Csprite Class i’m using:

Csprite* sprites1[10];

This is the mainloop:

int maingameloop(HWND handler)
{

SDL_KeyboardEvent *tclevento;
SDL_Event evento;
int running = 1;
int X0 = 100;
int Y0 = 220;
bool salir;
int opsalir;

//eliminar despues de probar, son de calcular_render
int e;
int t;
SDL_Surface *imagen;
SDL_Rect dest;

salir = false; /SDL_DEFAULT_REPEAT_DELAY = 500/
/SDL_DEFAULT_REPEAT_INTERVAL = 30/

//mira.initpos();

//mira.changespriteattr(200,100,3);

cuadro_princi.logger_write(“mira.initpos();”);

sprites1[0]->sel_frameactual(sprites1[0]->imagenes1[0]);
sprites1[1]->sel_frameactual(sprites1[1]->imagenes1[0]);

cuadro_princi.logger_write(“mira.sel_frameactual(mira.imagenes1[0]);”);

cuadro_princi.logger_write(sprites1[0]->frameactual);
cuadro_princi.logger_write(sprites1[1]->frameactual);

//mira.mandar_a_mainframe(cuadro_princi.screen,true);
cuadro_princi.logger_write(“mira.mandar_a_mainframe(cuadro_princi.screen);”);

calcular_render();

//MessageBox(handler,“antes de todo”,"",MB_OK);

cuadro_princi.showframe();

cuadro_princi.rendertimer = SDL_AddTimer(100,callbackRENDER,0);

cuadro_princi.logger_write(“cuadro_princi.showframe();”);

SDL_EnableKeyRepeat(100 ,10);
//16.67 ms
pause = FALSE;

//cuadro_princi.clsok = true;

while(!salir)
{

                                     //30 ms aprox

cuadro_princi.intervalo_render = 100;
cuadro_princi.time_refbase = 0;
cuadro_princi.time_actual = 0;

while(running)
{
while(SDL_PollEvent(&evento) )
{

 /*if(cuadro_princi.time_refbase != -1)
    cuadro_princi.time_refbase = SDL_GetTicks();
    
   
 if( cuadro_princi.tomar_tiempo(cuadro_princi.intervalo_render))
   cuadro_princi.time_actual = SDL_GetTicks();*/
 
 /*if( cuadro_princi.tomar_tiempo(cuadro_princi.intervalo_render))
   {
   cuadro_princi.showframe();
   
   }*/
 
  
  switch(evento.type)
    {
    case SDL_USEREVENT:
         
         switch(evento.user.code)
          {
          case 666:
               calcular_render();
               
               cuadro_princi.showframe();
               break;
          
          case 0:
               
               
               
               break;

          }
          break;
          
    case SDL_KEYDOWN: 
        case SDL_KEYUP:  
             switch(evento.key.keysym.sym)
              {
              //tropico = 0
              //meridiano = 1
              case SDLK_LEFT:
                   //dibujar meridiano |
                   
                   sprites1[1]->changespriteattr(sprites1[1]->xactual -

sprites1[1]->velocidad,0,3);

                   //calcular_render(cuadro_princi.screen,handler);
                   
                   
                   
                   break;
                   
              case SDLK_RIGHT:
                   //dibujar meridiano |
                   
                   sprites1[1]->changespriteattr(sprites1[1]->xactual +

sprites1[1]->velocidad,0,3);

                   //calcular_render(cuadro_princi.screen,handler);
                                          
                   
                   
                   break;
              
              
              case SDLK_UP:
                   //dibujar tropico  -

sprites1[0]->changespriteattr(sprites1[0]->xactual,sprites1[0]->yactual -
sprites1[0]->velocidad,3);

                   //calcular_render(cuadro_princi.screen,handler);
                                          
                   
                   
                   
                   break;
              
              case SDLK_DOWN:
                   //dibujar tropico  -

sprites1[0]->changespriteattr(sprites1[0]->xactual,sprites1[0]->yactual +
sprites1[0]->velocidad,3);

                   //calcular_render(cuadro_princi.screen,handler);
                                          
                   
                   break;
              
              case SDLK_p:
                   
                 
                   break;
                   
              case SDLK_RETURN:

//SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void
*param);

                   break;
                   
              case SDLK_ESCAPE:
                   
                   running = 0;
                   
                   break;
              }
             
             break;
    
     case SDL_QUIT:   
          
          running = 0;  
             break;
    }
 
 }

} //while running

opsalir = MessageBox(handler,“Salir no jogo?”,“Pregunta de los que
saben”,MB_YESNOCANCEL | MB_ICONQUESTION);

if( opsalir == IDYES)
salir = 1;

}//while !salir

SDL_RemoveTimer(cuadro_princi.rendertimer);
return 0;
}

And this is the leaking function itself:

void calcular_render()
{
int e;
int t;
SDL_Surface *imagen;
SDL_Rect dest;

//sprites1[0]->logger_write(“Calcular Render”);

//LAYER 3 = fondo
for(e =0;e<11;e++)
{
//si el puntero a csprite no es nulo y esta activo
if( (sprites1[e] != 0) && ( sprites1[e]->activo != 0) )
{

if(sprites1[e]->layer == 3)
 { 
 
 //sprites1[e]->logger_write("LAYER 3 FOUND");
 
 if( strcmp( sprites1[e]->imagenes1[sprites1[e]->idximagenes1],"nil") != 0)
   {
   
    //sprites1[e]->logger_write("LAYER 3 INSIDE");

sprites1[e]->sel_frameactual(sprites1[e]->imagenes1[sprites1[e]->idximagenes1]);

    //sprites1[e]->logger_write("Csprite: Loading Image :");
    //sprites1[e]->logger_write(sprites1[e]->frameactual);
    
    imagen = SDL_LoadBMP(sprites1[e]->frameactual); 
    

    //sprites1[e]->logger_write("Csprite: SDL_SetColorKey( )");
                                                            //cyan
    SDL_SetColorKey( imagen, SDL_SRCCOLORKEY, SDL_MapRGB(imagen->format,

255, 0, 255) );

    //sprites1[e]->logger_write("Csprite: asignando valores a Rectangulo Dest");
    
    dest.x = sprites1[e]->xactual;
    dest.y = sprites1[e]->yactual;
    dest.w = imagen->w;
    dest.h = imagen->h;
    
    //sprites1[e]->logger_write("Csprite: Blitting surface : SDL_BlitSurface");
    SDL_BlitSurface(imagen, NULL, cuadro_princi.screen, &dest);
   
   }
 
 
 
 }

}

}//for LAYER 3

SDL_FreeSurface(imagen);

//LAYER 2 = ENEMIGOS
for(e =0;e<11;e++)
{
//si el puntero a csprite no es nulo y esta activo
if( (sprites1[e] != 0) && ( sprites1[e]->activo != 0) )
{

if(sprites1[e]->layer == 2)
 { 
   //sprites1[e]->logger_write("LAYER 2 FOUND");
 
 if( strcmp( sprites1[e]->imagenes1[sprites1[e]->idximagenes1],"nil") != 0)
   {

    //sprites1[e]->logger_write("LAYER 2 INSIDE");

sprites1[e]->sel_frameactual(sprites1[e]->imagenes1[sprites1[e]->idximagenes1]);

    //sprites1[e]->logger_write("Csprite: Loading Image :");
    //sprites1[e]->logger_write(sprites1[e]->frameactual);
    
    imagen = SDL_LoadBMP(sprites1[e]->frameactual); 

    //sprites1[e]->logger_write("Csprite: SDL_SetColorKey( )");
                                                            //cyan
    SDL_SetColorKey( imagen, SDL_SRCCOLORKEY, SDL_MapRGB(imagen->format,

255, 0, 255) );

    //sprites1[e]->logger_write("Csprite: asignando valores a Rectangulo Dest");
    
    dest.x = sprites1[e]->xactual;
    dest.y = sprites1[e]->yactual;
    dest.w = imagen->w;
    dest.h = imagen->h;
    
    //sprites1[e]->logger_write("Csprite: Blitting surface : SDL_BlitSurface");
    SDL_BlitSurface(imagen, NULL, cuadro_princi.screen, &dest);
   }
 
 
 
 }

}

}//for LAYER 2

SDL_FreeSurface(imagen);

//LAYER 1 = objetos controlados por el jugador
for(e =0;e<11;e++)
{
//si el puntero a csprite no es nulo y esta activo
if( (sprites1[e] != 0) && ( sprites1[e]->activo != 0) )
{

if(sprites1[e]->layer == 1)
 { 
    //sprites1[e]->logger_write("LAYER 1 FOUND"); 
 if( strcmp( sprites1[e]->imagenes1[sprites1[e]->idximagenes1],"nil") != 0)
   {

    //sprites1[e]->logger_write("LAYER 1 INSIDE");

sprites1[e]->sel_frameactual(sprites1[e]->imagenes1[sprites1[e]->idximagenes1]);

    //MessageBox(handler,"Layer 1 sel_frameactual","",MB_OK);
    
    //sprites1[e]->logger_write("Csprite: Loading Image :");
    //sprites1[e]->logger_write(sprites1[e]->frameactual);
    
    imagen = SDL_LoadBMP(sprites1[e]->frameactual); 
    
    //MessageBox(handler,"Layer 1 SDL_LOADBMP OK","",MB_OK);
    //MessageBox(handler,"Layer 1 BMP = ",sprites1[e]->frameactual,MB_OK);
    
    if(!imagen)
      {
      sprites1[e]->logger_write("Error! imagen is NULL ");
      //MessageBox(handler,"Layer 1 SDL_LOADBMP: !IMAGEN","",MB_OK);
      }
    
    //sprites1[e]->logger_write("Csprite: SDL_SetColorKey( )");
                                                            //cyan
    SDL_SetColorKey( imagen, SDL_SRCCOLORKEY, SDL_MapRGB(imagen->format,

255, 0, 255) );

    //MessageBox(handler,"Layer 1 SETCOLORKEY OK","",MB_OK);
    
    //sprites1[e]->logger_write("Csprite: asignando valores a Rectangulo Dest");
    
    dest.x = sprites1[e]->xactual;
    dest.y = sprites1[e]->yactual;
    dest.w = imagen->w;
    dest.h = imagen->h;
    
    //sprites1[e]->logger_write("Csprite: Blitting surface : SDL_BlitSurface");
    if(SDL_BlitSurface(imagen, NULL, cuadro_princi.screen, &dest) == -1 )
      sprites1[e]->logger_write("SDL_BlitSurface Failed");
   }
 
 
 
 }

}

}//for LAYER 1

//MessageBox(handler,“Layer 1 ok”,"",MB_OK);

SDL_FreeSurface(imagen);
}

Behalf Of Manuel Lopez Blasi

Hi,
i’m making my little program, kinda remake of robocop arcade bonus stage.
I noticed a memory leak when i call my function “calcular_render”, grabbing
200 kb /second. I dunno what might be the cause. Any ideas? Thanks in
advance, here’s the complete code (I’m working in DevCpp):


I would gladly help but I do not see the definition for the "cuadro_princi"
class that you use throughout your example.

Ken Rogoway
Homebrew Software
http://www.homebrewsoftware.com/

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.487 / Virus Database: 269.13.16/1005 - Release Date: 9/13/2007
11:45 AM

----- Original Message -----
From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Sent: Thursday, September 13, 2007 10:28 PM
To: sdl at libsdl.org
Subject: [SDL] Memory Leak

Behalf Of Manuel Lopez Blasi

Hi,
i’m making my little program, kinda remake of robocop arcade bonus stage.
I noticed a memory leak when i call my function “calcular_render”, grabbing
200 kb /second. I dunno what might be the cause. Any ideas? Thanks in
advance, here’s the complete code (I’m working in DevCpp):


The problem is pretty obvious. In your calcular_render() function you call
SDL_LoadBMP() 11 times, but only free one of the images you load. Move your
call to SDL_FreeSurface(imagen); right after you call
SDL_BlitSurface(imagen, NULL, cuadro_princi.screen, &dest);

That will fix the leak.

Ken Rogoway
Homebrew Software
http://www.homebrewsoftware.com/

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.487 / Virus Database: 269.13.16/1005 - Release Date: 9/13/2007
11:45 AM

----- Original Message -----
From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Sent: Thursday, September 13, 2007 10:28 PM
To: sdl at libsdl.org
Subject: [SDL] Memory Leak

Ken Rogoway <Ken HomebrewSoftware.com> writes:

lists.libsdl.org] On> -----Original Message-----

From: sdl-bounces lists.libsdl.org [mailto:sdl-bounces
Behalf Of Manuel Lopez Blasi
Sent: Thursday, September 13, 2007 10:28 PM
To: sdl libsdl.org
Subject: [SDL] Memory Leak

Hi,
i’m making my little program, kinda remake of robocop arcade bonus stage.
I noticed a memory leak when i call my function “calcular_render”, grabbing
200 kb /second. I dunno what might be the cause. Any ideas? Thanks in
advance, here’s the complete code (I’m working in DevCpp):


I would gladly help but I do not see the definition for the "cuadro_princi"
class that you use throughout your example.

Hi Ken, here’s the definition:

cuadro_princi is of Cframe class wich is:

Cframe cuadro_princi;

class Cframe
{
public:
SDL_Surface *screen;
FILE *archlog;
Uint32 time_refbase;
Uint32 time_actual;

SDL_TimerID rendertimer;

int intervalo_render;
bool clsok;
void init_clsok(){clsok=false;};
bool tomar_tiempo(int intervalo);
void showframe();
void initfondo();

void logger_open(char spriteID[256]);
void logger_write(char* txt);
void logger_close();
bool INISDL_OK(HWND hwnd);
bool BeginDraw(int largo,int alto,int colordepth,HWND handler);
int minlimiter(int min,int valor);
int maxlimiter(int max,int valor);
int limiterpacman(int max,int valor);
};

cuadro_princi.screen is a SDL_Surface*

Thanks a lot!.

Ken Rogoway
Homebrew Software
http://www.homebrewsoftware.com/

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.487 / Virus Database: 269.13.16/1005 - Release Date: 9/13/2007
11:45 AM

THANK YOU SIR!!! problem fixed,

fool of me! LOL