2006-09-04 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Tue, 5 Sep 2006 03:40:19 +0000 (03:40 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Tue, 5 Sep 2006 03:40:19 +0000 (03:40 -0000)
* src/gmarkup.c: The leak fixing commit.

svn path=/trunk/mono/; revision=64913

eglib/ChangeLog
eglib/src/gmarkup.c
eglib/test/markup.c

index a2a0a711efb629708419c3822f9b313d62f6a6c2..f82844529448b68a5b50618ad5d298e4a3efe7d8 100644 (file)
@@ -1,5 +1,7 @@
 2006-09-04  Miguel de Icaza  <miguel@novell.com>
 
+       * src/gmarkup.c: The leak fixing commit.
+       
        * src/gmarkup.c (g_markup_parse_context_end_parse): Add missing
        method. 
        (g_markup_parse_context_free): Implement. 
index d3eef9aaf3d082a13dcd67c73a86f49641480983..4c8e81d18b9163e99ba9447b6f0c238b26d712e1 100644 (file)
@@ -173,21 +173,29 @@ parse_attributes (const char *p, const char *end, char ***names, char ***values,
                        p = parse_name (p, end, &name);
                        if (p == end)
                                return p;
+
                        p = skip_space (p, end);
-                       if (p == end)
+                       if (p == end){
+                               free (name);
                                return p;
+                       }
                        if (*p != '='){
                                set_error ("Expected an = after the attribute name `%s'", name);
+                               free (name);
                                return end;
                        }
                        p++;
                        p = skip_space (p, end);
-                       if (p == end)
+                       if (p == end){
+                               free (name);
                                return end;
+                       }
 
                        p = parse_value (p, end, &value, error);
-                       if (p == end)
+                       if (p == end){
+                               free (name);
                                return p;
+                       }
 
                        ++nnames;
                        *names = g_realloc (*names, sizeof (char **) * (nnames+1));
@@ -287,8 +295,9 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                                        g_strfreev (names);
                                        g_strfreev (values);
                                }
-                               
-                               set_error ("Unfinished sequence");
+                               /* Only set the error if parse_attributes did not */
+                               if (error != NULL && *error == NULL)
+                                       set_error ("Unfinished sequence");
                                goto fail;
                        }
                        l = element_end - element_start;
@@ -309,15 +318,20 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                                g_strfreev (values);
                        }
 
-                       if (error != NULL && *error != NULL)
+                       if (error != NULL && *error != NULL){
+                               free (ename);
                                goto fail;
+                       }
                        
                        if (full_stop){
                                if (context->parser.end_element != NULL){
                                        context->parser.end_element (context, ename, context->user_data, error);
-                                       if (error != NULL && *error != NULL)
+                                       if (error != NULL && *error != NULL){
+                                               free (ename);
                                                goto fail;
+                                       }
                                }
+                               free (ename);
                        } else
                                context->level = g_slist_prepend (context->level, ename);
                        
@@ -366,19 +380,23 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 
                case CLOSING_ELEMENT: {
                        GSList *current = context->level;
+                       char *text;
 
                        if (context->level == NULL){
                                set_error ("Too many closing tags, not enough open tags");
                                goto fail;
                        }
+                       text = current->data;
                        
                        if (context->parser.end_element != NULL){
-                               char *text = current->data;
-                               
                                context->parser.end_element (context, text, context->user_data, error);
-                               if (error != NULL && *error != NULL)
+                               if (error != NULL && *error != NULL){
+                                       free (text);
                                        goto fail;
+                               }
                        }
+                       free (text);
+                       
                        context->level = context->level->next;
                        g_slist_free_1 (current);
                        break;
index fb91133cfb6e273e3f5dd76d2a1c5c628ce6b31f..2cd72d158e6538c2145cb3e87b0015944c722f91 100644 (file)
@@ -3,7 +3,7 @@
 #include <glib.h>
 #include "test.h"
 
-#define do_bad_test(s) do { char *r = markup_test (s); if (r == NULL) return FAILED ("Failed on test " # s); } while (0)
+#define do_bad_test(s) do { char *r = markup_test (s); if (r == NULL) return FAILED ("Failed on test " # s); else free (r); } while (0)
 #define do_ok_test(s) do { char *r = markup_test (s); if (r != NULL) return FAILED ("Could not parse valid " # s); } while (0)
 
 static char *
@@ -22,8 +22,10 @@ markup_test (const char *s)
                char *msg = g_strdup (error->message);
                g_error_free (error);
 
+               g_free (parser);
                return msg;
        }
+       g_free (parser);
        return NULL;
 }
 
@@ -162,7 +164,7 @@ mono_domain (void)
 {
        AppConfigInfo *info;
 
-       info = domain_test ("<configuration><!--hello--><startup><!--world--><requiredRuntime version=\"v1\"><!--r--></requiredRuntime></startup></configuration>");
+       info = domain_test ("<configuration><!--hello--><startup><!--world--><requiredRuntime version=\"v1\"><!--r--></requiredRuntime></startup></configuration>"); 
        if (info->required_runtime == NULL)
                return FAILED ("No required runtime section");
        if (strcmp (info->required_runtime, "v1") != 0)