[gnome-db] [PATCH] Fix some memory leaks



The attached patch fixes some memory leaks.  In certain cases, the
string returned from g_object_get() or xmlNodeGetContent() was not freed.

The patch is based on libgda 3.0.2.

Phil
diff -u libgda-3.0.2.orig/libgda/gda-data-model-array.c libgda-3.0.2/libgda/gda-data-model-array.c
--- libgda-3.0.2.orig/libgda/gda-data-model-array.c	2008-01-28 11:17:26.000000000 -0500
+++ libgda-3.0.2/libgda/gda-data-model-array.c	2008-03-16 12:17:45.000000000 -0400
@@ -438,6 +438,7 @@
 
 		g_object_get (G_OBJECT (srccol), "id", &colid, NULL);
 		g_object_set (G_OBJECT (copycol), "id", colid, NULL);
+		g_free(colid);
 		gda_column_set_title (copycol, gda_column_get_title (srccol));
 		gda_column_set_defined_size (copycol, gda_column_get_defined_size (srccol));
 		gda_column_set_name (copycol, gda_column_get_name (srccol));
diff -u libgda-3.0.2.orig/libgda/gda-data-model.c libgda-3.0.2/libgda/gda-data-model.c
--- libgda-3.0.2.orig/libgda/gda-data-model.c	2008-01-28 11:17:26.000000000 -0500
+++ libgda-3.0.2/libgda/gda-data-model.c	2008-03-16 12:02:25.000000000 -0400
@@ -1374,13 +1374,15 @@
 	/* assume @colid is the ID of a column */
 	nbcols = gda_data_model_get_n_columns (model);
 	for (c = 0; !column && (c < nbcols); c++) {
-		const gchar *id;
+		gchar *id;
 		column = gda_data_model_describe_column (model, c);
 		g_object_get (column, "id", &id, NULL);
 		if (!id || strcmp (id, colid)) 
 			column = NULL;
 		else
 			*pos = c;
+		if(id != NULL)
+			g_free(id);
 	}
 
 	/* if no column has been found, assumr @colid is like "_%d" where %d is a column number */
@@ -1470,13 +1472,16 @@
 
 		if (!isnull) {
 			value = g_new0 (GValue, 1);
-			if (!gda_value_set_from_string (value, (gchar*)xmlNodeGetContent (xml_field), gdatype)) {
+			gchar* nodeval = (gchar*)xmlNodeGetContent (xml_field);
+			if (!gda_value_set_from_string (value, nodeval, gdatype)) {
 				g_free (value);
+				xmlFree(nodeval);
 				g_set_error (error, 0, 0, _("Cannot interpret string as a valid %s value"), 
 					     gda_g_type_to_string (gdatype));
 				retval = FALSE;
 				break;
 			}
+			xmlFree(nodeval);
 		}
 		else
 			g_free (isnull);
diff -u libgda-3.0.2.orig/libgda/gda-init.c libgda-3.0.2/libgda/gda-init.c
--- libgda-3.0.2.orig/libgda/gda-init.c	2008-01-28 11:17:26.000000000 -0500
+++ libgda-3.0.2/libgda/gda-init.c	2008-03-09 16:41:01.000000000 -0400
@@ -442,11 +442,12 @@
 			retval = FALSE;
 		}
 		else {
-			if (gda_server_provider_perform_operation (server, cnn, op, error))
+			if (!gda_server_provider_perform_operation (server, cnn, op, error)) {
 				/* error */
 				g_object_unref (op);
 		        xmlFreeDoc(parameters);
-			return FALSE;
+				return FALSE;
+			}
 		}
 		g_object_unref (op);
 		xmlFreeDoc(parameters);
diff -u libgda-3.0.2.orig/libgda/gda-server-operation.c libgda-3.0.2/libgda/gda-server-operation.c
--- libgda-3.0.2.orig/libgda/gda-server-operation.c	2008-01-28 11:17:26.000000000 -0500
+++ libgda-3.0.2/libgda/gda-server-operation.c	2008-03-16 12:38:21.000000000 -0400
@@ -1036,6 +1036,7 @@
 					g_object_get (G_OBJECT (column), "id", &colid, NULL);
 					if (!colid || strcmp (colid, extension +1))
 						column = NULL;
+					g_free(colid);
 				}
 			}
 			g_free (extension);
@@ -1829,6 +1830,7 @@
 					value = gda_data_model_get_value_at (node_info->model, 
 									     gda_column_get_position (node_info->column), 
 									     row);
+				g_free(extension);
 			}
 			g_free (str);
 		}		
@@ -1958,6 +1960,7 @@
 					g_object_get (G_OBJECT (column), "id", &colid, NULL);
 					if (!colid || strcmp (colid, colname +1))
 						column = NULL;
+					g_free(colid);
 				}
 				if (column) {
 					gchar *ptr;
@@ -2008,6 +2011,7 @@
 
 	g_free (extension);
 	g_free (colname);
+	g_free (path);
 	return allok;
 }
 
diff -u libgda-3.0.2.orig/libgda/gda-util.c libgda-3.0.2/libgda/gda-util.c
--- libgda-3.0.2.orig/libgda/gda-util.c	2008-01-28 11:17:26.000000000 -0500
+++ libgda-3.0.2/libgda/gda-util.c	2008-03-16 12:26:19.000000000 -0400
@@ -85,7 +85,7 @@
  * @string: string to escape
  *
  * Escapes @string to make it understandable by a DBMS. The escape method is very common and replaces any
- * occurence of "'" with "\'" and "\" with "\\".
+ * occurence of "'" with "''" and "\" with "\\"
  */
 gchar *
 gda_default_escape_string (const gchar *string)
@@ -111,7 +111,12 @@
 	ret = g_new0 (gchar, size);
 	retptr = ret;
 	while (*ptr) {
-		if ((*ptr == '\'') || (*ptr == '\\')) {
+		if (*ptr == '\'') {
+			*retptr = '\'';
+			*(retptr+1) = *ptr;
+			retptr += 2;
+		}
+		else if (*ptr == '\\') {
 			*retptr = '\\';
 			*(retptr+1) = *ptr;
 			retptr += 2;
@@ -685,6 +690,7 @@
 				col_ids [c] = g_strdup (id);
 			else
 				col_ids [c] = g_strdup_printf ("_%d", c);
+			g_free(id);
 		}
 	}
 
@@ -877,9 +883,10 @@
 			
 			if (!isnull) {
 				GValue *value;
+				gchar* nodeval = (gchar*)xmlNodeGetContent (vnode);
 
 				value = g_new0 (GValue, 1);
-				if (! gda_value_set_from_string (value, (gchar*)xmlNodeGetContent (vnode), gdatype)) {
+				if (! gda_value_set_from_string (value, nodeval, gdatype)) {
 					/* error */
 					g_free (value);
 				}
@@ -887,6 +894,7 @@
 					gda_parameter_set_value (param, value);
 					gda_value_free (value);
 				}
+				xmlFree(nodeval);
 			}
 			else {
 				gda_parameter_set_value (param, NULL);


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