2011-12-09 14 views
3

私はアプリケーションにメモリリークがないようにしています。SDLライブラリのメモリリーク

int main(int argc, char* argv[]) { 

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) { 
    printf("Could not initialize SDL - %s\n", SDL_GetError()); 
    return -1; 
    } 

    int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_FULLSCREEN; 
    SDL_Surface* screen = SDL_SetVideoMode(0, 0, 0, flags); 

    SDL_Quit(); 
    return 0; 
} 

私は、このアプリケーションでvalgrindのを実行すると、このメッセージの最後に記載されているとして、それはメモリリークの束を報告します。私は、次の簡単なSDLアプリケーションへのリークを絞り込みます。

SDL_SetVideoModeのドキュメントによれば、SDL_SetVideoModeから返されるサーフェスはSDL_Quitによって解放され、呼び出し元によって解放されてはならないことに注意してください。

http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode

誰かが、それは私が行方不明だということであるものを私に伝えることができる場合、私はそれをお願い申し上げます。

ご協力いただきありがとうございます。

==651== Memcheck, a memory error detector 
    ==651== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. 
    ==651== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info 
    ==651== Command: ./main 
    ==651== 
    ==651== Syscall param writev(vector[...]) points to uninitialised byte(s) 
    ==651== at 0x4F3FE05: writev (writev.c:56) 
    ==651== by 0x40004: ??? 
    ==651== Address 0x5701bfb is 19 bytes inside a block of size 16,384 alloc'd 
    ==651== at 0x402732C: calloc (vg_replace_malloc.c:467) 
    ==651== by 0x5B06551: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x4DF52DB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E00403: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DED4A8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1C79: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E8F112: (below main) (libc-start.c:226) 
    ==651== 
    ==651== 
    ==651== HEAP SUMMARY: 
    ==651==  in use at exit: 48,065 bytes in 917 blocks 
    ==651== total heap usage: 13,115 allocs, 12,198 frees, 1,985,815 bytes allocated 
    ==651== 
    ==651== 10 bytes in 2 blocks are definitely lost in loss record 9 of 167 
    ==651== at 0x4028876: malloc (vg_replace_malloc.c:236) 
    ==651== by 0x4EEC010: strdup (strdup.c:43) 
    ==651== by 0xBED27FFF: ??? 
    ==651== 
    ==651== 12 bytes in 1 blocks are definitely lost in loss record 14 of 167 
    ==651== at 0x4028876: malloc (vg_replace_malloc.c:236) 
    ==651== by 0x5C2206A: ??? 
    ==651== by 0x5C21AE4: ??? 
    ==651== by 0x5C21E8A: ??? 
    ==651== by 0x5C22365: ??? 
    ==651== by 0x5C1C8AD: ??? 
    ==651== by 0x5C1CBAB: ??? 
    ==651== by 0x4DF62CB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E006CF: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DED4A8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1C79: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E8F112: (below main) (libc-start.c:226) 
    ==651== 
    ==651== 112 (8 direct, 104 indirect) bytes in 1 blocks are definitely lost in loss record 135 of 167 
    ==651== at 0x402896C: realloc (vg_replace_malloc.c:525) 
    ==651== by 0x5B2A7B6: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B2ACB2: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B2C75F: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B2CFEA: _XlcCreateLC (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B4BFD9: _XlcDefaultLoader (in /usr/lib/i386-linux-  gnu/libX11.so.6.3.0) 
    ==651== by 0x5B34E3B: _XOpenLC (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B34FA1: _XlcCurrentLC (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x4E005DB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DED4A8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1C79: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E8F112: (below main) (libc-start.c:226) 
    ==651== 
    ==651== 112 (8 direct, 104 indirect) bytes in 1 blocks are definitely lost in loss record 136 of 167 
    ==651== at 0x402896C: realloc (vg_replace_malloc.c:525) 
    ==651== by 0x5B2A7B6: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B2ACB2: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B2C75F: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B2CFEA: _XlcCreateLC (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B4BFD9: _XlcDefaultLoader (in /usr/lib/i386-linux-  gnu/libX11.so.6.3.0) 
    ==651== by 0x5B34E3B: _XOpenLC (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B350BA: _XrmInitParseInfo (in /usr/lib/i386-linux-  gnu/libX11.so.6.3.0) 
    ==651== by 0x5B1B6AD: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B1F294: XrmGetStringDatabase (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5AFA4DA: ??? (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5AFA6F6: XGetDefault (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== 
    ==651== 124 bytes in 1 blocks are definitely lost in loss record 137 of 167 
    ==651== at 0x4028876: malloc (vg_replace_malloc.c:236) 
    ==651== by 0x55B0747: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B0802: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B029F: xcb_connect_to_display_with_auth_info (in /usr/lib/i386- linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B045A: xcb_connect (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x5B16407: _XConnectXCB (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B0619F: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x4DF52DB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E003DF: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DED4A8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1C79: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E8F112: (below main) (libc-start.c:226) 
    ==651== 
    ==651== 124 bytes in 1 blocks are definitely lost in loss record 138 of 167 
    ==651== at 0x4028876: malloc (vg_replace_malloc.c:236) 
    ==651== by 0x55B0747: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B0802: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B029F: xcb_connect_to_display_with_auth_info (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B045A: xcb_connect (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x5B16407: _XConnectXCB (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B0619F: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x4DF52DB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DFDD7B: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DED574: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1C79: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E8F112: (below main) (libc-start.c:226) 
    ==651== 
    ==651== 124 bytes in 1 blocks are definitely lost in loss record 139 of 167 
    ==651== at 0x4028876: malloc (vg_replace_malloc.c:236) 
    ==651== by 0x55B0747: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B0802: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B029F: xcb_connect_to_display_with_auth_info (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B045A: xcb_connect (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x5B16407: _XConnectXCB (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x5B0619F: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0) 
    ==651== by 0x4DF52DB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E00403: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DED4A8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1C79: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4E8F112: (below main) (libc-start.c:226) 
    ==651== 
    ==651== 124 bytes in 1 blocks are definitely lost in loss record 140 of 167 
    ==651== at 0x4028876: malloc (vg_replace_malloc.c:236) 
    ==651== by 0x55B0747: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B0802: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B029F: xcb_connect_to_display_with_auth_info (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x55B045A: xcb_connect (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0) 
    ==651== by 0x5534050: pa_client_conf_from_x11 (in /usr/lib/i386-linux-gnu/libpulsecommon-1.0.so) 
    ==651== by 0x54172E4: pa_context_new_with_proplist (in /usr/lib/i386-linux-gnu/libpulse.so.0.13.4) 
    ==651== by 0x54173EA: pa_context_new (in /usr/lib/i386-linux-gnu/libpulse.so.0.13.4) 
    ==651== by 0x54085C5: pa_simple_new (in /usr/lib/i386-linux-gnu/libpulse-simple.so.0.0.3) 
    ==651== by 0x4DF4263: ??? (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC2B16: SDL_AudioInit (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== by 0x4DC1BD6: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3) 
    ==651== 
    ==651== LEAK SUMMARY: 
    ==651== definitely lost: 534 bytes in 9 blocks 
    ==651== indirectly lost: 208 bytes in 8 blocks 
    ==651==  possibly lost: 0 bytes in 0 blocks 
    ==651== still reachable: 47,323 bytes in 900 blocks 
    ==651==   suppressed: 0 bytes in 0 blocks 
    ==651== Reachable blocks (those to which a pointer was found) are not shown. 
    ==651== To see them, rerun with: --leak-check=full --show-reachable=yes 
    ==651== 
    ==651== For counts of detected and suppressed errors, rerun with: -v 
    ==651== Use --track-origins=yes to see where uninitialised values come from 
    ==651== ERROR SUMMARY: 10 errors from 9 contexts (suppressed: 113 from 13) 
+0

どのバージョンのSDLですか? – karlphillip

+0

SDLバージョン1.2.14。 Ubuntu 11.10で動作します。すべての最新アップグレードが適用されます。 – Peter

+1

http://stackoverflow.com/questions/1997171/why-does-valgrind-say-basic-sdl-program-is-leaking-memoryの正確な複製 –

答えて

5

残念ながら、ライブラリがメモリリークを持つことは珍しいことではありません。絶え間なく成長するものでない限り、それは醜いですが大きな問題はありません。 OSがアプリケーション終了時にメモリを解放します。 (少なくともWindowsやLinuxなどのオペレーティングシステム)

+1

ありがとうございました。私は一般的な問題を理解しています。私は、私のコードの中に私が紛失しているものではないという確認をいくつか探していました。過去に人々が使用していた解決策または回避策のいずれか。 – Peter

+0

ああ、賛成票、コメントはありません –

関連する問題