TechCake
5Mar2008,17:20   #11
asadullah.ansari's Avatar
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
TechCake
5Mar2008,17:36   #12
asadullah.ansari's Avatar
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
Contributor
5Mar2008,17:59   #13
aisha.ansari84's Avatar
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.
Contributor
5Mar2008,18:01   #14
aisha.ansari84's Avatar
understood and clear
Go4Expert Member
5Mar2008,20:06   #15
alramesh's Avatar
I run this program for my application. It's working. Too Cooooooooool.
Thanks asadullah.ansari
Go4Expert Member
5Mar2008,20:19   #16
flyingfor's Avatar
Excellent asadullah.ansari. I cannt imagine. I am very happy to see this memory leak detector program so simple and understandable.
Go4Expert Member
6Mar2008,09:55   #17
flyingfor's Avatar
Can you tell me in different languages how to use this program?
Go4Expert Member
6Mar2008,09:57   #18
ron_genum's Avatar
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?
TechCake
6Mar2008,09:59   #19
asadullah.ansari's Avatar
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
TechCake
6Mar2008,11:07   #20
asadullah.ansari's Avatar
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?