EDIT: updated with some new info (Bold'ed). Also, the code and Valgrinds output is updated.
I recently started using SDL2 as my graphics library. After developing some stuff, I decided to run Valgrind and found out that I am leaking memory... a lot of memory.
After narrowing it down I compiled this code (In C):
#include <SDL2/SDL.h>
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
This is the make file:
CC = gcc
CCFLAGS = -Wall -o0
LDFLAGS = -lSDL2
SOURCES= main.c
OBJECTS=$(SOURCES:.c=.o)
EXE = Test
.PHONY:
all: $(OBJECTS)
$(CC) $(OBJECTS) $(CCFLAGS) $(LDFLAGS) -o $(EXE)
clean:
rm $(OBJECTS) $(EXE)
And got this Valgrind error:
==30933== Memcheck, a memory error detector
==30933== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30933== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==30933== Command: ./Test
==30933==
==30933==
==30933== HEAP SUMMARY:
==30933== in use at exit: 308,407 bytes in 559 blocks
==30933== total heap usage: 9,346 allocs, 8,787 frees, 2,502,489 bytes allocated
==30933==
==30933== LEAK SUMMARY:
==30933== definitely lost: 197,226 bytes in 6 blocks
==30933== indirectly lost: 6,272 bytes in 8 blocks
==30933== possibly lost: 0 bytes in 0 blocks
==30933== still reachable: 104,909 bytes in 545 blocks
==30933== suppressed: 0 bytes in 0 blocks
==30933== Rerun with --leak-check=full to see details of leaked memory
==30933==
==30933== For counts of detected and suppressed errors, rerun with: -v
==30933== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
I looked around and saw many people complain about memory leaks in SDL, but they all were very small (about 16 bytes, not 200,000!). Also, I checked other examples from the internet, trying to run them on my computer, and they all had that same leak (from what I'm assuming is SDL_Init).
I am running on Ubuntu13-64Bit.