I am using SDL2 version 2.0.14. This is the current stable version.
I noticed that any program I write with SDL2 has memory leaks. For example
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("title",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_OPENGL);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
This is the main.c
file. I build it with gcc main.c -o main.exe -lSDL2 -lSDL2main
If I run drmemory main.exe
this is what I get -
ERRORS FOUND:
1 unique, 2 total unaddressable access(es)
6 unique, 6 total uninitialized access(es)
0 unique, 0 total invalid heap argument(s)
0 unique, 0 total GDI usage error(s)
0 unique, 0 total handle leak(s)
0 unique, 0 total warning(s)
1 unique, 1 total, 88 byte(s) of leak(s)
1 unique, 1 total, 26 byte(s) of possible leak(s)
I don't see why this program has leaks at all. I tried to find out what is wrong and came across this question
Although this is already answered, I don't see how this solves my issue. I want to know why am I having these leaks and how to fix them. Also do I need to worry about those unaddressable
and uninitialized
accesses diagnosed by Dr. Memory.
I suspect it has to do something with the SDL2.dll
I downloaded from SDL2. I am using the win32-x64
dll.
EDIT
Here is the full 'error' details
Dr. Memory version 2.3.0 build 1 built on Feb 6 2020 06:07:09
Windows version: WinVer=63;Rel=;Build=9600;Edition=Professional
Dr. Memory results for pid 4868: "main.exe"
Application cmdline: "main.exe"
Recorded 118 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin64\suppress-default.txt
Error #1: UNADDRESSABLE ACCESS beyond top of stack: reading 0x000000000023fb70-0x000000000023fb78 8 byte(s)
# 0 .text [../../../../../src/gcc-8.1.0/libgcc/config/i386/cygwin.S:132]
# 1 _pei386_runtime_relocator
# 2 __tmainCRTStartup
# 3 .l_start
# 4 KERNEL32.dll!BaseThreadInitThunk +0x21 (0x00007ff902e81412 <KERNEL32.dll+0x1412>)
Note: @0:00:00.281 in thread 3800
Note: 0x000000000023fb70 refers to 600 byte(s) beyond the top of the stack 0x000000000023fdc8
Note: instruction: or $0x0000000000000000 (%rcx) -> (%rcx)
Error #2: UNINITIALIZED READ: reading 0x000000000023eeec-0x000000000023eef0 4 byte(s) within 0x000000000023eee8-0x000000000023eef0
# 0 system call NtGdiOpenDCW parameter value #5
# 1 GDI32.dll!GetNearestColor +0x21f (0x00007ff903152650 <GDI32.dll+0x12650>)
# 2 GDI32.dll!GetNearestColor +0x30c (0x00007ff90315273d <GDI32.dll+0x1273d>)
# 3 GDI32.dll!CreateDCW +0x12 (0x00007ff903152783 <GDI32.dll+0x12783>)
# 4 SDL2.dll!? +0x0 (0x0000000073eae403 <SDL2.dll+0x10e403>)
# 5 SDL2.dll!? +0x0 (0x0000000073eae781 <SDL2.dll+0x10e781>)
# 6 USER32.dll!mouse_event +0x1f9 (0x00007ff90532df1a <USER32.dll+0xdf1a>)
# 7 SDL2.dll!? +0x0 (0x0000000073eae91a <SDL2.dll+0x10e91a>)
# 8 SDL2.dll!? +0x0 (0x0000000073eb1d9d <SDL2.dll+0x111d9d>)
# 9 SDL2.dll!? +0x0 (0x0000000073e760ce <SDL2.dll+0xd60ce>)
#10 SDL2.dll!? +0x0 (0x0000000073da1547 <SDL2.dll+0x1547>)
#11 main
Note: @0:00:02.451 in thread 3800
Error #3: UNINITIALIZED READ: reading 0x000000000023f734-0x000000000023f738 4 byte(s) within 0x000000000023f730-0x000000000023f738
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eaffe9 <SDL2.dll+0x10ffe9>)
# 5 SDL2.dll!? +0x0 (0x0000000073eb08fc <SDL2.dll+0x1108fc>)
# 6 SDL2.dll!? +0x0 (0x0000000073e740b7 <SDL2.dll+0xd40b7>)
# 7 SDL2.dll!? +0x0 (0x0000000073e755df <SDL2.dll+0xd55df>)
# 8 main
Note: @0:00:02.839 in thread 3800
Error #4: UNINITIALIZED READ: reading 0x000000000023f7d4-0x000000000023f7d8 4 byte(s) within 0x000000000023f7d0-0x000000000023f7d8
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eb2b9c <SDL2.dll+0x112b9c>)
# 5 SDL2.dll!? +0x0 (0x0000000073e7584d <SDL2.dll+0xd584d>)
# 6 main
Note: @0:00:03.636 in thread 3800
Error #5: UNINITIALIZED READ: reading 0x000000000023f494-0x000000000023f498 4 byte(s) within 0x000000000023f490-0x000000000023f498
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eaf7fa <SDL2.dll+0x10f7fa>)
# 5 SDL2.dll!? +0x0 (0x0000000073eafaed <SDL2.dll+0x10faed>)
# 6 SDL2.dll!? +0x0 (0x0000000073eb099d <SDL2.dll+0x11099d>)
# 7 SDL2.dll!? +0x0 (0x0000000073eb2c5b <SDL2.dll+0x112c5b>)
# 8 SDL2.dll!? +0x0 (0x0000000073e7584d <SDL2.dll+0xd584d>)
# 9 main
Note: @0:00:03.890 in thread 3800
Error #6: UNINITIALIZED READ: reading 0x000000000023f494-0x000000000023f498 4 byte(s) within 0x000000000023f490-0x000000000023f498
# 0 system call NtUserCreateWindowEx parameter value #14
# 1 USER32.dll!IsCharAlphaW +0x20e (0x00007ff905329d4f <USER32.dll+0x9d4f>)
# 2 USER32.dll!IsCharAlphaW +0x436 (0x00007ff905329f77 <USER32.dll+0x9f77>)
# 3 USER32.dll!CreateWindowExW +0x7d (0x00007ff90532a03e <USER32.dll+0xa03e>)
# 4 SDL2.dll!? +0x0 (0x0000000073eaf7fa <SDL2.dll+0x10f7fa>)
# 5 SDL2.dll!? +0x0 (0x0000000073eafe55 <SDL2.dll+0x10fe55>)
# 6 SDL2.dll!? +0x0 (0x0000000073eb099d <SDL2.dll+0x11099d>)
# 7 SDL2.dll!? +0x0 (0x0000000073eb2c5b <SDL2.dll+0x112c5b>)
# 8 SDL2.dll!? +0x0 (0x0000000073e7584d <SDL2.dll+0xd584d>)
# 9 main
Note: @0:00:03.947 in thread 3800
Error #7: UNINITIALIZED READ: reading 0x000000000023f6b0-0x000000000023f6b8 8 byte(s) within 0x000000000023f6a8-0x000000000023f6b8
# 0 system call NtUserTrackMouseEvent TRACKMOUSEEVENT post-dwFlags
# 1 SDL2.dll!? +0x0 (0x0000000073eb3bf2 <SDL2.dll+0x113bf2>)
# 2 SDL2.dll!? +0x0 (0x0000000073dcc1b7 <SDL2.dll+0x2c1b7>)
# 3 SDL2.dll!? +0x0 (0x0000000073dca237 <SDL2.dll+0x2a237>)
# 4 SDL2.dll!? +0x0 (0x0000000073dca7a8 <SDL2.dll+0x2a7a8>)
# 5 SDL2.dll!? +0x0 (0x0000000073ea90d8 <SDL2.dll+0x1090d8>)
# 6 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
# 7 USER32.dll!DispatchMessageW +0xc2 (0x00007ff905322463 <USER32.dll+0x2463>)
# 8 USER32.dll!CallWindowProcW +0x9a (0x00007ff905323ccb <USER32.dll+0x3ccb>)
# 9 OPENGL32.dll!glDebugEntry +0x1146b (0x00007ff8fa3928fc <OPENGL32.dll+0x428fc>)
#10 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
#11 USER32.dll!DispatchMessageW +0xc2 (0x00007ff905322463 <USER32.dll+0x2463>)
#12 USER32.dll!MsgWaitForMultipleObjects +0x141 (0x00007ff905323902 <USER32.dll+0x3902>)
#13 USER32.dll!MsgWaitForMultipleObjects +0x20d (0x00007ff9053239ce <USER32.dll+0x39ce>)
#14 USER32.dll!GetWindowLongW +0x10f (0x00007ff905326980 <USER32.dll+0x6980>)
#15 SDL2.dll!? +0x0 (0x0000000073e73b3c <SDL2.dll+0xd3b3c>)
#16 SDL2.dll!? +0x0 (0x0000000073e75896 <SDL2.dll+0xd5896>)
#17 main
Note: @0:00:06.599 in thread 3800
Error #8: LEAK 88 direct bytes 0x0000000002679b00-0x0000000002679b58 + 0 indirect bytes
# 0 replace_RtlAllocateHeap [d:\drmemory_package\common\alloc_replace.c:3771]
# 1 IMM32.dll!CtfImmGetTMAEFlags +0x1b4 (0x00007ff905013b35 <IMM32.dll+0x3b35>)
# 2 IMM32.dll!ImmGetContext +0x105 (0x00007ff905012396 <IMM32.dll+0x2396>)
# 3 SDL2.dll!? +0x0 (0x0000000073eaae90 <SDL2.dll+0x10ae90>)
# 4 SDL2.dll!? +0x0 (0x0000000073eab89b <SDL2.dll+0x10b89b>)
# 5 SDL2.dll!? +0x0 (0x0000000073dc8961 <SDL2.dll+0x28961>)
# 6 SDL2.dll!? +0x0 (0x0000000073ea90a4 <SDL2.dll+0x1090a4>)
# 7 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
# 8 USER32.dll!DispatchMessageW +0xc2 (0x00007ff905322463 <USER32.dll+0x2463>)
# 9 USER32.dll!CallWindowProcW +0x9a (0x00007ff905323ccb <USER32.dll+0x3ccb>)
#10 OPENGL32.dll!glDebugEntry +0x1146b (0x00007ff8fa3928fc <OPENGL32.dll+0x428fc>)
#11 USER32.dll!DispatchMessageW +0x15c (0x00007ff9053224fd <USER32.dll+0x24fd>)
Error #9: POSSIBLE LEAK 26 direct bytes 0x00000000029c01c0-0x00000000029c01da + 0 indirect bytes
# 0 replace_malloc [d:\drmemory_package\common\alloc_replace.c:2577]
# 1 msvcrt.dll!malloc_crt
# 2 msvcrt.dll!_setargv
# 3 msvcrt.dll!_getmainargs
# 4 pre_cpp_init
# 5 msvcrt.dll!initterm
# 6 __tmainCRTStartup
# 7 .l_start
# 8 KERNEL32.dll!BaseThreadInitThunk +0x21 (0x00007ff902e81412 <KERNEL32.dll+0x1412>)
===========================================================================
FINAL SUMMARY:
DUPLICATE ERROR COUNTS:
Error # 1: 2
SUPPRESSIONS USED:
ERRORS FOUND:
1 unique, 2 total unaddressable access(es)
6 unique, 6 total uninitialized access(es)
0 unique, 0 total invalid heap argument(s)
0 unique, 0 total GDI usage error(s)
0 unique, 0 total handle leak(s)
0 unique, 0 total warning(s)
1 unique, 1 total, 88 byte(s) of leak(s)
1 unique, 1 total, 26 byte(s) of possible leak(s)
ERRORS IGNORED:
91 potential error(s) (suspected false positives)
(details: C:\Users\Kabir\AppData\Roaming\Dr. Memory\DrMemory-main.exe.4868.000\potential_errors.txt)
10 potential leak(s) (suspected false positives)
(details: C:\Users\Kabir\AppData\Roaming\Dr. Memory\DrMemory-main.exe.4868.000\potential_errors.txt)
112 unique, 248 total, 34288 byte(s) of still-reachable allocation(s)
(re-run with "-show_reachable" for details)
Details: C:\Users\Kabir\AppData\Roaming\Dr. Memory\DrMemory-main.exe.4868.000\results.txt