Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Memory Leak detection Program without using any tools (http://www.go4expert.com/articles/memory-leak-detection-program-using-t9133/)

asadullah.ansari 5Mar2008 17:20

Re: Memory Leak detection Program without using any tools
 
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;
}


asadullah.ansari 5Mar2008 17:36

Re: Memory Leak detection Program without using any tools
 
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;

}


aisha.ansari84 5Mar2008 17:59

Re: Memory Leak detection Program without using any tools
 
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 5Mar2008 18:01

Re: Memory Leak detection Program without using any tools
 
understood and clear

alramesh 5Mar2008 20:06

Re: Memory Leak detection Program without using any tools
 
I run this program for my application. It's working. Too Cooooooooool.
Thanks asadullah.ansari

flyingfor 5Mar2008 20:19

Re: Memory Leak detection Program without using any tools
 
Excellent asadullah.ansari. I cannt imagine. I am very happy to see this memory leak detector program so simple and understandable.

flyingfor 6Mar2008 09:55

Re: Memory Leak detection Program without using any tools
 
Can you tell me in different languages how to use this program?

ron_genum 6Mar2008 09:57

Re: Memory Leak detection Program without using any tools
 
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 6Mar2008 09:59

Re: Memory Leak detection Program without using any tools
 
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.

asadullah.ansari 6Mar2008 11:07

Re: Memory Leak detection Program without using any tools
 
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?


All times are GMT +5.5. The time now is 22:43.