G
gNash
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char * strclear(const char *str)
{
char *string;
string=(char *)malloc(strlen(str)+1);
strcpy(string,str);
return string;
}
int main()
{
char *str="Five pineapples";
char *string;
string=strclear(str);
printf ("The string is %s\n",string);
free(string);
return 0;
}
Please refer above program for my question..
1. When i run with valgrid i got message as "16 byts in 1 block still
reachable". I think memory is leaking in the program. Am i right?
2. Since i assign value of heap memory starting address and calling
free it is not freed.. why?
3. Could you any one please tell me how can i free the memory which
has been allocated dynamically by another function. without using any
globel variable?
Please help me ..
Thanks in advance,
Ganesh
#include <string.h>
#include <stdlib.h>
char * strclear(const char *str)
{
char *string;
string=(char *)malloc(strlen(str)+1);
strcpy(string,str);
return string;
}
int main()
{
char *str="Five pineapples";
char *string;
string=strclear(str);
printf ("The string is %s\n",string);
free(string);
return 0;
}
Please refer above program for my question..
1. When i run with valgrid i got message as "16 byts in 1 block still
reachable". I think memory is leaking in the program. Am i right?
2. Since i assign value of heap memory starting address and calling
free it is not freed.. why?
3. Could you any one please tell me how can i free the memory which
has been allocated dynamically by another function. without using any
globel variable?
Please help me ..
Thanks in advance,
Ganesh