I'm writing a little wrapper to learn a bit about C and SDL2 in the same way.
Today i've decided to launch valgrind to test it and see it in action.
Well, the results are pretty scary! It seems to be like some others dyn libs on my system are leaking as hell! (We can clearly see SDL2 and OpenGL but the GPU driver seems in bad state too) : (running on mac os x yosemite). I've also pasted my code and i didn't see something wrong since i'm not allocating memory on the heap by hand. SDL2 is doing it on his own.
==35991== Memcheck, a memory error detector
==35991== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==35991== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==35991== Command: ./QSDL
==35991==
--35991-- ./QSDL:
--35991-- dSYM directory is missing; consider using --dsymutil=yes
==35991== Thread 2:
==35991== Invalid read of size 32
==35991== at 0x102908C1D: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==35991== by 0x10291C93A: pthread_setname_np (in /usr/lib/system/libsystem_pthread.dylib)
==35991== by 0x10004272A: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100042C64: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100042708: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10291C2FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==35991== by 0x10291C278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==35991== by 0x10291A4B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==35991== Address 0x109b53a80 is 32 bytes before a block of size 16 in arena "client"
==35991==
==35991== Invalid read of size 32
==35991== at 0x102908C1D: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==35991== by 0x10291C980: pthread_setname_np (in /usr/lib/system/libsystem_pthread.dylib)
==35991== by 0x10004272A: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100042C64: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100042708: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10291C2FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==35991== by 0x10291C278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==35991== by 0x10291A4B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==35991== Address 0x109b53a80 is 32 bytes before a block of size 16 in arena "client"
==35991==
--35991-- UNKNOWN __pthread_sigmask is unsupported.
--35991-- UNKNOWN host message [id 412, to mach_host_self(), reply 0x1003]
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x1003]
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
--35991-- UNKNOWN __pthread_sigmask is unsupported. (repeated 2 times)
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x1803]
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times)
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 8 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x30f]
==35991== Thread 1:
==35991== Conditional jump or move depends on uninitialised value(s)
==35991== at 0x105207C1D: _LSApplicationCheckIn (in /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices)
==35991== by 0x107E08565: _RegisterApplication (in /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices)
==35991== by 0x107E06C88: GetCurrentProcess (in /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices)
==35991== by 0x100043D99: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100047A12: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100079911: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10004025A: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100000972: initScreen (in ./QSDL)
==35991== by 0x100000D04: main (in ./QSDL)
==35991==
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x30f] (repeated 2 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x1803] (repeated 2 times)
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 16 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x30f] (repeated 4 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x1803] (repeated 4 times)
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 32 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x1803] (repeated 8 times)
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 64 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x30f] (repeated 8 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x3c0b]
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x3c0b] (repeated 2 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x2e0b]
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x2e0b] (repeated 2 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x2e0b] (repeated 4 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x30f] (repeated 16 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x3c0b] (repeated 4 times)
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 128 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x3c0b] (repeated 8 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x2e0b] (repeated 8 times)
--35991-- UNKNOWN task message [id 4816, to mach_task_self(), reply 0x30f]
--35991-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 256 times)
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x6217]
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x6217] (repeated 2 times)
--35991-- UNKNOWN task message [id 4816, to mach_task_self(), reply 0x6217]
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x621b]
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x621b] (repeated 2 times)
==35991== Invalid write of size 8
==35991== at 0x123400003F8B: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a038 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003F93: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a030 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003F9B: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a028 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003FA3: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a020 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003FAB: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a018 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003FB3: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a010 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003FBB: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a008 is not stack'd, malloc'd or (recently) free'd
==35991==
==35991== Invalid write of size 8
==35991== at 0x123400003FC3: IntelStateHeaps::allocateHeap(IntelStateHeaps::HeapInfo&, unsigned int, unsigned int) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003EA3: IntelStateHeaps::initHeaps(GLDShareGroupRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400003919: GenContext::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x123400002FF9: Gen7Context::Initialize(GLDContextRec*) (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x1234000029E7: glrInitializeContext (in /System/Library/Extensions/AppleIntelHD5000GraphicsGLDriver.bundle/Contents/MacOS/AppleIntelHD5000GraphicsGLDriver)
==35991== by 0x10EF7FE96: gldCreateContext (in /System/Library/PrivateFrameworks/GPUSupport.framework/Versions/A/Libraries/libGPUSupportMercury.dylib)
==35991== by 0x11113581E: gliCreateContextWithShared (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x100533B32: CGLCreateContext (in /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL)
==35991== by 0x1014C1E1B: -[NSOpenGLContext initWithFormat:shareContext:] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==35991== by 0x100046928: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100046F77: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007EA23: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== Address 0x11314a000 is not stack'd, malloc'd or (recently) free'd
==35991==
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x1803] (repeated 16 times)
==35991== Conditional jump or move depends on uninitialised value(s)
==35991== at 0x1112162CF: glViewportArrayv_Core (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x11114AEAD: glViewport_Exec (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x10009A255: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10009BE95: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x1000982B2: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007F293: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100000A2A: initScreen (in ./QSDL)
==35991== by 0x100000D04: main (in ./QSDL)
==35991==
==35991== Conditional jump or move depends on uninitialised value(s)
==35991== at 0x1112162CF: glViewportArrayv_Core (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x11114AEAD: glViewport_Exec (in /System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine)
==35991== by 0x10009A255: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x10007F356: ??? (in /Library/Frameworks/SDL2.framework/Versions/A/SDL2)
==35991== by 0x100000A2A: initScreen (in ./QSDL)
==35991== by 0x100000D04: main (in ./QSDL)
==35991==
--35991-- UNKNOWN host message [id 222, to mach_host_self(), reply 0x621b] (repeated 4 times)
==35991==
==35991== HEAP SUMMARY:
==35991== in use at exit: 4,963,922 bytes in 13,493 blocks
==35991== total heap usage: 86,557 allocs, 73,064 frees, 180,996,329 bytes allocated
==35991==
==35991== LEAK SUMMARY:
==35991== definitely lost: 123,533 bytes in 363 blocks
==35991== indirectly lost: 575,572 bytes in 3,074 blocks
==35991== possibly lost: 1,619,730 bytes in 2,120 blocks
==35991== still reachable: 2,645,087 bytes in 7,936 blocks
==35991== suppressed: 0 bytes in 0 blocks
==35991== Rerun with --leak-check=full to see details of leaked memory
==35991==
==35991== For counts of detected and suppressed errors, rerun with: -v
==35991== Use --track-origins=yes to see where uninitialised values come from
==35991== ERROR SUMMARY: 29 errors from 13 contexts (suppressed: 131 from 23)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <SDL2/SDL.h>
//Globals
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
int initScreen(unsigned int w, unsigned int h, const char * title) {
if (w < 1 || h < 1) {
printf("ERROR: width / height are invalid\n");
return -1;
}
//SDL_INIT_EVERYTHING flag to init all SDL components
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
printf("ERROR: Unable to init SDL: %s\n", SDL_GetError());
SDL_Quit();
return -1;
}
//Init window
window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_SHOWN);
if (window == NULL) {
printf("ERROR: Unable to create window: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
return -1;
}
//Init renderer to take advantage of GPU
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
printf("ERROR: Unable to create renderer: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_Quit();
return -1;
}
return 0;
}
SDL_Texture* loadTexture(const char * fpath) {
SDL_Texture* texture = NULL;
SDL_Surface* surface = NULL;
if (strlen(fpath) == 0) {
printf("ERROR: No path given\n");
}
else {
surface = SDL_LoadBMP(fpath);
if (surface == NULL) {
printf("ERROR: %s\n", SDL_GetError());
}
else {
texture = SDL_CreateTextureFromSurface(renderer, surface);
if (texture == NULL) {
printf("ERROR: %s\n", SDL_GetError());
SDL_DestroyTexture(texture);
}
SDL_FreeSurface(surface);
}
}
return texture;
}
void drawTexture(SDL_Texture * texture) {
if (texture == NULL) {
printf("ERROR: Can't draw an undefined texture\n");
}
SDL_RenderCopy(renderer, texture, NULL, NULL);
}
void clear() {
SDL_RenderClear(renderer);
}
void update() {
SDL_RenderPresent(renderer);
}
//Texture processing helper
void genXOR(unsigned int w, unsigned int h) {
for(unsigned int x = 0; x < w; x++) {
for(unsigned int y = 0; y < h; y++) {
Uint8 c = x ^ y;
SDL_SetRenderDrawColor(renderer, c, c, c, 255);
SDL_Rect rect = {x, y, w, h};
SDL_RenderFillRect(renderer, &rect);
}
}
}
int main() {
initScreen(640, 480, "Main");
// clear();
// genXOR(640, 480);
// update();
SDL_Delay(3000);
renderer = NULL;
window = NULL;
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
SDL_Quit();
return EXIT_SUCCESS;
}
My question is : Have you ever experienced something like that ? and what can i do now about these leaks since all my "own" code is about automatic allocation on the stack.