dshow: fix return code when opening device
authorRamiro Polla <ramiro.polla@gmail.com>
Thu, 6 Dec 2012 04:32:47 +0000 (02:32 -0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 8 Dec 2012 20:44:30 +0000 (21:44 +0100)
Successfully opening a device altered the ret variable, making the function
not cleanup properly and return an incorrect value for errors that happened
afterwards.

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavdevice/dshow.c

index ea01b2a..9485af6 100644 (file)
@@ -929,20 +929,18 @@ static int dshow_read_header(AVFormatContext *avctx)
     }
 
     if (ctx->device_name[VideoDevice]) {
-        ret = dshow_open_device(avctx, devenum, VideoDevice);
-        if (ret < 0)
-            goto error;
-        ret = dshow_add_device(avctx, VideoDevice);
-        if (ret < 0)
+        if ((r = dshow_open_device(avctx, devenum, VideoDevice)) < 0 ||
+            (r = dshow_add_device(avctx, VideoDevice)) < 0) {
+            ret = r;
             goto error;
+        }
     }
     if (ctx->device_name[AudioDevice]) {
-        ret = dshow_open_device(avctx, devenum, AudioDevice);
-        if (ret < 0)
-            goto error;
-        ret = dshow_add_device(avctx, AudioDevice);
-        if (ret < 0)
+        if ((r = dshow_open_device(avctx, devenum, AudioDevice)) < 0 ||
+            (r = dshow_add_device(avctx, AudioDevice)) < 0) {
+            ret = r;
             goto error;
+        }
     }
 
     ctx->mutex = CreateMutex(NULL, 0, NULL);