[libgda/LIBGDA_4.2] gda_sql_builder_add_field_id()/select_add_field(): Avoid incorrect free().



commit 714d7eb7343f8089490ac859d0fe971612240b38
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Jul 12 21:31:37 2011 +0200

    gda_sql_builder_add_field_id()/select_add_field(): Avoid incorrect free().
    
    Avoid freeing "" string literals.

 libgda/gda-sql-builder.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/libgda/gda-sql-builder.c b/libgda/gda-sql-builder.c
index 6df816e..9ac38e9 100644
--- a/libgda/gda-sql-builder.c
+++ b/libgda/gda-sql-builder.c
@@ -508,8 +508,11 @@ gda_sql_builder_select_add_field (GdaSqlBuilder *builder, const gchar *field_nam
 	}
 	g_return_val_if_fail (field_name && *field_name, 0);
 
-	if (table_name && *table_name)
+	gboolean tmp_is_allocated = FALSE;
+	if (table_name && *table_name) {
 		tmp = g_strdup_printf ("%s.%s", table_name, field_name);
+		tmp_is_allocated = TRUE;
+	}
 	else
 		tmp = (gchar*) field_name;
 
@@ -522,7 +525,7 @@ gda_sql_builder_select_add_field (GdaSqlBuilder *builder, const gchar *field_nam
 		gda_sql_builder_add_field_value_id (builder,
 					      field_id,
 					      0);
-	if (table_name)
+	if (tmp_is_allocated)
 		g_free (tmp);
 
     return field_id;
@@ -976,14 +979,17 @@ GdaSqlBuilderId
 gda_sql_builder_add_field_id (GdaSqlBuilder *builder, const gchar *field_name, const gchar *table_name)
 {
 	gchar* tmp = 0;
-	if (table_name && *table_name)
+	gboolean tmp_is_allocated = FALSE;
+	if (table_name && *table_name) {
 		tmp = g_strdup_printf ("%s.%s", table_name, field_name);
+		tmp_is_allocated = TRUE;
+	}
 	else
 		tmp = (gchar*) field_name;
 
 	guint field_id = gda_sql_builder_add_id (builder, tmp);
 
-	if (table_name)
+	if (tmp_is_allocated)
 		g_free (tmp);
 
 	return field_id;



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