Memory Leak Explanation
From: pdi (precipice_removethis_at_henzel._.takethisout_..org)
Date: 05/05/04
- Next message: sms: "Re: Global variables!"
- Previous message: Jerry Coffin: "Re: Newbie OOP question"
- Next in thread: Russell Hanneken: "Re: Memory Leak Explanation"
- Reply: Russell Hanneken: "Re: Memory Leak Explanation"
- Reply: MCheu: "Re: Memory Leak Explanation"
- Reply: marbac: "Re: Memory Leak Explanation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 05 May 2004 13:31:00 -0700
Hello All
I have been away from C and C++ for a bit now but having to pick it up
again to do some work on mobile devices. I had a few questions that
came to mind while brushing up on the language again.
I saw this article in the May 2003 version of Linux magazine
discussing Valgrind. In it they had the following example and said
that Valgrind identifies this program as having a memory leak. When
you set the pointer to the second block allocated, the original 512
allocated is lost.
My question is what would be the best way to do this so as to avoid
the mem leak.
Thanks
JPH
Linux Mag Code Sample 2003 May
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *prtr1, *prtr2;
int i;
prtr1 = (char *) malloc (512);
prtr2 = (char *) malloc (512);
prtr2 = ptr1;
free(prt1);
free(ptr2);
}
- Next message: sms: "Re: Global variables!"
- Previous message: Jerry Coffin: "Re: Newbie OOP question"
- Next in thread: Russell Hanneken: "Re: Memory Leak Explanation"
- Reply: Russell Hanneken: "Re: Memory Leak Explanation"
- Reply: MCheu: "Re: Memory Leak Explanation"
- Reply: marbac: "Re: Memory Leak Explanation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|