[PATCH] Fix crashes when pthread_create fails
Zhouyang Jia <[email protected]>
| Newsgroups | gmane.comp.video.mplayer.devel |
|---|---|
| Message-ID | <CABb2TxLGs-7DE=hapNqxATR6qyt6J6kwz4WF9Q55r3ZwyXZB1w@mail.gmail.com> |
Hi, I'm a PhD student. I analyzed the mplayer source code and found pthread_create missing error handling in several places, which may cause bad results like crash. I think it's unsafe to assume the library function would be correct. It would be better if we could handle the error properly. Attached please find the patch against the trunk version. Hopefully, it can solve these potential bugs. Best, Zhouyang _______________________________________________ MPlayer-dev-eng mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
pthread_create_mplayer-trunk.patch
(application/octet-stream, 1.6 KB)
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index 98766ec..e455148 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -1582,7 +1582,11 @@ static int start(priv_t *priv)
/* start vbi thread */
if(priv->priv_vbi){
priv->vbi_shutdown = 0;
- pthread_create(&priv->vbi_grabber_thread, NULL, vbi_grabber, priv);
+ if (pthread_create(&priv->vbi_grabber_thread, NULL, vbi_grabber, priv) != 0){
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: create thread failed: %s\n",
+ info.short_name, strerror(errno));
+ return 0;
+ }
}
/* start audio thread */
priv->shutdown = 0;
@@ -1640,7 +1644,11 @@ static void *video_grabber(void *data)
priv->streamon = 1;
if (!priv->tv_param->noaudio) {
- pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv);
+ if (pthread_create(&priv->audio_grabber_thread, NULL, audio_grabber, priv) != 0){
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: create thread failed: %s\n",
+ info.short_name, strerror(errno));
+ return 0;
+ }
}
for (priv->frames = 0; !priv->shutdown;)
@@ -1811,7 +1819,11 @@ static double grab_video_frame(priv_t *priv, char *buffer, int len)
int loop_cnt = 0;
if (priv->first) {
- pthread_create(&priv->video_grabber_thread, NULL, video_grabber, priv);
+ if (pthread_create(&priv->video_grabber_thread, NULL, video_grabber, priv) != 0){
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: create thread failed: %s\n",
+ info.short_name, strerror(errno));
+ return 0;
+ }
priv->first = 0;
}