Welcome! Log In Create A New Profile

Advanced

[Solved]Memory leak, again...

Posted by arasium 
[Solved]Memory leak, again...
September 20, 2010 03:16PM
I'm trying to find a memory leak in my program.
During these research, i'v found something strange:

VPAD_Init();

struct mallinfo nfo = mallinfo();
struct mallinfo nfo2;
u32 length = 23801856;
				
				
cout << endl << endl << endl << "Memory used: " << nfo.uordblks << endl;
void* ptr = malloc(length);
nfo2 = mallinfo();
cout << "Allocated: " << nfo2.uordblks << endl;
cout << "Diff: " << nfo2.uordblks - nfo.uordblks << endl;
free(ptr);
nfo = mallinfo();
cout << "Memory used: " << nfo.uordblks << endl;
		
while(VPAD_ButtonsDown(0) == 0);

I think, the allocated memory is bigger from the one requested.... And this is annoying because this can be due to:
1 - There is an error in the malloc (very bad)
2 - The mallinfo function won't help me because it doesn't report the good informations.

What is your point of view?



Edited 2 time(s). Last edit at 09/21/2010 02:29PM by arasium.
Re: Memory leak, again...
September 20, 2010 05:39PM
What did it output? Would help to know what we are looking at.
Re: Memory leak, again...
September 20, 2010 05:43PM
In fact we can see that the malloc will reserved much more space that needed.
To add, this memory won't be freed when we free the pointer.
Re: Memory leak, again...
September 20, 2010 08:37PM
That might be administration data that won't be freed?
Re: Memory leak, again...
September 21, 2010 11:02AM
I hope it won't.

Here is the results:

Memory used: 1 405 872
Allocated: 289 179 224
Diff: 287 773 352
Memory used: 263 971 488


So the diff show us that there is too much allocated memory..... And to add, after the "free", the freed memory correspond to the requested one (ie 23 801 856) and not the one really allocated.
Re: Memory leak, again...
September 21, 2010 11:58AM
i did my test of this and it appears fine on my end. here is my code.
struct mallinfo before;
    struct mallinfo during;
    struct mallinfo after;
    u32 length = 0x2000;
    int poo = 10;
    void* ptr;
    struct mallinfo now = mallinfo();
    gprintf("n: %d\n\n", now.uordblks );

    while( poo-- )
    {
	before = mallinfo();
	ptr = malloc( length );
	during = mallinfo();
	free(ptr);
	after = mallinfo();
	gprintf("b: %d\nd: %d\na: %d\n\n", before.uordblks, during.uordblks, after.uordblks );
    }

and here is my result
n: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192

b: 2192
d: 10392
a: 2192
Re: Memory leak, again...
September 21, 2010 12:08PM
Indeed. My problem occured only with high length values like the one in m'y sample.
I'm using the last devkitpro release.
Re: Memory leak, again...
September 21, 2010 02:23PM
I'm guessing mallinfo() assumes the wii's memory is one contiguous block, when it's actually two discrete blocks (MEM1 and MEM2) with a 243,269,632 byte gap between them.
Re: Memory leak, again...
September 21, 2010 02:29PM
Oh yeah, this is right.

Thank you tueidj. Your contribution is always helpfull.
So my problem is solved, and i will return to my source code to find where is my memory leak :D
Sorry, only registered users may post in this forum.

Click here to login