Re: will I get Memory leak..
- From: gNash <ganeshamutha@xxxxxxxxx>
- Date: Wed, 14 Nov 2007 13:09:08 -0000
On Nov 14, 5:59 pm, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:
gNash <ganeshamu...@xxxxxxxxx> writes:
void main()
{
char *fp;
fp=malloc(26);
strcpy(fp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
You should get into the habit now or always checking the return from
malloc. Also, 26 is not enough for this string. You need space for
27 bytes.
fp[10]='\0';
free(fp);
}
Please refer the program for my questions..
1. Can any one tell me if would i assign '\0' at middle of
dynamically assigned memory area will i get memory leak.. ??
No.
2 . Will "free()" delete all the memory which allocated by
dynamically even NULL values has been added in middle of that.??
Yes. BTW, NULL is not the same as '\0'. That is a null byte.
3. How let i know that will i get memory leak in a program?? any
compiler option are there ?? Can i use splint tool ?
There is an excellent tool called "valgrind" that can do this (and
more) to help you find memory allocation errors. splint (and friends)
can tell you about possible portability issues and about errors that
can be detected without running your program.
--
Ben.
Thank you all.. i am clear..
Thank you again..
Ganesh.
.
- References:
- will I get Memory leak..
- From: gNash
- Re: will I get Memory leak..
- From: Ben Bacarisse
- will I get Memory leak..
- Prev by Date: Re: will I get Memory leak..
- Next by Date: Re: will I get Memory leak..
- Previous by thread: Re: will I get Memory leak..
- Next by thread: Re: will I get Memory leak..
- Index(es):
Relevant Pages
|