avdevice/decklink: fix leak when listing devices and there is no memory
authorMarton Balint <cus@passwd.hu>
Sat, 17 Mar 2018 11:41:15 +0000 (12:41 +0100)
committerMarton Balint <cus@passwd.hu>
Sat, 24 Mar 2018 19:55:46 +0000 (20:55 +0100)
Fixes Coverity CID 1419523.

Signed-off-by: Marton Balint <cus@passwd.hu>
libavdevice/decklink_common.cpp

index da414ed..b889033 100644 (file)
@@ -322,21 +322,14 @@ int ff_decklink_list_devices(AVFormatContext *avctx,
                 ret = AVERROR(ENOMEM);
                 goto next;
             }
-            new_device->device_name = av_strdup(displayName);
-            if (!new_device->device_name) {
-                ret = AVERROR(ENOMEM);
-                goto next;
-            }
 
+            new_device->device_name = av_strdup(displayName);
             new_device->device_description = av_strdup(displayName);
-            if (!new_device->device_description) {
-                av_freep(&new_device->device_name);
-                ret = AVERROR(ENOMEM);
-                goto next;
-            }
 
-            if ((ret = av_dynarray_add_nofree(&device_list->devices,
-                                              &device_list->nb_devices, new_device)) < 0) {
+            if (!new_device->device_name ||
+                !new_device->device_description ||
+                av_dynarray_add_nofree(&device_list->devices, &device_list->nb_devices, new_device) < 0) {
+                ret = AVERROR(ENOMEM);
                 av_freep(&new_device->device_name);
                 av_freep(&new_device->device_description);
                 av_freep(&new_device);