0

I'm currently on Kubuntu and I write a code with SDL 2.

My goal is to do ray-casting.

So no problem in my code - gdb said no problem and exit normally but valgrind said one error

==1894== Memcheck, a memory error detector
==1894== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1894== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==1894== Command: ./ray
==1894== 
==1894== Conditional jump or move depends on uninitialised value(s)
==1894==    at 0x50B8565: pa_shm_cleanup (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so)
==1894==    by 0x50B87A1: pa_shm_create_rw (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so)
==1894==    by 0x50A84B6: pa_mempool_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so)
==1894==    by 0x4E149B1: pa_context_new_with_proplist (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.21.2)
==1894==    by 0x493ED5E: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.10.0)
==1894==    by 0x493F65A: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.10.0)
==1894==    by 0x4891D9B: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.10.0)
==1894==    by 0x488D906: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.10.0)
==1894==    by 0x10941D: main (main.c:9)
==1894== 
==1894== 
==1894== HEAP SUMMARY:
==1894==     in use at exit: 349,601 bytes in 2,981 blocks
==1894==   total heap usage: 220,203 allocs, 217,222 frees, 32,111,232 bytes allocated
==1894== 
==1894== LEAK SUMMARY:
==1894==    definitely lost: 377 bytes in 3 blocks
==1894==    indirectly lost: 3,071 bytes in 24 blocks
==1894==      possibly lost: 0 bytes in 0 blocks
==1894==    still reachable: 346,153 bytes in 2,954 blocks
==1894==         suppressed: 0 bytes in 0 blocks
==1894== Rerun with --leak-check=full to see details of leaked memory
==1894== 
==1894== Use --track-origins=yes to see where uninitialised values come from
==1894== For lists of detected and suppressed errors, rerun with: -s
==1894== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)

If I understand, my code is great but there is a problem with a pulseAudio lib?

To test, I just write SDL_Init(SDL_INIT_EVERYTHING) SDL_Quit() in the main function and valgrind said the same thing. So that by SDL with a pulseAudio lib.

Can someone help me to track and remove that error?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • From the [SDL_Quit](https://wiki.libsdl.org/SDL_Quit) documentation: ``` You should call this function even if you have already shutdown each initialized subsystem with SDL_QuitSubSystem(). If you start a subsystem using a call to that subsystem's init function (for example SDL_VideoInit()) instead of SDL_Init() or SDL_InitSubSystem(), then you must use that subsystem's quit function (SDL_VideoQuit()) to shut it down before calling SDL_Quit(). ``` `SDL_INIT_EVERYTHING` is used to initialize all subsystems... Is the problem still present, if you'll use `SDL_QuitSubSystem()`? – A.N. Nov 07 '21 at 21:58
  • thanks for your comment @A.N.. When I do `SDL_Init(SDL_INIT_EVERYTHING)` and after `SDL_QuitSubSystem(SDL_INIT_EVERYTHING)` and 'SDL_Quit()'/ the problem still present. But If I only init video, the problem goes out. The problem is related with SDL_INIT_AUDIO – van3ll0pe Nov 08 '21 at 06:35
  • Interesting, but: `valgrind $(which vlc) >log 2>&1`: ``` ==672556== LEAK SUMMARY: ==672556== definitely lost: 1,848 bytes in 21 blocks ==672556== indirectly lost: 29,358 bytes in 375 blocks ==672556== possibly lost: 800 bytes in 3 blocks ==672556== still reachable: 1,089,606 bytes in 15,360 blocks ==672556== suppressed: 192 bytes in 3 blocks ==672556== Rerun with --leak-check=full to see details of leaked memory ``` – A.N. Nov 08 '21 at 16:41
  • Please, run Valgrind with a `--leak-check=full` flag. – A.N. Nov 08 '21 at 16:42
  • Wait, first message is not about memory leakage, it's about possibly undefined behaviour: `Conditional jump or move depends on uninitialised value(s)`. – A.N. Nov 08 '21 at 16:46
  • same problem on my debian laptop. On the debian laptop I just write a main with only `SDL_Init(SDL_INIT_EVERYTHING)` and `SDL_Quit()` and 1 error and 2 suppressed. here the value of valgrind --leak-check=full Do you have any leak problem with sdl ? – van3ll0pe Nov 08 '21 at 20:03
  • Me? I don't use it now. But, as you can see, even VLC has leaks, despite it doesn't use SDL: a leak in the PulseAudio is possible. – A.N. Nov 09 '21 at 22:54

1 Answers1

0

The problem is likely in the SDL2 or PulseAudio lib. Though having exact test code with the compilation command would ensure that you are not doing something wrong, it is unlikely a bug from you and I would ignore it.

Valgrind can and have error suppression lists to remove these annoyances. How do you tell Valgrind to completely suppress a particular .so file? might help you.

Also avoid using SDL_INIT_EVERYTHING, you likely only need SDL_INIT_VIDEO or SDL_INIT_VIDEO|SDL_INIT_TIMER depending on what you do, checkout the SDL_Init() documentation.

Devilish Spirits
  • 439
  • 4
  • 18
  • Here my makefile ```INC= -I ./include LIB= -lSDL2main -lSDL2 -lSDL2_mixer -lSDL2_ttf -lSDL2_image BIN= -o ray SRC= src/main.c \ src/screen.c \ src/map.c compile: gcc -Wall -Wextra $(SRC) $(INC) $(LIB) $(BIN) -g run: ./ray``` The problem is related to `SDL_INIT_AUDIO` so when I only used `SDL_INIT_VIDEO` everything works and I have 0 error but how I do if I need to use AUDIO in SDL2 ? – van3ll0pe Nov 08 '21 at 06:36