M
Matt Gostick
Well, it's not useless, it just doesn't seem to be working for me.
Basically, when I'm returning a pointer from a function, free does not
seem to be freeing the memory for me. Here is an example of what I am
trying to do:
char *blah (void) {
char *string;
string = (char *) malloc(sizeof("foobar")*sizeof(char));
strcpy(string, "foobar");
return string;
}
int main (void) {
char *string;
string = blah();
printf("%s\n", string);
free(string);
return 0;
}
-----
I'm not quite sure how to properly diagnose this... as I haven't
touched C in quite some time. Although, the problem I am having now
is evident b/c the software is a high volume socket server and I can
see the process size growing with `top`.
Any help would be very much appretiated.
Thanks,
Matt.
Basically, when I'm returning a pointer from a function, free does not
seem to be freeing the memory for me. Here is an example of what I am
trying to do:
char *blah (void) {
char *string;
string = (char *) malloc(sizeof("foobar")*sizeof(char));
strcpy(string, "foobar");
return string;
}
int main (void) {
char *string;
string = blah();
printf("%s\n", string);
free(string);
return 0;
}
-----
I'm not quite sure how to properly diagnose this... as I haven't
touched C in quite some time. Although, the problem I am having now
is evident b/c the software is a high volume socket server and I can
see the process size growing with `top`.
Any help would be very much appretiated.
Thanks,
Matt.