SDL or X11 do nasty things with memory (cf Valgrind)

Hello,

I’ve launched valgrind on glob2 (our game), and it detects some nasty things
with memory. I’m quite sure it’s on SDL’s or X11’s side. I’ve searched the
ml, but it seems I have differents errors then the one already reported.

The one with SDL_DisplayFormatAlpha is in this context :
Sprite::Surface::Surface(SDL_Surface *source)
{
assert(source);
s = SDL_DisplayFormatAlpha(source);
assert(s);
SDL_FreeSurface(source);

[...]

}

Note that source is just loaded using libSDL_image.

I’m using the libsdl1.2 (1.2.5-3) and libsdl1.2-dev (1.2.5-3) package on
debian woody. xlibs’s version is 4.2.1-6.

I hope it can helps to improve SDL. Anyway, the game works…

Stephane===

Valgrind’s output :

==1412== Syscall param modify_ldt(ptr)(func=1 or 0x11) contains uninitialised
or unaddressable byte(s)
==1412== at 0x403B68D8: (within /usr/lib/libGL.so.1.0.4496)
==1412== Address 0xBFFFFA20 is on thread 1’s stack
Toolkit : Initialized : Graphic Context created
==1412==
==1412== Syscall param writev(vector[…]) contains uninitialised or
unaddressable byte(s)
==1412== at 0x40170076: vgAllRoadsLeadToRome_writev (vg_intercept.c:108)
==1412== by 0x401700B2: __writev (vg_intercept.c:733)
==1412== by 0x40661C47: (within /usr/X11R6/lib/libX11.so.6.2)
==1412== by 0x406626C4: _X11TransWritev (in /usr/X11R6/lib/libX11.so.6.2)
==1412== by 0x40647549: _XSend (in /usr/X11R6/lib/libX11.so.6.2)
==1412== by 0x4064307E: XStoreColors (in /usr/X11R6/lib/libX11.so.6.2)
==1412== by 0x402BB455: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402BA970: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== Address 0x4233CB27 is 19 bytes inside a block of size 2048 alloc’d
==1412== at 0x4015D87A: calloc (vg_clientfuncs.c:245)
==1412== by 0x406397A5: XOpenDisplay (in /usr/X11R6/lib/libX11.so.6.2)
==1412== by 0x402B9BA0: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B03C6: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x4028F132: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x4028F171: SDL_Init (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x810D994: SDLGraphicContext::SDLGraphicContext()
(SDLGraphicContext.cpp:910)
==1412== by 0x8109D6A:
GraphicContext::createGraphicContext(DrawableSurface::GraphicContextType)
(GraphicContext.cpp:39)
Toolkit : Screen set to 640x480 at 32 bpp in window
==1412==
==1412== Invalid read of size 4
==1412== at 0x4029AA2F: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x40298C71: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF2DC: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412== by 0x810A241: GraphicContext::loadSprite(char const*, char const*)
(GraphicContext.cpp:99)
==1412== Address 0x4230BA04 is 4 bytes after a block of size 1004 alloc’d
==1412== at 0x4015D414: malloc (vg_clientfuncs.c:103)
==1412== by 0x402AE6E1: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AEA9F: SDL_MapSurface (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF299: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412==
==1412== Invalid read of size 4
==1412== at 0x4029A9D7: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x40298C71: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF2DC: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412== by 0x810A241: GraphicContext::loadSprite(char const*, char const*)
(GraphicContext.cpp:99)
==1412== Address 0x4230BA04 is 4 bytes after a block of size 1004 alloc’d
==1412== at 0x4015D414: malloc (vg_clientfuncs.c:103)
==1412== by 0x402AE6E1: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AEA9F: SDL_MapSurface (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF299: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412==
==1412== Invalid read of size 4
==1412== at 0x4029A9ED: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x40298C71: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF2DC: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412== by 0x810A241: GraphicContext::loadSprite(char const*, char const*)
(GraphicContext.cpp:99)
==1412== Address 0x4230BA04 is 4 bytes after a block of size 1004 alloc’d
==1412== at 0x4015D414: malloc (vg_clientfuncs.c:103)
==1412== by 0x402AE6E1: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AEA9F: SDL_MapSurface (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF299: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412==
==1412== Invalid read of size 4
==1412== at 0x4029AA19: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x40298C71: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF2DC: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412== by 0x810A241: GraphicContext::loadSprite(char const*, char const*)
(GraphicContext.cpp:99)
==1412== Address 0x4230BA04 is 4 bytes after a block of size 1004 alloc’d
==1412== at 0x4015D414: malloc (vg_clientfuncs.c:103)
==1412== by 0x402AE6E1: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AEA9F: SDL_MapSurface (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF299: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412==
==1412== Invalid read of size 4
==1412== at 0x4029AA03: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x40298C71: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF2DC: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)
==1412== by 0x810A241: GraphicContext::loadSprite(char const*, char const*)
(GraphicContext.cpp:99)
==1412== Address 0x4230BA04 is 4 bytes after a block of size 1004 alloc’d
==1412== at 0x4015D414: malloc (vg_clientfuncs.c:103)
==1412== by 0x402AE6E1: (within /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AEA9F: SDL_MapSurface (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AF299: SDL_LowerBlit (in /usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402AFB1D: SDL_ConvertSurface (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x402B1745: SDL_DisplayFormatAlpha (in
/usr/lib/libSDL-1.2.so.0.0.5)
==1412== by 0x811C54A: Sprite::Surface::Surface(SDL_Surface*)
(Sprite.cpp:37)
==1412== by 0x811D4AE: Sprite::loadFrame(SDL_RWops*, SDL_RWops*)
(Sprite.cpp:225)