gpt4 book ai didi

c - 如何在使用 SDL2 的程序中查找 valgrind 检测到的内存错误的原因

转载 作者:行者123 更新时间:2023-12-02 01:28:17 28 4
gpt4 key购买 nike

我正在使用 SDL2,当我使用 valgrind 运行它时,我得到了这个内存错误:

==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)

为了隔离造成伤害的原因,我将其减少到最低限度:

#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();
}

里面没有我的代码。所以我可能错误地使用了 sdl api,但看着片段我无法弄清楚是什么。还有一个 so question 有类似的问题 Uncaught exception at SDL_Quit ,但是没有答案而且测试的代码也很不一样。

这是完整的泄漏检查输出:

==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)

最佳答案

@John Bollinger 给了你正确的答案。

这已在 this 中修复提交。

您需要从源代码构建 Valgrind(按照说明 here )。

或者 3.20 将在几周后发布(目标是 2022 年 10 月 22 日)。

我无法对泄密事件发表评论。任何库的调试版本都会给你“???”在调用堆栈中会有帮助。

关于c - 如何在使用 SDL2 的程序中查找 valgrind 检测到的内存错误的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73900136/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com