SDL Memory Leaks detected using Valgrind

8.2k views Asked by At

Possible Duplicate:
Why does valgrind say basic SDL program is leaking memory?

So I've been using a SDL a lot in creating a small OpenGL application; I recently became interested in checking out how my memory is going (I have taken as much care as possible to ensure no memory leaks etc). But then I created the SDL driver in my program, and it all went down hill. I've isolated the code, and have no idea if I'm doing something wrong, if it is SDL, or maybe its a library SDL is using (see Valgrind results).

#include <SDL.h>

int main() {
    SDL_Surface* Screen;
    if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        return 1;
    }
    Screen = SDL_SetVideoMode(1280, 1024, 32, SDL_OPENGL);
    SDL_FreeSurface(Screen);
    SDL_Quit();
    return 0;
}

Now I can't exactly isolate more than 1 section, so I'll post the results from Valgrind here for the init by itself, and then for the entire program.

if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
    return 1;
}

==7485== LEAK SUMMARY:
==7485==    definitely lost: 16 bytes in 1 blocks
==7485==    indirectly lost: 176 bytes in 4 blocks
==7485==      possibly lost: 9,155 bytes in 14 blocks
==7485==    still reachable: 654,484 bytes in 1,484 blocks

Note: Using SDL_Quit() after the above code induces further memory leaks, so this isn't the fix (unfortunately). Now for the entire program (as initial source posted)(first error is repeated several times before the below is displayed):

==7515== Invalid write of size 1
==7515==    at 0x4C29910: memcpy (mc_replace_strmem.c:497)
==7515==    by 0xB9BE0CF: ??? (in /usr/lib/fglrx/dri/fglrx_dri.so)
==7515==  Address 0x7f42bca30fff is not stack'd, malloc'd or (recently) free'd
==7515== 
==7515== More than 10000000 total errors detected.  I'm not reporting any more.
==7515== Final error counts will be inaccurate.  Go fix your program!
==7515== Rerun with --error-limit=no to disable this cutoff.  Note
==7515== that errors may occur in your program without prior warning from
==7515== Valgrind, because errors are no longer being displayed.
==7515== 
==7515== HEAP SUMMARY:
==7515==     in use at exit: 4,539,966 bytes in 11,312 blocks
==7515==   total heap usage: 49,855 allocs, 38,543 frees, 40,485,815 bytes allocated
==7515== 
==7515== LEAK SUMMARY:
==7515==    definitely lost: 79,981 bytes in 126 blocks
==7515==    indirectly lost: 30,480 bytes in 54 blocks
==7515==      possibly lost: 3,374,770 bytes in 9,289 blocks
==7515==    still reachable: 1,054,735 bytes in 1,843 blocks
==7515==         suppressed: 0 bytes in 0 blocks
==7515== Rerun with --leak-check=full to see details of leaked memory

I am using Ubuntu 10.10 if it matters.

Second note; I am using Valgrind like so (incase that is the issue?):

valgrind ./main

Third note; fglrx is the Ubuntu ATI driver.

0

There are 0 answers