gl: Don't leak temp strings in _RGB_pixel_order()
authorJan Schmidt <jan@centricular.com>
Fri, 29 May 2015 16:19:25 +0000 (02:19 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:03 +0000 (19:32 +0000)
Fix a memory leak of temporary strings when computing
swizzling of RGB formats.

gst-libs/gst/gl/gstglcolorconvert.c

index 8e49fe9..05cdfe5 100644 (file)
@@ -829,7 +829,9 @@ _RGB_pixel_order (const gchar * expected, const gchar * wanted)
 {
   GString *ret = g_string_sized_new (4);
   gchar *expect, *want;
+  gchar *orig_want;
   int len;
+  gboolean discard_output = TRUE;
 
   if (g_ascii_strcasecmp (expected, wanted) == 0) {
     g_string_free (ret, TRUE);
@@ -837,7 +839,7 @@ _RGB_pixel_order (const gchar * expected, const gchar * wanted)
   }
 
   expect = g_ascii_strdown (expected, -1);
-  want = g_ascii_strdown (wanted, -1);
+  orig_want = want = g_ascii_strdown (wanted, -1);
 
   if (strcmp (expect, "rgb16") == 0 || strcmp (expect, "bgr16") == 0) {
     gchar *temp = expect;
@@ -847,7 +849,7 @@ _RGB_pixel_order (const gchar * expected, const gchar * wanted)
 
   if (strcmp (want, "rgb16") == 0 || strcmp (want, "bgr16") == 0) {
     gchar *temp = want;
-    want = g_strndup (temp, 3);
+    orig_want = want = g_strndup (temp, 3);
     g_free (temp);
   }
 
@@ -859,7 +861,7 @@ _RGB_pixel_order (const gchar * expected, const gchar * wanted)
       len++;
     }
     g_free (want);
-    want = new_want;
+    orig_want = want = new_want;
   }
 
   /* pad expect with 'a's */
@@ -884,7 +886,7 @@ _RGB_pixel_order (const gchar * expected, const gchar * wanted)
 
     if (!(val = strchr (expect, needle))
         && needle == 'a' && !(val = strchr (expect, 'x')))
-      goto fail;
+      goto out;
 
     idx = (gint) (val - expect);
 
@@ -892,11 +894,12 @@ _RGB_pixel_order (const gchar * expected, const gchar * wanted)
     want = &want[1];
   }
 
-  return g_string_free (ret, FALSE);
+  discard_output = FALSE;
+out:
+  g_free (orig_want);
+  g_free (expect);
 
-fail:
-  g_string_free (ret, TRUE);
-  return NULL;
+  return g_string_free (ret, discard_output);
 }
 
 static void