M
Mark Bluemel
gNash said:Hi all,
void main()
{
char *fp;
fp=malloc(26);
strcpy(fp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
fp[10]='\0';
free(fp);
}
Please refer the program for my questions..
Your program has bugs which have already been pointed out.
1. Can any one tell me if would i assign '\0' at middle of
dynamically assigned memory area will i get memory leak.. ??
Yes, of course someone can tell you that. No, you won't get a memory
leak.
2 . Will "free()" delete all the memory which allocated by
dynamically even NULL values has been added in middle of that.??
free() doesn't care what's in the memory pointed to by its argument.
It has other ways, which vary according to the implementation of the
library, of telling how large a region of memory to free.
3. How let i know that will i get memory leak in a program?? any
compiler option are there ?? Can i use splint tool ?
Memory leaks are dynamic. Compiler options and splint can only perform
static analysis. Tools such as valgrind can perform certain dynamic
analyses and detect (at least some) memory leaks.