[librsvg] Plug a mem leak



commit a8f1e457f88ad73ee31ed033c465a97a1cec7fb7
Author: Christian Persch <chpe gnome org>
Date:   Sat Nov 12 00:16:23 2011 +0100

    Plug a mem leak
    
    ... and don't call g_strv_length() just to find out if length is == 2 !
    
    ==5735== 4 bytes in 1 blocks are definitely lost in loss record 18 of 356
    ==5735==    at 0x402AD89: malloc (vg_replace_malloc.c:236)
    ==5735==    by 0x4566BDA: standard_malloc (gmem.c:85)
    ==5735==    by 0x4566F80: g_malloc (gmem.c:159)
    ==5735==    by 0x4567282: g_malloc_n (gmem.c:361)
    ==5735==    by 0x457DFCC: g_strsplit (gstrfuncs.c:2249)
    ==5735==    by 0x4053934: rsvg_parse_style (rsvg-styles.c:919)

 rsvg-styles.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/rsvg-styles.c b/rsvg-styles.c
index e685eb2..5437ef5 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -918,19 +918,19 @@ parse_style_value (const gchar *string, gchar **value, gboolean *important)
 
     strings = g_strsplit (string, "!", 2);
 
-    if (strings[0] == NULL)
-       return FALSE;
+    if (strings == NULL || strings[0] == NULL) {
+        g_strfreev (strings);
+        return FALSE;
+    }
 
-    if (g_strv_length (strings) == 2 &&
+    if (strings[1] != NULL && strings[2] == NULL &&
         g_str_equal (g_strstrip (strings[1]), "important")) {
         *important = TRUE;
     } else {
         *important = FALSE;
     }
-    if (strings[0])
-        *value = g_strdup (g_strstrip (strings[0]));
-    else
-        *value = g_strdup ("");
+
+    *value = g_strdup (g_strstrip (strings[0]));
 
     g_strfreev (strings);
 



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