Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
45c39e56
Commit
45c39e56
authored
Jan 14, 2012
by
Laurent BRULET
Committed by
Michael Niedermayer
Jan 14, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
udp: fix segfault on closing
Fixes ticket915
parent
633606c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
5 deletions
+33
-5
udp.c
libavformat/udp.c
+33
-5
No files found.
libavformat/udp.c
View file @
45c39e56
...
@@ -71,6 +71,8 @@ typedef struct {
...
@@ -71,6 +71,8 @@ typedef struct {
pthread_t
circular_buffer_thread
;
pthread_t
circular_buffer_thread
;
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
pthread_cond_t
cond
;
pthread_cond_t
cond
;
int
thread_started
;
volatile
int
exit_thread
;
#endif
#endif
uint8_t
tmp
[
UDP_MAX_PKT_SIZE
+
4
];
uint8_t
tmp
[
UDP_MAX_PKT_SIZE
+
4
];
int
remaining_in_dg
;
int
remaining_in_dg
;
...
@@ -327,7 +329,7 @@ static void *circular_buffer_task( void *_URLContext)
...
@@ -327,7 +329,7 @@ static void *circular_buffer_task( void *_URLContext)
fd_set
rfds
;
fd_set
rfds
;
struct
timeval
tv
;
struct
timeval
tv
;
for
(;;
)
{
while
(
!
s
->
exit_thread
)
{
int
left
;
int
left
;
int
ret
;
int
ret
;
int
len
;
int
len
;
...
@@ -525,18 +527,36 @@ static int udp_open(URLContext *h, const char *uri, int flags)
...
@@ -525,18 +527,36 @@ static int udp_open(URLContext *h, const char *uri, int flags)
#if HAVE_PTHREADS
#if HAVE_PTHREADS
if
(
!
is_output
&&
s
->
circular_buffer_size
)
{
if
(
!
is_output
&&
s
->
circular_buffer_size
)
{
int
ret
;
/* start the task going */
/* start the task going */
s
->
fifo
=
av_fifo_alloc
(
s
->
circular_buffer_size
);
s
->
fifo
=
av_fifo_alloc
(
s
->
circular_buffer_size
);
pthread_mutex_init
(
&
s
->
mutex
,
NULL
);
ret
=
pthread_mutex_init
(
&
s
->
mutex
,
NULL
);
pthread_cond_init
(
&
s
->
cond
,
NULL
);
if
(
ret
!=
0
)
{
if
(
pthread_create
(
&
s
->
circular_buffer_thread
,
NULL
,
circular_buffer_task
,
h
))
{
av_log
(
h
,
AV_LOG_ERROR
,
"pthread_mutex_init failed : %s
\n
"
,
strerror
(
ret
));
av_log
(
h
,
AV_LOG_ERROR
,
"pthread_create failed
\n
"
);
goto
fail
;
goto
fail
;
}
}
ret
=
pthread_cond_init
(
&
s
->
cond
,
NULL
);
if
(
ret
!=
0
)
{
av_log
(
h
,
AV_LOG_ERROR
,
"pthread_cond_init failed : %s
\n
"
,
strerror
(
ret
));
goto
cond_fail
;
}
ret
=
pthread_create
(
&
s
->
circular_buffer_thread
,
NULL
,
circular_buffer_task
,
h
);
if
(
ret
!=
0
)
{
av_log
(
h
,
AV_LOG_ERROR
,
"pthread_create failed : %s
\n
"
,
strerror
(
ret
));
goto
thread_fail
;
}
s
->
thread_started
=
1
;
}
}
#endif
#endif
return
0
;
return
0
;
#if HAVE_PTHREADS
thread_fail:
pthread_cond_destroy
(
&
s
->
cond
);
cond_fail:
pthread_mutex_destroy
(
&
s
->
mutex
);
#endif
fail:
fail:
if
(
udp_fd
>=
0
)
if
(
udp_fd
>=
0
)
closesocket
(
udp_fd
);
closesocket
(
udp_fd
);
...
@@ -617,12 +637,20 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
...
@@ -617,12 +637,20 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
static
int
udp_close
(
URLContext
*
h
)
static
int
udp_close
(
URLContext
*
h
)
{
{
UDPContext
*
s
=
h
->
priv_data
;
UDPContext
*
s
=
h
->
priv_data
;
int
ret
;
if
(
s
->
is_multicast
&&
(
h
->
flags
&
AVIO_FLAG_READ
))
if
(
s
->
is_multicast
&&
(
h
->
flags
&
AVIO_FLAG_READ
))
udp_leave_multicast_group
(
s
->
udp_fd
,
(
struct
sockaddr
*
)
&
s
->
dest_addr
);
udp_leave_multicast_group
(
s
->
udp_fd
,
(
struct
sockaddr
*
)
&
s
->
dest_addr
);
closesocket
(
s
->
udp_fd
);
closesocket
(
s
->
udp_fd
);
av_fifo_free
(
s
->
fifo
);
av_fifo_free
(
s
->
fifo
);
#if HAVE_PTHREADS
#if HAVE_PTHREADS
if
(
s
->
thread_started
)
{
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_mutex_destroy
(
&
s
->
mutex
);
pthread_cond_destroy
(
&
s
->
cond
);
pthread_cond_destroy
(
&
s
->
cond
);
#endif
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment