From 761b17e400cc7ecde246cd2f913f804f0b967fa9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 14 Sep 2004 14:03:16 +0000 Subject: [PATCH] gst/tcp/: Be a bit more paranoid when freeing memory. Original commit message from CVS: * gst/tcp/gstfdset.c: (gst_fdset_wait): * gst/tcp/gstmultifdsink.c: (gst_multifdsink_close): * gst/tcp/gsttcpserversink.c: (gst_tcpserversink_init_send), (gst_tcpserversink_close): Be a bit more paranoid when freeing memory. --- ChangeLog | 8 ++++++++ gst/tcp/gstfdset.c | 4 +++- gst/tcp/gstmultifdsink.c | 20 +++++++++++--------- gst/tcp/gsttcpserversink.c | 6 ++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e54c3bdbd..c90d6d4aa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-09-17 Wim Taymans + + * gst/tcp/gstfdset.c: (gst_fdset_wait): + * gst/tcp/gstmultifdsink.c: (gst_multifdsink_close): + * gst/tcp/gsttcpserversink.c: (gst_tcpserversink_init_send), + (gst_tcpserversink_close): + Be a bit more paranoid when freeing memory. + 2004-09-13 Ronald S. Bultje * gst/qtdemux/qtdemux.c: (gst_qtdemux_add_stream), diff --git a/gst/tcp/gstfdset.c b/gst/tcp/gstfdset.c index b1a3f98a28..f1f486eb15 100644 --- a/gst/tcp/gstfdset.c +++ b/gst/tcp/gstfdset.c @@ -443,7 +443,7 @@ gst_fdset_wait (GstFDSet * set, int timeout) case GST_FDSET_MODE_SELECT: { struct timeval tv; - struct timeval *tvptr = NULL; + struct timeval *tvptr; set->testreadfds = set->readfds; set->testwritefds = set->writefds; @@ -453,6 +453,8 @@ gst_fdset_wait (GstFDSet * set, int timeout) tv.tv_usec = timeout % 1000; tvptr = &tv; + } else { + tvptr = NULL; } res = select (FD_SETSIZE, &set->testreadfds, &set->testwritefds, diff --git a/gst/tcp/gstmultifdsink.c b/gst/tcp/gstmultifdsink.c index e9a8611308..2ebc4463a3 100644 --- a/gst/tcp/gstmultifdsink.c +++ b/gst/tcp/gstmultifdsink.c @@ -1435,26 +1435,28 @@ gst_multifdsink_close (GstMultiFdSink * this) this->running = FALSE; SEND_COMMAND (this, CONTROL_STOP); - g_thread_join (this->thread); + if (this->thread) { + g_thread_join (this->thread); + this->thread = NULL; + } close (READ_SOCKET (this).fd); close (WRITE_SOCKET (this).fd); - gst_fdset_remove_fd (this->fdset, &READ_SOCKET (this)); if (this->streamheader) { - GSList *l; - - for (l = this->streamheader; l; l = l->next) { - gst_buffer_unref (l->data); - } + g_slist_foreach (this->streamheader, (GFunc) gst_data_unref, NULL); g_slist_free (this->streamheader); + this->streamheader = NULL; } if (fclass->close) fclass->close (this); - gst_fdset_free (this->fdset); - this->fdset = NULL; + if (this->fdset) { + gst_fdset_remove_fd (this->fdset, &READ_SOCKET (this)); + gst_fdset_free (this->fdset); + this->fdset = NULL; + } } static GstElementStateReturn diff --git a/gst/tcp/gsttcpserversink.c b/gst/tcp/gsttcpserversink.c index d378631a3c..ee4eab0b9f 100644 --- a/gst/tcp/gsttcpserversink.c +++ b/gst/tcp/gsttcpserversink.c @@ -304,8 +304,6 @@ gst_tcpserversink_init_send (GstMultiFdSink * parent) gst_fdset_add_fd (parent->fdset, &this->server_sock); gst_fdset_fd_ctl_read (parent->fdset, &this->server_sock, TRUE); - //FD_SET (this->server_sock_fd, &parent->readfds); - return TRUE; } @@ -315,10 +313,10 @@ gst_tcpserversink_close (GstMultiFdSink * parent) GstTCPServerSink *this = GST_TCPSERVERSINK (parent); if (this->server_sock.fd != -1) { + gst_fdset_remove_fd (parent->fdset, &this->server_sock); + close (this->server_sock.fd); this->server_sock.fd = -1; - - gst_fdset_remove_fd (parent->fdset, &this->server_sock); } return TRUE; }