[cheese/wip/hans-fixes-master: 8/16] Fix cheese_camera_device_get_best_format memleak



commit 24d84d62b3153ef9897ec8fc2267c00ae2a130df
Author: Hans de Goede <hdegoede redhat com>
Date:   Mon Jun 10 13:44:47 2013 +0200

    Fix cheese_camera_device_get_best_format memleak
    
    cheese_camera_device_get_best_format() calls
    cheese_camera_device_get_format_list(), which returns a sorted copy of
    the format lists, then takes the first element of that list, and
    returns a copy of that element. While never freeing the list copy.
    
    This patch fixes this leak by simply making the priv->formats list
    sorted so that cheese_camera_device_get_best_format can use it directly
    without the need to make (and then later free) a copy.
    
    Signed-off-by: Hans de Goede <hdegoede redhat com>

 libcheese/cheese-camera-device.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index c7b7a07..d018078 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -219,7 +219,8 @@ cheese_camera_device_add_format (CheeseCameraDevice *device, CheeseVideoFormat *
 
   GST_INFO ("%dx%d", format->width, format->height);
 
-  priv->formats = g_list_append (priv->formats, format);
+  priv->formats = g_list_insert_sorted (priv->formats, format,
+                                        compare_formats);
 }
 
 /*
@@ -700,7 +701,7 @@ cheese_camera_device_get_format_list (CheeseCameraDevice *device)
 {
   g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
 
-  return g_list_sort (g_list_copy (device->priv->formats), compare_formats);
+  return g_list_copy (device->priv->formats);
 }
 
 /**
@@ -789,7 +790,7 @@ cheese_camera_device_get_best_format (CheeseCameraDevice *device)
   g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
 
   format = g_boxed_copy (CHEESE_TYPE_VIDEO_FORMAT,
-                         cheese_camera_device_get_format_list (device)->data);
+                         device->priv->formats->data);
 
   GST_INFO ("%dx%d", format->width, format->height);
   return format;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]