Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » memory leak with install_sound() - allegro 4.2.3

This thread is locked; no one can reply to it. rss feed Print
memory leak with install_sound() - allegro 4.2.3
xadow123
Member #14,602
October 2012

Hello everybody! New forum member here and my first post.

Now, let me get to business.

If you compile and run the code below, all goes well. However, when the
program ends memory leaks are detected as shown in the attached image. This only
happens when installing Allegro's sound module. Is this a bug in the library?
Any way to prevent the memory leaks?

#SelectExpand
1#include <allegro.h> 2#include <crtdbg.h> 3 4int main() 5{ 6 //memory leak detector 7 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 8 9 allegro_init(); 10 11 set_color_depth(32); 12 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); 13 14 install_keyboard(); 15 install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL); 16 17 readkey(); 18 19 return 0; 20} 21END_OF_MAIN()

weapon_S
Member #7,859
October 2006
avatar

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Allegro 4.2.3 is the latest binary version of Allegro 4.
Allegro 4.4.1 is the latest source version of Allegro 4, but you have to build it yourself. The memory leak may have been fixed in this version.

Both are outdated by Allegro 5, so unless you have a reason for using 4, move on to 5.

xadow123
Member #14,602
October 2012

thanks for the replies.

i'll try my luck with allegro 4.4.1.

i've already started learning allegro 4.2 since that's what my learning material uses. moving on with allegro 5 would require some time learning things again. seeing some source code for allegro 5, the syntax are different and probably the way of doing things.

i'll get back here to tell you guys the results.

[EDIT]:

i've tried with allegro 4.4.2 but unfortunately there are still memory leaks but from 6 its now down to only 2.

memory leak in 4.2.3:

