[FFmpeg-devel] [PATCH] lavd/avdevice: always free detected devices on error

Lukasz Marek lukasz.m.luki at gmail.com
Tue Mar 4 02:57:27 CET 2014


Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
---
 libavdevice/avdevice.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 5950c0c..e1eb69c 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -198,6 +198,7 @@ void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContex
 
 int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
 {
+    int ret;
     av_assert0(s);
     av_assert0(device_list);
     av_assert0(s->oformat || s->iformat);
@@ -210,8 +211,12 @@ int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
     if (!(*device_list))
         return AVERROR(ENOMEM);
     if (s->oformat)
-        return s->oformat->get_device_list(s, *device_list);
-    return s->iformat->get_device_list(s, *device_list);
+        ret = s->oformat->get_device_list(s, *device_list);
+    else
+        ret = s->iformat->get_device_list(s, *device_list);
+    if (ret < 0)
+        avdevice_free_list_devices(device_list);
+    return ret;
 }
 
 void avdevice_free_list_devices(AVDeviceInfoList **device_list)
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list