Ticket #9945: BMediaFile-leak.cpp

File BMediaFile-leak.cpp, 1.0 KB (added by ttcoder, 7 years ago)

Change filepath and compile: the leak is reproduced in a dozen lines or so

Line 
1
2// gcc -g BMediaFile-leak.cpp -lbe -lmedia -lroot_debug
3// LD_PRELOAD=libroot_debug.so ./BMediaFile-leak
4
5#include <stdio.h>
6#include <media/MediaFile.h>
7#include <storage/Entry.h>
8
9#include <malloc_debug.h>
10
11
12int main()
13{
14 entry_ref ref;
15#error replace this with a path of your own before compiling
16 get_ref_for_path( "/tmp/Apidya_Credits.mp3", &ref );
17
18 heap_debug_dump_allocations( true, find_thread(NULL) );
19 //total allocations: 416; total bytes: 77964
20
21 // do ten times the new/delete cycle, to amplify
22 // the leak and make it obvious:
23 for( int i = 0; i < 10; i++ )
24 {
25 BMediaFile * mediaFile = new BMediaFile( &ref );
26 heap_debug_dump_allocations( true, find_thread(NULL) );
27
28 delete mediaFile;
29 mediaFile = NULL;
30 heap_debug_dump_allocations( true, find_thread(NULL) );
31
32 //last of the 10 dumps shows 1MB leak:
33 //total allocations: 4713; total bytes: 1233586
34 }
35//full list of allocations:
36//heap_debug_dump_allocations( false, find_thread(NULL) );
37// some 'pmff' markers at some allocations when inspecting memory:
38//debugger( "0x180dd000" );
39}
40