asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
Quote:
Originally Posted by aisha.ansari84
suppose there is a function which allocates memory for a temporary variable temp , does some work and then returns temp.

i think there should be a memory leak in this case as i cannot free temp ,right so how can i control memory leak here
I think this example will solved your problem.
Code:
#include<malloc.h>

int* fun();
int main()
{
  int *p2 = fun();
  free(p2);
   return 0;
 }

int* fun()
{
  int *p1 = (int *)malloc(10);
  return p1;
}

Last edited by shabbir; 6Mar2008 at 13:23.. Reason: Code block
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
to check memory leak, you can use my program as
Code:
#include<malloc.h>
#include "findLeak.h"


int* fun();
int main()
{
  int *p2 = fun();
  free(p2);
  WriteMemLeak();
  return 0;
 }

int* fun()
{
  int *p1 = (int *)malloc(10);
  return p1;

}

Last edited by shabbir; 6Mar2008 at 13:23.. Reason: Code block
aisha.ansari84's Avatar, Join Date: Feb 2008
Contributor
that means you want to say that i need to free the memory in the function where i m receiving the value returned by temporary variable.
aisha.ansari84's Avatar, Join Date: Feb 2008
Contributor
understood and clear
alramesh's Avatar
Go4Expert Member
I run this program for my application. It's working. Too Cooooooooool.
Thanks asadullah.ansari
flyingfor's Avatar
Go4Expert Member
Excellent asadullah.ansari. I cannt imagine. I am very happy to see this memory leak detector program so simple and understandable.
flyingfor's Avatar
Go4Expert Member
Can you tell me in different languages how to use this program?
ron_genum's Avatar, Join Date: Feb 2008
Go4Expert Member
suppose ive detected memory leaks on my OS as I run that program, what will I do next?
Is there any posible ways to prevent it or get rid of it?
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
Quote:
Originally Posted by flyingfor
Can you tell me in different languages how to use this program?
You can make my program in binary also.

Beauty of this program is that only one interface you have to use, that is "WriteMemLeak()" only.
If any way other languages support to use C Interface, then you can use it.

Last edited by asadullah.ansari; 6Mar2008 at 11:04.. Reason: for Synchronization
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
Quote:
Originally Posted by ron_genum
suppose ive detected memory leaks on my OS as I run that program, what will I do next?
Is there any posible ways to prevent it or get rid of it?
I am not getting your question.

Is it true what i am understanding that "memory leak is in OS not in your program".
If it is true then your question is
"How to detect memory leak coming in OS by program posted by asadullah.ansari? "

Response me?