Browse Source

2006-09-04 Miguel de Icaza <[email protected]>

	* src/gmarkup.c: The leak fixing commit.


svn path=/trunk/mono/; revision=64913
Miguel de Icaza 19 years ago
parent
commit
c2ef8d52cf
3 changed files with 34 additions and 12 deletions
  1. 2 0
      eglib/ChangeLog
  2. 28 10
      eglib/src/gmarkup.c
  3. 4 2
      eglib/test/markup.c

+ 2 - 0
eglib/ChangeLog

@@ -1,5 +1,7 @@
 2006-09-04  Miguel de Icaza  <[email protected]>
 
+	* 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. 

+ 28 - 10
eglib/src/gmarkup.c

@@ -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;

+ 4 - 2
eglib/test/markup.c

@@ -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)