From: Manfred Georg <[email protected]>

A badly behaving user provided mutex manager (such as that in OpenCV)
may not reset the mutex to NULL on destruction.

This can cause a problem for a later mutex manager
(which may assert that the mutex is NULL before creating).

Signed-off-by: Manfred Georg <[email protected]>
Signed-off-by: Luca Barbato <[email protected]>
---

Review in patch form:
* We normally use ret for keeping the return value
* We tend to align =


libavcodec/utils.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a472076..204d80b 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2317,19 +2317,25 @@ AVHWAccel *av_hwaccel_next(const AVHWAccel *hwaccel)

 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
 {
+    int ret;
+
     if (lockmgr_cb) {
-        if (lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
-            return -1;
-        if (lockmgr_cb(&avformat_mutex, AV_LOCK_DESTROY))
+        void *old_codec_mutex    = codec_mutex;
+        void *old_avformat_mutex = avformat_mutex;
+
+        codec_mutex    = NULL;
+        avformat_mutex = NULL;
+
+        ret = lockmgr_cb(&old_codec_mutex, AV_LOCK_DESTROY);
+        if (lockmgr_cb(&old_avformat_mutex, AV_LOCK_DESTROY) || ret)
             return -1;
     }

     lockmgr_cb = cb;

     if (lockmgr_cb) {
-        if (lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
-            return -1;
-        if (lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE))
+        ret = lockmgr_cb(&codec_mutex, AV_LOCK_CREATE);
+        if (lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE) || ret)
             return -1;
     }
     return 0;
--
2.1.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to