M
Matt Gostick
It was my pthreads that were leaking.. not my string ops. doh. I
added pthread_join after my pthread_create and I have no more
problems. Perhaps this is not the correct group to ask, but from what
I understand pthread_join causes the main to 'sleep' until the pthread
returns. That's kinda pointless for me since I want to run _many_
pthreads at once. I looked into pthread_detach, but could not get it
to work properly. Should I be using pthread_join?
Matt
----------
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.
added pthread_join after my pthread_create and I have no more
problems. Perhaps this is not the correct group to ask, but from what
I understand pthread_join causes the main to 'sleep' until the pthread
returns. That's kinda pointless for me since I want to run _many_
pthreads at once. I looked into pthread_detach, but could not get it
to work properly. Should I be using pthread_join?
Matt
----------
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.