gl: Don't leak temp strings in _RGB_pixel_order()

Fix a memory leak of temporary strings when computing
swizzling of RGB formats.
This commit is contained in:
Jan Schmidt 2015-05-30 02:19:25 +10:00 committed by Tim-Philipp Müller
parent 5007311198
commit 0f6b04c91d

View file

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