diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-23 16:13:03 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-23 16:13:03 +0000 |
commit | c5a15468f04a020e9b517eb22d63cc85776be00c (patch) | |
tree | f91ffcf2288a10a06614978371c2551dcebd4436 /net | |
parent | 5380a5b7e62aa57289b877d8b67403dda1be5b7b (diff) |
Fixed NULL-pointer access bug in tcpserver_free() that caused trouble when closing a [tcpserver].
Free send parameters if thread fails to create.
[tcpclient] posts "tcpclient_free" at start and end of tcpclient_free if verbosity==1.
svn path=/trunk/externals/mrpeach/; revision=13243
Diffstat (limited to 'net')
-rw-r--r-- | net/tcpclient.c | 2 | ||||
-rw-r--r-- | net/tcpserver.c | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/net/tcpclient.c b/net/tcpclient.c index 93fbb91..9804db8 100644 --- a/net/tcpclient.c +++ b/net/tcpclient.c @@ -526,9 +526,11 @@ static void *tcpclient_new(t_floatarg udpflag) static void tcpclient_free(t_tcpclient *x) { + if (x->x_verbosity) post("tcpclient_free..."); tcpclient_disconnect(x); clock_free(x->x_poll); clock_free(x->x_clock); + if (x->x_verbosity) post("...tcpclient_free"); } void tcpclient_setup(void) diff --git a/net/tcpserver.c b/net/tcpserver.c index 5272029..e2b8224 100644 --- a/net/tcpserver.c +++ b/net/tcpserver.c @@ -399,6 +399,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a if (0 != (sender_thread_result = pthread_create(&sender_thread, &sender_attr, tcpserver_send_buf_thread, (void *)ttsp))) { error("%s: couldn't create sender thread (%d)", objName, sender_thread_result); + freebytes (ttsp, sizeof (t_tcpserver_send_params)); goto failed; } flen += j; @@ -452,6 +453,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a if ( 0!= (sender_thread_result = pthread_create(&sender_thread, &sender_attr, tcpserver_send_buf_thread, (void *)ttsp))) { error("%s: couldn't create sender thread (%d)", objName, sender_thread_result); + freebytes (ttsp, sizeof (t_tcpserver_send_params)); goto failed; } flen += j; @@ -493,6 +495,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a if ( 0!= (sender_thread_result = pthread_create(&sender_thread, &sender_attr, tcpserver_send_buf_thread, (void *)ttsp))) { error("%s: couldn't create sender thread (%d)", objName, sender_thread_result); + freebytes (ttsp, sizeof (t_tcpserver_send_params)); goto failed; } flen += length; @@ -1026,16 +1029,17 @@ static void tcpserver_free(t_tcpserver *x) { int i; + post("tcp_server_free..."); for(i = 0; i < MAX_CONNECT; i++) { - - if (NULL!=x->x_sr[i]) { - tcpserver_socketreceiver_free(x->x_sr[i]); - if (x->x_sr[i]->sr_fd >= 0) + if (x->x_sr[i] != NULL) + { + if (x->x_sr[i]->sr_fd >= 0) { - sys_rmpollfn(x->x_sr[i]->sr_fd); - sys_closesocket(x->x_sr[i]->sr_fd); + sys_rmpollfn(x->x_sr[i]->sr_fd); + sys_closesocket(x->x_sr[i]->sr_fd); } + tcpserver_socketreceiver_free(x->x_sr[i]); } } if (x->x_connectsocket >= 0) @@ -1043,7 +1047,7 @@ static void tcpserver_free(t_tcpserver *x) sys_rmpollfn(x->x_connectsocket); sys_closesocket(x->x_connectsocket); } - + post("...tcp_server_free"); } void tcpserver_setup(void) |