diff mbox

[FFmpeg-devel] avdevice/decklink: fix leak when listing devices and there is no memory

Message ID 20180317122828.23220-1-cus@passwd.hu
State Accepted
Commit 87455b78cc5191d59394f27751da85d588f05d07
Headers show

Commit Message

Marton Balint March 17, 2018, 12:28 p.m. UTC
Fixes Coverity CID 1419523.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavdevice/decklink_common.cpp | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

Comments

Marton Balint March 24, 2018, 9:06 p.m. UTC | #1
On Sat, 17 Mar 2018, Marton Balint wrote:

> Fixes Coverity CID 1419523.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavdevice/decklink_common.cpp | 17 +++++------------
> 1 file changed, 5 insertions(+), 12 deletions(-)

Applied.

Regards,
Marton
diff mbox

Patch

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index da414ed5f8..b889033cf8 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -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);