I am using SDL2 and when I run it with valgrind I get this memory error
:
==19367== Memcheck, a memory error detector
==19367== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==19367== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==19367== Command: ./test
==19367==
==19367== Invalid read of size 8
==19367== at 0x40286C8: strncmp (strcmp.S:172)
==19367== by 0x400668D: is_dst (dl-load.c:216)
==19367== by 0x400810E: _dl_dst_count (dl-load.c:253)
==19367== by 0x400810E: expand_dynamic_string_token (dl-load.c:395)
==19367== by 0x40082B7: fillin_rpath.isra.0 (dl-load.c:483)
==19367== by 0x4008602: decompose_rpath (dl-load.c:654)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19367== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19367== by 0x4003494: openaux (dl-deps.c:64)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19367== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19367== Address 0x68c9269 is 9 bytes inside a block of size 15 alloc'd
==19367== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19367== by 0x40271FF: malloc (rtld-malloc.h:56)
==19367== by 0x40271FF: strdup (strdup.c:42)
==19367== by 0x4008594: decompose_rpath (dl-load.c:629)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19367== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19367== by 0x4003494: openaux (dl-deps.c:64)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19367== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x400E34D: _dl_open (dl-open.c:883)
==19367==
==19367== Invalid read of size 8
==19367== at 0x40286C8: strncmp (strcmp.S:172)
==19367== by 0x400668D: is_dst (dl-load.c:216)
==19367== by 0x4007F79: _dl_dst_substitute (dl-load.c:295)
==19367== by 0x40082B7: fillin_rpath.isra.0 (dl-load.c:483)
==19367== by 0x4008602: decompose_rpath (dl-load.c:654)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19367== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19367== by 0x4003494: openaux (dl-deps.c:64)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19367== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19367== Address 0x68c9269 is 9 bytes inside a block of size 15 alloc'd
==19367== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19367== by 0x40271FF: malloc (rtld-malloc.h:56)
==19367== by 0x40271FF: strdup (strdup.c:42)
==19367== by 0x4008594: decompose_rpath (dl-load.c:629)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19367== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19367== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19367== by 0x4003494: openaux (dl-deps.c:64)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19367== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19367== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19367== by 0x400E34D: _dl_open (dl-open.c:883)
==19367==
==19367==
==19367== HEAP SUMMARY:
==19367== in use at exit: 303,614 bytes in 3,333 blocks
==19367== total heap usage: 70,133 allocs, 66,800 frees, 12,517,414 bytes allocated
==19367==
==19367== LEAK SUMMARY:
==19367== definitely lost: 11,984 bytes in 270 blocks
==19367== indirectly lost: 44,148 bytes in 923 blocks
==19367== possibly lost: 0 bytes in 0 blocks
==19367== still reachable: 247,482 bytes in 2,140 blocks
==19367== suppressed: 0 bytes in 0 blocks
==19367== Rerun with --leak-check=full to see details of leaked memory
==19367==
==19367== For lists of detected and suppressed errors, rerun with: -s
==19367== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
In order to isolate what is causing harm I reduced to this minimum:
#include <stdio.h>
#include <SDL2/SDL.h>
int main(void)
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
{
printf("error initializing SDL: %s\n", SDL_GetError());
return 1;
}
SDL_Window* win = SDL_CreateWindow("Test",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480, 0);
if (!win)
{
printf("error creating window: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!rend)
{
printf("error creating renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(win);
SDL_Quit();
return 1;
}
SDL_RenderClear(rend);
SDL_DestroyRenderer(rend);
SDL_DestroyWindow(win);
SDL_Quit();
}
In which there is not code of mine. So I may be using wrongly sdl api, but looking at snippets I can't figure out what. There is another so question with a similar problem Uncaught exception at SDL_Quit, but it has no answers and the code tested is quite different.
This is the full leak-check
output:
==19704== Memcheck, a memory error detector
==19704== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==19704== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==19704== Command: ./test
==19704==
==19704== Invalid read of size 8
==19704== at 0x40286C8: strncmp (strcmp.S:172)
==19704== by 0x400668D: is_dst (dl-load.c:216)
==19704== by 0x400810E: _dl_dst_count (dl-load.c:253)
==19704== by 0x400810E: expand_dynamic_string_token (dl-load.c:395)
==19704== by 0x40082B7: fillin_rpath.isra.0 (dl-load.c:483)
==19704== by 0x4008602: decompose_rpath (dl-load.c:654)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19704== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19704== by 0x4003494: openaux (dl-deps.c:64)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19704== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19704== Address 0x68ca699 is 9 bytes inside a block of size 15 alloc'd
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x40271FF: malloc (rtld-malloc.h:56)
==19704== by 0x40271FF: strdup (strdup.c:42)
==19704== by 0x4008594: decompose_rpath (dl-load.c:629)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19704== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19704== by 0x4003494: openaux (dl-deps.c:64)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19704== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400E34D: _dl_open (dl-open.c:883)
==19704==
==19704== Invalid read of size 8
==19704== at 0x40286C8: strncmp (strcmp.S:172)
==19704== by 0x400668D: is_dst (dl-load.c:216)
==19704== by 0x4007F79: _dl_dst_substitute (dl-load.c:295)
==19704== by 0x40082B7: fillin_rpath.isra.0 (dl-load.c:483)
==19704== by 0x4008602: decompose_rpath (dl-load.c:654)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19704== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19704== by 0x4003494: openaux (dl-deps.c:64)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19704== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19704== Address 0x68ca699 is 9 bytes inside a block of size 15 alloc'd
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x40271FF: malloc (rtld-malloc.h:56)
==19704== by 0x40271FF: strdup (strdup.c:42)
==19704== by 0x4008594: decompose_rpath (dl-load.c:629)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:696)
==19704== by 0x400ABF5: cache_rpath (dl-load.c:677)
==19704== by 0x400ABF5: _dl_map_object (dl-load.c:2165)
==19704== by 0x4003494: openaux (dl-deps.c:64)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x4003C7B: _dl_map_object_deps (dl-deps.c:248)
==19704== by 0x400EA0E: dl_open_worker_begin (dl-open.c:592)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400DF99: dl_open_worker (dl-open.c:782)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400E34D: _dl_open (dl-open.c:883)
==19704==
==19704==
==19704== HEAP SUMMARY:
==19704== in use at exit: 303,614 bytes in 3,333 blocks
==19704== total heap usage: 70,139 allocs, 66,806 frees, 12,517,934 bytes allocated
==19704==
==19704== 8 bytes in 1 blocks are definitely lost in loss record 5 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x59ADA59: ???
==19704== by 0x498615B: X11_InitKeyboard (SDL_x11keyboard.c:321)
==19704== by 0x498A97D: X11_VideoInit (SDL_x11video.c:470)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 32 bytes in 1 blocks are definitely lost in loss record 375 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x59986D3: ???
==19704== by 0x5993228: ???
==19704== by 0x5993BF0: ???
==19704== by 0x5970B2C: ???
==19704== by 0x5970D85: ???
==19704== by 0x4988590: GetXftDPI (SDL_x11modes.c:541)
==19704== by 0x4988590: X11_InitModes_StdXlib.isra.0 (SDL_x11modes.c:617)
==19704== by 0x498A965: X11_VideoInit (SDL_x11video.c:456)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 32 (16 direct, 16 indirect) bytes in 1 blocks are definitely lost in loss record 376 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x59A94A7: ???
==19704== by 0x59A9562: ???
==19704== by 0x4986146: X11_InitKeyboard (SDL_x11keyboard.c:319)
==19704== by 0x498A97D: X11_VideoInit (SDL_x11video.c:470)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 40 bytes in 1 blocks are definitely lost in loss record 1,122 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x5975809: ???
==19704== by 0x4989DC4: X11_CreateDevice (SDL_x11video.c:165)
==19704== by 0x495E530: SDL_VideoInit_REAL (SDL_video.c:469)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 40 bytes in 1 blocks are definitely lost in loss record 1,123 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x5975826: ???
==19704== by 0x4989DC4: X11_CreateDevice (SDL_x11video.c:165)
==19704== by 0x495E530: SDL_VideoInit_REAL (SDL_video.c:469)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 40 bytes in 1 blocks are definitely lost in loss record 1,124 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x5975843: ???
==19704== by 0x4989DC4: X11_CreateDevice (SDL_x11video.c:165)
==19704== by 0x495E530: SDL_VideoInit_REAL (SDL_video.c:469)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 48 (16 direct, 32 indirect) bytes in 1 blocks are definitely lost in loss record 1,742 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x59A740D: ???
==19704== by 0x59A9470: ???
==19704== by 0x59A98AE: ???
==19704== by 0x5993884: ???
==19704== by 0x5993BC2: ???
==19704== by 0x5970B2C: ???
==19704== by 0x5970D85: ???
==19704== by 0x4988590: GetXftDPI (SDL_x11modes.c:541)
==19704== by 0x4988590: X11_InitModes_StdXlib.isra.0 (SDL_x11modes.c:617)
==19704== by 0x498A965: X11_VideoInit (SDL_x11video.c:456)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704==
==19704== 64 bytes in 1 blocks are definitely lost in loss record 2,046 of 2,194
==19704== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x746A7DD: ???
==19704== by 0x6D02593: ???
==19704== by 0x400647D: call_init.part.0 (dl-init.c:70)
==19704== by 0x4006567: call_init (dl-init.c:33)
==19704== by 0x4006567: _dl_init (dl-init.c:117)
==19704== by 0x4BAEC84: _dl_catch_exception (dl-error-skeleton.c:182)
==19704== by 0x400DFF5: dl_open_worker (dl-open.c:808)
==19704== by 0x400DFF5: dl_open_worker (dl-open.c:771)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x400E34D: _dl_open (dl-open.c:883)
==19704== by 0x4ACA6BB: dlopen_doit (dlopen.c:56)
==19704== by 0x4BAEC27: _dl_catch_exception (dl-error-skeleton.c:208)
==19704== by 0x4BAECF2: _dl_catch_error (dl-error-skeleton.c:227)
==19704==
==19704== 80 (40 direct, 40 indirect) bytes in 1 blocks are definitely lost in loss record 2,135 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x599F7B2: ???
==19704== by 0x59A22DF: ???
==19704== by 0x59A20D6: ???
==19704== by 0x599C0EC: ???
==19704== by 0x59C16D9: ???
==19704== by 0x59A9495: ???
==19704== by 0x59A9562: ???
==19704== by 0x4986146: X11_InitKeyboard (SDL_x11keyboard.c:319)
==19704== by 0x498A97D: X11_VideoInit (SDL_x11video.c:470)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704==
==19704== 1,203 (16 direct, 1,187 indirect) bytes in 1 blocks are definitely lost in loss record 2,171 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x599D429: ???
==19704== by 0x59A0C10: ???
==19704== by 0x59A20E2: ???
==19704== by 0x599C0EC: ???
==19704== by 0x59C16D9: ???
==19704== by 0x59A9495: ???
==19704== by 0x59A9562: ???
==19704== by 0x4986146: X11_InitKeyboard (SDL_x11keyboard.c:319)
==19704== by 0x498A97D: X11_VideoInit (SDL_x11video.c:470)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704==
==19704== 2,048 bytes in 1 blocks are definitely lost in loss record 2,177 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x599F8B2: ???
==19704== by 0x59A22DF: ???
==19704== by 0x59A20D6: ???
==19704== by 0x599C0EC: ???
==19704== by 0x59C16D9: ???
==19704== by 0x59A9495: ???
==19704== by 0x59A98AE: ???
==19704== by 0x5993884: ???
==19704== by 0x5993BC2: ???
==19704== by 0x5970B2C: ???
==19704== by 0x5970D85: ???
==19704==
==19704== 4,096 bytes in 1 blocks are definitely lost in loss record 2,183 of 2,194
==19704== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x597EE1A: ???
==19704== by 0x5992AB3: ???
==19704== by 0x5970B1B: ???
==19704== by 0x5970D85: ???
==19704== by 0x4988590: GetXftDPI (SDL_x11modes.c:541)
==19704== by 0x4988590: X11_InitModes_StdXlib.isra.0 (SDL_x11modes.c:617)
==19704== by 0x498A965: X11_VideoInit (SDL_x11video.c:456)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 5,348 bytes in 255 blocks are definitely lost in loss record 2,185 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x4AE260E: strdup (strdup.c:42)
==19704== by 0x653E741: ???
==19704== by 0x653E4E4: ???
==19704== by 0x64DE550: ???
==19704== by 0x6443E46: ???
==19704== by 0x6444C8A: ???
==19704== by 0x64C04BB: ???
==19704== by 0x4948A75: SDL_EGL_MakeCurrent (SDL_egl.c:1124)
==19704== by 0x4948A75: SDL_EGL_MakeCurrent (SDL_egl.c:1096)
==19704== by 0x4948CD5: SDL_EGL_CreateContext (SDL_egl.c:1056)
==19704== by 0x498979E: X11_GLES_CreateContext (SDL_x11opengles.c:100)
==19704== by 0x495C9B7: SDL_GL_CreateContext_REAL (SDL_video.c:4047)
==19704==
==19704== 7,616 (52 direct, 7,564 indirect) bytes in 1 blocks are definitely lost in loss record 2,186 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x599D65F: ???
==19704== by 0x599DA7F: ???
==19704== by 0x59A2196: ???
==19704== by 0x59A20D6: ???
==19704== by 0x599C0EC: ???
==19704== by 0x59C16D9: ???
==19704== by 0x59A9495: ???
==19704== by 0x59A98AE: ???
==19704== by 0x5993884: ???
==19704== by 0x5993BC2: ???
==19704== by 0x5970B2C: ???
==19704==
==19704== 16,416 (64 direct, 16,352 indirect) bytes in 1 blocks are definitely lost in loss record 2,191 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x597EFB6: ???
==19704== by 0x5992AB3: ???
==19704== by 0x5970B1B: ???
==19704== by 0x5970D85: ???
==19704== by 0x4988590: GetXftDPI (SDL_x11modes.c:541)
==19704== by 0x4988590: X11_InitModes_StdXlib.isra.0 (SDL_x11modes.c:617)
==19704== by 0x498A965: X11_VideoInit (SDL_x11video.c:456)
==19704== by 0x495E409: SDL_VideoInit_REAL (SDL_video.c:501)
==19704== by 0x487DEAE: SDL_InitSubSystem_REAL.part.0 (SDL.c:251)
==19704== by 0x10925E: main (hw.c:6)
==19704==
==19704== 19,021 (64 direct, 18,957 indirect) bytes in 1 blocks are definitely lost in loss record 2,192 of 2,194
==19704== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==19704== by 0x599D9A6: ???
==19704== by 0x59A8B6B: ???
==19704== by 0x59C0A15: ???
==19704== by 0x59A9495: ???
==19704== by 0x59A98AE: ???
==19704== by 0x5993884: ???
==19704== by 0x5993BC2: ???
==19704== by 0x5970B2C: ???
==19704== by 0x5970D85: ???
==19704== by 0x4988590: GetXftDPI (SDL_x11modes.c:541)
==19704== by 0x4988590: X11_InitModes_StdXlib.isra.0 (SDL_x11modes.c:617)
==19704== by 0x498A965: X11_VideoInit (SDL_x11video.c:456)
==19704==
==19704== LEAK SUMMARY:
==19704== definitely lost: 11,984 bytes in 270 blocks
==19704== indirectly lost: 44,148 bytes in 923 blocks
==19704== possibly lost: 0 bytes in 0 blocks
==19704== still reachable: 247,482 bytes in 2,140 blocks
==19704== suppressed: 0 bytes in 0 blocks
==19704== Reachable blocks (those to which a pointer was found) are not shown.
==19704== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==19704==
==19704== For lists of detected and suppressed errors, rerun with: -s
==19704== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0)
CodePudding user response:
Considering the source file and function names in the associated stack traces, the "invalid read" errors appear to be occurring inside the dynamic loader. Not only is that not the fault of your code, it probably isn't SDL's fault, either.
It is possible that those errors reflect known and accepted runtime behavior that the dynamic loader's authors are satisfied is unproblematic in practice. If so, then they have escaped Valgrind's list of such errors (which is a long one for glibc overall). That may arise from your Valgrind being older than your Glibc, or perhaps from Valgrind simply not having caught up to this particular issue yet. On the other hand, there's a small chance that it reflects a bona fide bug in the dynamic loader.
I would first apply all available OS updates, then perform a clean build and check again. If that did not resolve the error then I would consider upgrading to the very latest Valgrind (by building it from source), supposing that that was newer. If the latest Valgrind still reported the error then I would seek support from the Valgrind team, as they are in the best position to determine whether it is a known (to them) issue, and if so, whether it is ignorable or a genuine bug.
CodePudding user response:
@John Bollinger is giving you the correct answer.
This was fixed in this commit.
You need to either build Valgrind from source (follow the instructions here).
Alternatively 3.20 is due out in a few weeks (aiming for October 22 2022).
I can't comment on the leaks. A debug build of whatever library is giving you the '???' in the callstacks would help.