Valgind on SDL

Hi there

Currently i am fixing our GameCode with valgrind, and am trying very
hard, to eliminate all possible errors. During this exercise, i found
out, that some errors do not come from my implementations, but from
SDL (or the faulty implementation on my part initializing it).

The base of my code comes from Cone3D, which can be found under:
http://cone3d.gamedev.net/cgi-bin/download.pl?file=/cone3d/ogladv/tut1/cone3d.tar.gz&blah=1
from the setup tutorial on http://cone3d.gamedev.net

i compiled it with
g++ *.cpp -lGL -lGLU sdl-config --cflags --libs

and running valgrind over it with:
valgrind ./a.out
gets the attached output.

If someone could tell me, how to initialize and delete SDL for real,
it would be greate.

thanks in advance
Benjamin

==27518== Memcheck, a memory error detector for x86-linux.
==27518== Copyright © 2002-2005, and GNU GPL’d, by Julian Seward et al.
==27518== Using valgrind-2.4.0, a program supervision framework for
x86-linux.
==27518== Copyright © 2000-2005, and GNU GPL’d, by Julian Seward et al.
==27518== For more details, rerun with: -v
==27518==
==27518== Syscall param write(buf) points to uninitialised byte(s)
==27518== at 0x1BC31448: write (in /lib/libc-2.3.5.so)
==27518== Address 0x1BEE25A6 is 14 bytes inside a block of size 16384
alloc’d
==27518== at 0x1B904D5D: calloc (in
/usr/lib/valgrind/vgpreload_memcheck.so)
==27518== by 0x1BCD7315: XOpenDisplay (in /usr/lib/libX11.so.6.2)
==27518== Warning: set address range perms: large range 134217728, a
0, v 0
==27518== Warning: set address range perms: large range 134217728, a
0, v 0
==27518==
==27518== Syscall param ioctl(generic) points to uninitialised byte(s)
==27518== at 0x1BC37204: ioctl (in /lib/libc-2.3.5.so)
==27518== by 0x1C48B2C9: s9109 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C3A4097: s11533 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C202D0C: s9848 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47A8FB: s9042 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48E520: s2820 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48DA35: s2805 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1B99FD64: CreateContext (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1B99F2F4: glXCreateContext (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1BA7DF39: X11_GL_CreateContext (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA81F0C: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA82645: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== Address 0x52BFDE04 is on thread 1’s stack
==27518==
==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1C48B2CC: s9109 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C3A4097: s11533 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C202D0C: s9848 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47A8FB: s9042 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48E520: s2820 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48DA35: s2805 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1B99FD64: CreateContext (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1B99F2F4: glXCreateContext (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1BA7DF39: X11_GL_CreateContext (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA81F0C: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA82645: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA77528: SDL_SetVideoMode (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518==
==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1C26D8B2: s5478 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C2708F9: s13521 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C270307: s12657 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C18F599: s62 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C18F2DE: s13737 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C271A36: s13161 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47E01A: s2750 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47E4E9: s2751 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48EE62: s2824 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1B99C80A: glXSwapBuffers (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1BA7E26F: X11_GL_SwapBuffers (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA78C64: SDL_GL_SwapBuffers (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518==
==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1C26D98E: s5478 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C2708F9: s13521 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C270307: s12657 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C18F599: s62 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C18F2DE: s13737 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C271A36: s13161 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47E01A: s2750 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47E4E9: s2751 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48EE62: s2824 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1B99C80A: glXSwapBuffers (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1BA7E26F: X11_GL_SwapBuffers (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA78C64: SDL_GL_SwapBuffers (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518==
==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1BA7D2A3: X11_SetKeyboardState (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA7C62C: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA7C8D1: X11_PumpEvents (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA8EE64: SDL_PumpEvents (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA8EEA7: SDL_PollEvent (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x804A1CA: main (in /home/bensch/tmp/Cone3D/a.out)
==27518==
==27518== Syscall param ioctl(generic) points to uninitialised byte(s)
==27518== at 0x1BC37204: ioctl (in /lib/libc-2.3.5.so)
==27518== by 0x1C48C604: s12231 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C2E0853: s12060 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C275269: s7033 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C204598: s347 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47A983: s7381 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48E714: s2821 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48F526: s2833 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1B9A000E: DestroyContext (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1BA7E01F: X11_GL_Shutdown (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA816B8: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA83004: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== Address 0x52BFE034 is on thread 1’s stack
==27518==
==27518== Syscall param ioctl(generic) points to uninitialised byte(s)
==27518== at 0x1BC37204: ioctl (in /lib/libc-2.3.5.so)
==27518== by 0x1C481F2D: s12207 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C4824EF: s9802 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C4946E3: s5756 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48B80D: s8887 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C20A7AA: s418 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C20A10D: s12012 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C41E90C: s7346 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C3EF5D3: s10098 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C411C9F: s11488 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C3A87AE: s7226 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C20451F: s347 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== Address 0x52BFDEE4 is on thread 1’s stack
==27518==
==27518== Syscall param ioctl(generic) points to uninitialised byte(s)
==27518== at 0x1BC37204: ioctl (in /lib/libc-2.3.5.so)
==27518== by 0x1C47A10B: s3296 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C47AA3C: s11892 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48E074: s2819 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1C48DCA5: s2804 (in /usr/lib/modules/dri/fglrx_dri.so)
==27518== by 0x1B9A1DBF: __glXFreeDisplayPrivate (in
/usr/lib/opengl/ati/lib/libGL.so.1.2)
==27518== by 0x1BCCD375: _XFreeExtData (in /usr/lib/libX11.so.6.2)
==27518== Address 0x52BFE064 is on thread 1’s stack
==27518== Warning: set address range perms: large range 134217728, a
1, v 1
==27518== Warning: set address range perms: large range 134217728, a
1, v 1
==27518==
==27518== ERROR SUMMARY: 102 errors from 9 contexts (suppressed: 69
from 1)
==27518== malloc/free: in use at exit: 2257868 bytes in 1008 blocks.
==27518== malloc/free: 4214 allocs, 3206 frees, 8309403 bytes allocated.
==27518== For counts of detected errors, rerun with: -v
==27518== searching for pointers to 1008 not-freed blocks.
==27518== checked 3381112 bytes.
==27518==
==27518== LEAK SUMMARY:
==27518== definitely lost: 34664 bytes in 31 blocks.
==27518== possibly lost: 2788 bytes in 2 blocks.
==27518== still reachable: 2220416 bytes in 975 blocks.
==27518== suppressed: 0 bytes in 0 blocks.
==27518== Use --leak-check=full to see details of leaked memory.–
visit the worlds most furious open-source 3D-action game
http://www.orxonox.net

Currently i am fixing our GameCode with valgrind, and am trying very
hard, to eliminate all possible errors. During this exercise, i found
out, that some errors do not come from my implementations, but from
SDL (or the faulty implementation on my part initializing it).

Those are in the ATI drivers, not SDL.

–ryan.

Ryan C. Gordon wrote:

Currently i am fixing our GameCode with valgrind, and am trying very
hard, to eliminate all possible errors. During this exercise, i found
out, that some errors do not come from my implementations, but from
SDL (or the faulty implementation on my part initializing it).

Those are in the ATI drivers, not SDL.

Except this one :

==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1BA7D2A3: X11_SetKeyboardState (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA7C62C: (within /usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA7C8D1: X11_PumpEvents (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA8EE64: SDL_PumpEvents (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x1BA8EEA7: SDL_PollEvent (in
/usr/lib/libSDL-1.2.so.0.7.1)
==27518== by 0x804A1CA: main (in /home/bensch/tmp/Cone3D/a.out)
==27518==

Stephane

Except this one :

==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1BA7D2A3: X11_SetKeyboardState (in
/usr/lib/libSDL-1.2.so.0.7.1)

I can’t reproduce this here…does that library name mean this happens
in some variation of SDL 1.2.7?

–ryan.

Ryan C. Gordon wrote:

Except this one :

==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1BA7D2A3: X11_SetKeyboardState (in
/usr/lib/libSDL-1.2.so.0.7.1)

I can’t reproduce this here…does that library name mean this happens
in some variation of SDL 1.2.7?

Yes. But I don’t remember seeing any change that could fix such an issue…

Stephane

P? Tue, 11 Oct 2005 19:22:51 +0200, skrev Ryan C. Gordon
:

Except this one :

==27518== Conditional jump or move depends on uninitialised value(s)
==27518== at 0x1BA7D2A3: X11_SetKeyboardState (in
/usr/lib/libSDL-1.2.so.0.7.1)

I can’t reproduce this here…does that library name mean this happens
in some variation of SDL 1.2.7?

I found the same thing some time ago (using SDL 1.2.7). I didn’t report
it then because I wanted to investigate further, but as using valgrind is
pretty painful at my ancient machine (soooo slow) I never got around to
it, and eventually I forgot about it =P. I do remember this happening in
X11_SetKeyboardState, though, and I also got the leak in
SDL_SYS_CreateThread that was just reported by someone in another mail.

  • Gerry

I found the same thing some time ago (using SDL 1.2.7). I didn’t report
it then because I wanted to investigate further, but as using valgrind is
pretty painful at my ancient machine (soooo slow) I never got around to
it, and eventually I forgot about it =P. I do remember this happening in
X11_SetKeyboardState, though, and I also got the leak in
SDL_SYS_CreateThread that was just reported by someone in another mail.

If someone can reproduce the X11_SetKeyboardState issue on SDL CVS,
built with debug symbols, please post the Valgrind output here. I can’t
trigger it, and I don’t know what line is upsetting Valgrind.

I’ll look at the CreateThread issue.

–ryan.

  • On 2005-10-11 Ryan C. Gordon wrote :

I’ll look at the CreateThread issue.

This seems to be a glibc issue, as Ryan suggested; I just ran a
pthread-only test, and valgrind gives similar results:

==7089== 68 bytes in 1 blocks are possibly lost in loss record 1 of 1
==7089== at 0x1B904F75: calloc (vg_replace_malloc.c:175)
==7089== by 0x1B8F16A7: (within /lib/ld-2.3.5.so)
==7089== by 0x1B8F197B: _dl_allocate_tls (in /lib/ld-2.3.5.so)
==7089== by 0x411804F0: pthread_create@@GLIBC_2.1 (in /lib/tls/libpthread-2.3.5.so)
==7089== by 0x804849F: main (test.c:34)–
:wq
^X^Cy^K^X^C^C^C^C

Ryan C. Gordon wrote:

If someone can reproduce the X11_SetKeyboardState issue on SDL CVS,
built with debug symbols, please post the Valgrind output here. I
can’t trigger it, and I don’t know what line is upsetting Valgrind.

I’ll look at the CreateThread issue.

–ryan.

==7557== Conditional jump or move depends on uninitialised value(s)
==7557== at 0x1BA7FE6B: X11_SetKeyboardState (SDL_x11events.c:882)
==7557== by 0x1BA7F151: X11_DispatchEvent (SDL_x11events.c:243)
==7557== by 0x1BA7F3ED: X11_PumpEvents (SDL_x11events.c:469)
==7557== by 0x1BA91F42: SDL_PumpEvents (SDL_events.c:363)
==7557== by 0x1BA91F88: SDL_PollEvent (SDL_events.c:382)
==7557== by 0x804A1CA: main (in /home/bensch/tmp/Cone3D/a.out)

Hope it helps.

Benjamin–
visit the worlds most furious open-source 3D-action game
http://www.orxonox.net

Hope it helps.

It does, thank you!

The latest in SDL’s CVS should no longer trigger that Valgrind
warning…but someone might want to point out to the x.org folks that
XNextEvent() may not be fully initializing the the XEvent structure in
the case of a KeymapNotify event.

–ryan.

Valgrind seems like an interesting tool. I would like to use it, but I
am not sure I understand how to, though. For example, I am getting
this:

==9185== Address 0x1B93EFD3 is 19 bytes inside a block of size 16384 alloc’d
==9185== at 0x1B909B71: calloc (vg_replace_malloc.c:175)
==9185== by 0x3E1D69: XOpenDisplay (in /usr/X11R6/lib/libX11.so.6.2)
==9185== by 0xB31904: (within /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0xB28803: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0xAFB13E: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0xAFB17B: SDL_Init (in /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0x8053FD3: sdl_init (sdl_lib.c:48)
==9185== by 0x804BCA1: init_dnought (main.c:106)
==9185== by 0x804BCFB: main (main.c:73)

My sdl_lib.c code is:

46 PUBLIC void sdl_init(void)
47 {
48 if ((SDL_Init(SDL_INIT_EVERYTHING) == -1)) {

and the message is “Address 0x1B93EFD3 is 19 bytes inside a block of
size 16384 alloc’d”.

Is this saying that something is checking a memory location inside a
memory area allocated by something else for a different purpose? It
does not look like my code is doing this. It this reporting a problem
in the supporting libraries? Why is this being flagged?

Here is another one:

==9185== Syscall param write(buf) points to uninitialised byte(s)
==9185== at 0x30AB2B: (within /lib/libc-2.3.5.so)
==9185== by 0x40C3FB: _X11TransWrite (in /usr/X11R6/lib/libX11.so.6.2)
==9185== by 0x3F179A: (within /usr/X11R6/lib/libX11.so.6.2)
==9185== by 0x3F18B5: _XReply (in /usr/X11R6/lib/libX11.so.6.2)
==9185== by 0x3EC482: XSync (in /usr/X11R6/lib/libX11.so.6.2)
==9185== by 0xB3102F: (within /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0xB320B2: (within /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0xB2775D: SDL_SetVideoMode (in /usr/lib/libSDL-1.2.so.0.7.1)
==9185== by 0x804EE31: init_screen (screen_lib.c:44)
==9185== by 0x804A88C: get_url (get_url.c:56)
==9185== by 0x804BD0F: main (main.c:76)

Here are the applicable lines in my screen_lib.c code:

43 PUBLIC int init_screen(int sw, int sh, int options)
44 {
45 screen = SDL_SetVideoMode(sw, sh, 0, options);

I call it with this code from get_url.c:

55
56 init_screen(640, 32, SDL_ANYFORMAT);
57

I do not see anything unitialized here. Is there an error I am not
seeing, or do I just not know how to use the tool properly? Again, why
is this being flagged?

Thank you,
Chris–
E-Mail: Chris Nystrom
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris Nystrom wrote:

Valgrind seems like an interesting tool. I would like to use it,
but I am not sure I understand how to, though. For example, I am
getting this:

see:
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.errormsgs
there everything is described


visit the worlds most furious open-source 3D-action game
http://www.orxonox.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iQIVAwUBQ0zaQq3dUaw0Ln2OAQKSARAAypab7DZjZzb0gKKtUZM16PseQnuPiNYD
3FlegXY45q3Tvz0K6xoZpjINi/uJDPqUZ4YkhhsfNO3wf6mgRcH4xPTjzsh0TWQJ
OGFErn6Kr68DzWetAsqAZ6lWSC9UjjWJzZveUJNIgkMfn02kGkEewJHMnV/in8Kc
wJoqh5eDjmIwh+kGJoXQ8D5mtTzarJ4y0PrTNiuf1hZOAYxcz/ZPvUrgpRM/nSyV
f+V8KvPrF0iqrhFA6BJBiq3YHj1HTUKzJSHZfTqn/a4jcSOfwI4JtBNPNVtlZBv5
94NmZH+KebcdHW7iEiU4dLs+kZ9/09micvxupNMg/VjvP6e4jRsiCjxX8sxQYfRF
mEKwGeRIlTUw/SDR1sFZserdQx+quJLi6tZtqjybpFfEQkQ2+W9WztY/07irYd/A
DLaE3T60h4o00QGsHZBOdDZeD/S8a9poySFhFLvPBCfknod8NB1fqe9E9/xmKjEd
YSIYJRe8Penf+njxbBzq8K4Exn101QuAHzipXKHcW+j5dv0M1Op1jFdUDxuHj3JX
84ZOcRXwvEpIUdb49YZO5wR7Ki53J9a/3vq+te1ltjULqECvDif59KvPR4yyp+TT
Qwp2gejsB2LH5Y1nogeF0tXMgRkOxRiNg/5+lmzH25VnbXnnTDJY5zZHA/ohs8Nf
XbUZSBrnP4c=
=5s8j
-----END PGP SIGNATURE-----

I do not see anything unitialized here. Is there an error I am not
seeing, or do I just not know how to use the tool properly? Again, why
is this being flagged?

In this case, there’s an issue inside Xlib…eventually you have to get
used to “your bugs” vs “everyone else’s bugs”…everyone else’s bugs
just weren’t apparent to you before.

In the latter case, you can report them to the project in question,
upgrade to see if they’re fixed, or write a Valgrind suppression file,
so Valgrind ignores them and only focuses on issues in your code.

–ryan.