[FFmpeg-cvslog] avutil/slicethread: Check pthread_*_init() for failure
Michael Niedermayer
git at videolan.org
Sun Jul 21 18:18:54 EEST 2024
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Jul 11 23:27:34 2024 +0200| [23851c9ee0f231122c58955e795e17cfe8ca5d98] | committer: Michael Niedermayer
avutil/slicethread: Check pthread_*_init() for failure
Fixes: CID1604383 Unchecked return value
Fixes: CID1604439 Unchecked return value
Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=23851c9ee0f231122c58955e795e17cfe8ca5d98
---
libavutil/slicethread.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/libavutil/slicethread.c b/libavutil/slicethread.c
index 115b099736..e6b82e31b6 100644
--- a/libavutil/slicethread.c
+++ b/libavutil/slicethread.c
@@ -102,6 +102,7 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv,
{
AVSliceThread *ctx;
int nb_workers, i;
+ int ret;
av_assert0(nb_threads >= 0);
if (!nb_threads) {
@@ -135,16 +136,37 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv,
atomic_init(&ctx->first_job, 0);
atomic_init(&ctx->current_job, 0);
- pthread_mutex_init(&ctx->done_mutex, NULL);
- pthread_cond_init(&ctx->done_cond, NULL);
+ ret = pthread_mutex_init(&ctx->done_mutex, NULL);
+ if (ret) {
+ av_freep(&ctx->workers);
+ av_freep(pctx);
+ return AVERROR(ret);
+ }
+ ret = pthread_cond_init(&ctx->done_cond, NULL);
+ if (ret) {
+ ctx->nb_threads = main_func ? 0 : 1;
+ avpriv_slicethread_free(pctx);
+ return AVERROR(ret);
+ }
ctx->done = 0;
for (i = 0; i < nb_workers; i++) {
WorkerContext *w = &ctx->workers[i];
int ret;
w->ctx = ctx;
- pthread_mutex_init(&w->mutex, NULL);
- pthread_cond_init(&w->cond, NULL);
+ ret = pthread_mutex_init(&w->mutex, NULL);
+ if (ret) {
+ ctx->nb_threads = main_func ? i : i + 1;
+ avpriv_slicethread_free(pctx);
+ return AVERROR(ret);
+ }
+ ret = pthread_cond_init(&w->cond, NULL);
+ if (ret) {
+ pthread_mutex_destroy(&w->mutex);
+ ctx->nb_threads = main_func ? i : i + 1;
+ avpriv_slicethread_free(pctx);
+ return AVERROR(ret);
+ }
pthread_mutex_lock(&w->mutex);
w->done = 0;
More information about the ffmpeg-cvslog
mailing list