Ticket #16031: BMediaFile-leak.cpp

File BMediaFile-leak.cpp, 1.8 KB (added by ttcoder, 4 years ago)

Short and sweet test bench for BMediaFile and BMediaTrack

Line 
1
2// gcc -g BMediaFile-leak.cpp -lbe -lmedia -lroot_debug
3// LD_PRELOAD=libroot_debug.so ./BMediaFile-leak
4
5
6// New June 2020 version for working on #16031.
7// Adapted from
8// https://dev.haiku-os.org/raw-attachment/ticket/9945/BMediaFile-leak.cpp
9// and
10// #11752
11
12
13
14#include <stdio.h>
15#include <media/MediaFile.h>
16#include <storage/Entry.h>
17
18#include <malloc_debug.h>
19
20
21int main()
22{
23 entry_ref ref;
24#error replace this with a path of your own before compiling
25 get_ref_for_path( "/tmp/Apidya_Credits.mp3", &ref );
26
27 heap_debug_dump_allocations( true, find_thread(NULL) );
28 //total allocations: 416; total bytes: 77964
29
30 // do ten times the new/delete cycle, to amplify
31 // the leak and make it obvious:
32 for( int i = 0; i < 10; i++ )
33 {
34 BMediaFile * mediaFile = new BMediaFile( &ref );
35 heap_debug_dump_allocations( true, find_thread(NULL) );
36
37#if 1
38#error try without, then with, audio track decoding?
39 BMediaTrack * mediaTrack = mediaFile->TrackAt(0); // will be Release()d in dtor
40
41 media_format decodedmediaformat;
42 memset( &decodedmediaformat, 0, sizeof(decodedmediaformat) );
43 decodedmediaformat.type = B_MEDIA_RAW_AUDIO;
44 ret = mediaTrack->DecodedFormat( &decodedmediaformat );
45
46 for( ;; )
47 {
48 char buf[8192] = { 0 };
49 int64 numread = 0;
50 ret = mediaTrack->ReadFrames(buf,&numread);
51 // printf( "got %Ld frames.. ", numread );
52 //heap_debug_dump_allocations( true, find_thread(NULL));// fflush(stdout);
53
54 if( ret < 0 )
55 break;
56 }
57#endif
58 delete mediaFile;
59 mediaFile = NULL;
60 heap_debug_dump_allocations( true, find_thread(NULL) );
61
62 //last of the 10 dumps shows 1MB leak:
63 //total allocations: 4713; total bytes: 1233586
64 }
65//full list of allocations:
66//heap_debug_dump_allocations( false, find_thread(NULL) );
67// some 'pmff' markers at some allocations when inspecting memory:
68//debugger( "0x180dd000" );
69}
70