Re: [FFmpeg-devel] [PATCH 01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions

2021-09-03 Thread Andreas Rheinhardt
Steve Lhomme:
> On 2021-09-02 17:34, Andreas Rheinhardt wrote:
>> Also do not destroy and reinitialize mutexes and conditions when
>> certain input parameters change. Given that the decoder did not
>> create these variables at all during init, uninitialized mutexes
>> and conditions are destroyed before the very first initialization.
>> This is undefined behaviour and certain threading implementations
>> like pthreadGC2 crash when it is attempted.
>>
>> Fix this by initializing these objects once during init and freeing
>> them in close.
> 
> Works for me.
> 

Ok, then I will apply this patchset tomorrow unless there are objections.

- Andreas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions

2021-09-03 Thread Steve Lhomme

On 2021-09-02 17:34, Andreas Rheinhardt wrote:

Also do not destroy and reinitialize mutexes and conditions when
certain input parameters change. Given that the decoder did not
create these variables at all during init, uninitialized mutexes
and conditions are destroyed before the very first initialization.
This is undefined behaviour and certain threading implementations
like pthreadGC2 crash when it is attempted.

Fix this by initializing these objects once during init and freeing
them in close.


Works for me.


Reported-by: Steve Lhomme 
Signed-off-by: Andreas Rheinhardt 
---
  libavcodec/vp9.c | 18 +-
  1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 874005a5ae..5c20a7ec5d 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -43,8 +43,6 @@ static void vp9_free_entries(AVCodecContext *avctx) {
  VP9Context *s = avctx->priv_data;
  
  if (avctx->active_thread_type & FF_THREAD_SLICE)  {

-pthread_mutex_destroy(>progress_mutex);
-pthread_cond_destroy(>progress_cond);
  av_freep(>entries);
  }
  }
@@ -66,9 +64,6 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) {
  
  for (i  = 0; i < n; i++)

  atomic_init(>entries[i], 0);
-
-pthread_mutex_init(>progress_mutex, NULL);
-pthread_cond_init(>progress_cond, NULL);
  }
  return 0;
  }
@@ -1252,6 +1247,12 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
  
  free_buffers(s);

  vp9_free_entries(avctx);
+#if HAVE_THREADS
+if (avctx->active_thread_type & FF_THREAD_SLICE) {
+pthread_mutex_destroy(>progress_mutex);
+pthread_cond_destroy(>progress_cond);
+}
+#endif
  av_freep(>td);
  return 0;
  }
@@ -1797,6 +1798,13 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx)
  s->last_bpp = 0;
  s->s.h.filter.sharpness = -1;
  
+#if HAVE_THREADS

+if (avctx->active_thread_type & FF_THREAD_SLICE) {
+pthread_mutex_init(>progress_mutex, NULL);
+pthread_cond_init(>progress_cond, NULL);
+}
+#endif
+
  for (int i = 0; i < 3; i++) {
  s->s.frames[i].tf.f = av_frame_alloc();
  if (!s->s.frames[i].tf.f)
--
2.30.2


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions

2021-09-02 Thread Andreas Rheinhardt
Also do not destroy and reinitialize mutexes and conditions when
certain input parameters change. Given that the decoder did not
create these variables at all during init, uninitialized mutexes
and conditions are destroyed before the very first initialization.
This is undefined behaviour and certain threading implementations
like pthreadGC2 crash when it is attempted.

Fix this by initializing these objects once during init and freeing
them in close.

Reported-by: Steve Lhomme 
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/vp9.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 874005a5ae..5c20a7ec5d 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -43,8 +43,6 @@ static void vp9_free_entries(AVCodecContext *avctx) {
 VP9Context *s = avctx->priv_data;
 
 if (avctx->active_thread_type & FF_THREAD_SLICE)  {
-pthread_mutex_destroy(>progress_mutex);
-pthread_cond_destroy(>progress_cond);
 av_freep(>entries);
 }
 }
@@ -66,9 +64,6 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) {
 
 for (i  = 0; i < n; i++)
 atomic_init(>entries[i], 0);
-
-pthread_mutex_init(>progress_mutex, NULL);
-pthread_cond_init(>progress_cond, NULL);
 }
 return 0;
 }
@@ -1252,6 +1247,12 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
 
 free_buffers(s);
 vp9_free_entries(avctx);
+#if HAVE_THREADS
+if (avctx->active_thread_type & FF_THREAD_SLICE) {
+pthread_mutex_destroy(>progress_mutex);
+pthread_cond_destroy(>progress_cond);
+}
+#endif
 av_freep(>td);
 return 0;
 }
@@ -1797,6 +1798,13 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx)
 s->last_bpp = 0;
 s->s.h.filter.sharpness = -1;
 
+#if HAVE_THREADS
+if (avctx->active_thread_type & FF_THREAD_SLICE) {
+pthread_mutex_init(>progress_mutex, NULL);
+pthread_cond_init(>progress_cond, NULL);
+}
+#endif
+
 for (int i = 0; i < 3; i++) {
 s->s.frames[i].tf.f = av_frame_alloc();
 if (!s->s.frames[i].tf.f)
-- 
2.30.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".