Re: will I get Memory leak..



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.

.



Relevant Pages

  • Re: will I get Memory leak..
    ... dynamically assigned memory area will i get memory leak.. ... Can i use splint tool? ... more) to help you find memory allocation errors. ...
    (comp.lang.c)
  • Re: will I get Memory leak..
    ... dynamically assigned memory area will i get memory leak.. ... Can i use splint tool? ... more) to help you find memory allocation errors. ...
    (comp.lang.c)
  • 1GB plus Memory and the /3GB switch
    ... I have 2 gigs of memory in the machine. ... Started getting Memory allocation errors and virtal memory warnings. ...
    (microsoft.public.windows.server.sbs)
  • Re: [9fans] quantity vs. quality
    ... if the system can't afford memory allocation errors, ... preallocating and capping a maximum that the ... make the memory usage and response times bounded. ...
    (comp.os.plan9)