[FFmpeg-devel] [PATCH] libavformat/UDP Protocol : seg fault on closing
Laurent BRULET
lbrulet at gmail.com
Fri Jan 13 22:02:33 CET 2012
The following patch fixes ticket #915 (https://ffmpeg.org/trac/ffmpeg/ticket/915)
--
Laurent
---
diff --git a/libavformat/udp.c b/libavformat/udp.c
index cdcd136..fc5b140 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -71,6 +71,7 @@ typedef struct {
pthread_t circular_buffer_thread;
pthread_mutex_t mutex;
pthread_cond_t cond;
+ volatile int exit_thread;
#endif
uint8_t tmp[UDP_MAX_PKT_SIZE+4];
int remaining_in_dg;
@@ -327,7 +328,7 @@ static void *circular_buffer_task( void *_URLContext)
fd_set rfds;
struct timeval tv;
- for(;;) {
+ while(!s->exit_thread) {
int left;
int ret;
int len;
@@ -617,12 +618,18 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
static int udp_close(URLContext *h)
{
UDPContext *s = h->priv_data;
+ int ret;
if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
closesocket(s->udp_fd);
av_fifo_free(s->fifo);
#if HAVE_PTHREADS
+ s->exit_thread = 1;
+ ret = pthread_join(s->circular_buffer_thread, NULL);
+ if (ret != 0)
+ av_log(h, AV_LOG_ERROR, "pthread_join(): %s\n", strerror(ret));
+
pthread_mutex_destroy(&s->mutex);
pthread_cond_destroy(&s->cond);
#endif
More information about the ffmpeg-devel
mailing list