{"name":"memory_leak_in_allegro_4_2_3.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/d\/9ddaca22cbddfc4d9979ae0178595a1f.png","w":1141,"h":306,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/d\/9ddaca22cbddfc4d9979ae0178595a1f"}memory_leak_in_allegro_4_2_3.png

memory leak in 4.4.2:

{"name":"memory_leak_in_allegro_4_4_2.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/4\/74c7a1e04e479cfdd7cd8873ba6b09d0.png","w":565,"h":190,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/4\/74c7a1e04e479cfdd7cd8873ba6b09d0"}memory_leak_in_allegro_4_4_2.png

source code:

#SelectExpand
1#include <allegro.h> 2#include <crtdbg.h> 3 4int main() 5{ 6 //memory leak detector 7 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 8 9 allegro_init(); 10 11 set_color_depth(32); 12 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); 13 14 install_keyboard(); 15 install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); 16 17 readkey(); 18 19 remove_sound(); 20 allegro_exit(); 21 22 return 0; 23} 24END_OF_MAIN()

can you guys check if the memory leaks are also present in allegro 5 when initializing the sound module.

weapon_S
Member #7,859
October 2006
avatar

[Copied over from other thread]
At the moment you are the expert on this issue. The download came with a debug version of Allegro. Actually two different debug versions: MT and MD. This page seems very explanatory: http://stackoverflow.com/questions/7870343/sdl-memory-leaks-and-visual-leak-detector.
I have no debugging experience with Visual Studio at all... I'm hoping that when you link with the appropriate allegro-debug the weird numbers will turn into something understandable.

xadow123
Member #14,602
October 2012

@weapons_S

i'm no expert either. in fact, i only understood the string "Detected memory leaks!" and i really don't know that much about "_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
". all i know is that it can detect memory leaks and it will tell me that in the debug output.

also i think that the memory leak detector code above is working fine. i tested it with a simple undeleted "int* x = new int;" and it detected the memory leak. i also included "allegro-4.4.2-monolith-md-debug.lib" in config prop->linker->input->additional dependencies.

i don't know what's the difference b/w an MT and MD debug. i simply followed the instructions given in this site: http://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2010_and_Allegro_5. i think its also applicable with allegro 4.4.2.

weapon_S said:

I'm hoping that when you link with the appropriate allegro-debug the weird numbers will turn into something understandable

are you referring to this one: allegro-4.4.2-monolith-md-debug.lib?

weapon_S
Member #7,859
October 2006
avatar

Yep, that's what I mean. Try the /MD linker flag, #define _DEBUG at the start of your file, and link with that specific file. (And set project to "debug"???)
Maybe you can add _CRTDBG_CHECK_ALWAYS_DF to your CRT debug flags. Currently you are only listing memory that isn't deallocated at the end of the program. This is, as mentioned, a moot point. But maybe there is something more fundamentally wrong with Allegro's routines...
(I'm just conveying the manual pages I've found:

)

xadow123
Member #14,602
October 2012

sorry, just now. been busy lately. okay here's what i did basing from your instructions. i'm not sure if i did it right.

1. went to project property pages->c/c++->code generation->runtime library. changed the value from Multi-threaded Debug DLL (/MDd) to Multi-threaded DLL (/MD)

{"name":"step1.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/0\/e098f4448048162b203624b532b359cd.png","w":849,"h":595,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/0\/e098f4448048162b203624b532b359cd"}step1.png

2. changed the code to this one:

#SelectExpand
1#include <allegro.h> 2#include <crtdbg.h> 3 4int main() 5{ 6 //memory leak detector 7 #if defined(DEBUG) | defined(_DEBUG) 8 _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF ); 9 #endif 10 11 allegro_init(); 12 13 set_color_depth(32); 14 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); 15 16 install_keyboard(); 17 install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); 18 19 readkey(); 20 21 remove_sound(); 22 allegro_exit(); 23 24 return 0; 25} 26END_OF_MAIN()

3. there's no allegro-4.2.3-monolith-md-debug.lib in allegro 4.2.3 so i went to project property pages->linker->input->addt'l dependencies then added alld.lib. configuration is also set to debug.

{"name":"step3.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/3\/e35eb7af28518a836f60b36a9e97c662.png","w":851,"h":599,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/3\/e35eb7af28518a836f60b36a9e97c662"}step3.png

4. no more memory leaks:

{"name":"step_4.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/5\/15dda432a907d72b728c860ae0d1ec6f.jpg","w":1023,"h":541,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/5\/15dda432a907d72b728c860ae0d1ec6f"}step_4.png

i quite don't understand what happened. is there a memory leak or not? can somebody explain please.

weapon_S
Member #7,859
October 2006
avatar

What you're doing now seems opposite to what I meant. Now you're not linking to the debug build. I've downloaded 4.4.2. Using MSVC 10 (2010 Express). Linked with debug-md. Using the provided dependency libraries or from the Allegro 5 package made no difference.

Dumping objects ->
{725} normal block at 0x016E8188, 24 bytes long.
 Data: < Y              > E0 59 20 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{724} normal block at 0x016EEAB0, 2048 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
Object dump complete.
The program '[3740] all44_debug1.exe: Native' has exited with code 0 (0x0).

Dumping objects seems MSVC always does in debug. In your previous posts you have perhaps cropped off the relevant information (before "Memory leaks detected").
Just to clarify: what you said in the other thread[1] might be wrong. My method hasn't "fixed" anything, nor should it have. I wanted more adequate debug information. By a little misguidance it seems you have instead removed some debug information; the error might still be there, but is invisible to the compiler now.
For some reason I can't reproduce it. This might be a good thing.

References

  1. You should really post in the most relevant thread. http://www.allegro.cc/forums/thread/611228/968777#target
xadow123
Member #14,602
October 2012

i barely have any knowledge on using msvc's debug tools and _CrtSetDbgFlag so i'm really just making wild guesses.

what i have here is allegro 4.2 and there's no monolith-md-debug.lib for 4.2. i have the 4.4.2 on another computer.

sorry for double posting. i'll just be posting here everything about the install_sound() "memory leak".

i've downloaded 4.4.2 and follow the instructions given here: http://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2010_and_Allegro_5

run the above code again and here's the full debug output:

'allegro_coding.exe': Loaded 'C:\Users\xadow123\Documents\Visual Studio 2010\Projects\allegro_coding\Debug\allegro_coding.exe', Symbols loaded.
'allegro_coding.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Allegro\allegro-4.4.2-msvc-10.0\allegro-4.4.2-msvc-10.0\bin\allegro-4.4.2-monolith-md-debug.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\ddraw.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\dciman32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\dsound.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\powrprof.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\opengl32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\glu32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'allegro_coding.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\nvd3dum.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\dinput.dll', Cannot find or open the PDB file
'allegro_coding.exe': Unloaded 'C:\Windows\System32\dinput.dll'
'allegro_coding.exe': Unloaded 'C:\Windows\System32\nvd3dum.dll'
'allegro_coding.exe': Loaded 'C:\Windows\System32\nvd3dum.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\dinput.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\hid.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\wintrust.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\crypt32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\msasn1.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\MMDevAPI.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\propsys.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x178c) has exited with code 0 (0x0).
'allegro_coding.exe': Loaded 'C:\Windows\System32\AudioSes.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0xaa0) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x11bc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1374) has exited with code 0 (0x0).
'allegro_coding.exe': Loaded 'C:\Windows\System32\wdmaud.drv', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\ksuser.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\avrt.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\msacm32.drv', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\msacm32.dll', Cannot find or open the PDB file
'allegro_coding.exe': Loaded 'C:\Windows\System32\midimap.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x14bc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1508) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xb9c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x4e4) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x16b0) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x122c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x16b4) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1188) has exited with code 0 (0x0).
'allegro_coding.exe': Unloaded 'C:\Windows\System32\nvd3dum.dll'
The thread 'Win32 Thread' (0x1058) has exited with code 0 (0x0).
'allegro_coding.exe': Unloaded 'C:\Windows\System32\dinput.dll'
'allegro_coding.exe': Unloaded 'C:\Windows\System32\hid.dll'
The thread 'Win32 Thread' (0x7bc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x15a8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x8e8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1734) has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{757} normal block at 0x00579040, 24 bytes long.
Data: < > 18 96 0B 00 FF FF FF FF 00 00 00 00 00 00 00 00
{756} normal block at 0x050660A8, 2048 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The thread 'Win32 Thread' (0xb98) has exited with code 0 (0x0).
The program '[1084] allegro_coding.exe: Native' has exited with code 0 (0x0).

Go to: