[open-ils-commits] r7839 - trunk/Open-ILS/src/c-apps

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Sep 26 14:05:52 EDT 2007


Author: miker
Date: 2007-09-26 13:56:02 -0400 (Wed, 26 Sep 2007)
New Revision: 7839

Modified:
   trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
avoid freeing in-hash data (constification in osrfHash would be great!)

Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c	2007-09-26 17:48:11 UTC (rev 7838)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c	2007-09-26 17:56:02 UTC (rev 7839)
@@ -288,14 +288,12 @@
 		if (!tabledef) {
 			tabledef = osrfHashGet(class, "source_definition");
 			buffer_fadd( tablebuf, "(%s)x", tabledef );
+			tabledef = buffer_data(tablebuf);
+			buffer_free(tablebuf);
 		} else {
-			buffer_add( tablebuf, tabledef );
+			tabledef = strdup(tabledef);
 		}
 
-		free(tabledef);
-		tabledef = buffer_data(tablebuf);
-		buffer_free(tablebuf);
-
 		growing_buffer* sql_buf = buffer_init(32);
 		buffer_fadd( sql_buf, "SELECT * FROM %s WHERE 1=0;", tabledef );
 
@@ -1358,9 +1356,10 @@
 		if (!table) {
 			table = osrfHashGet(idlClass, "source_definition");
 			buffer_fadd( tablebuf, "(%s)", table );
-			free(table);
 			table = buffer_data(tablebuf);
 			buffer_free(tablebuf);
+		} else {
+			table = strdup(table);
 		}
 
 		char* type = jsonObjectToSimpleString( jsonObjectGetKey( snode->item, "type" ) );
@@ -1466,6 +1465,8 @@
 
 		buffer_fadd(join_buf, " %s AS \"%s\" ON ( \"%s\".%s = \"%s\".%s", table, class, class, field, leftclass, fkey);
 
+		free(table);
+
 		if (filter) {
 			if (filter_op) {
 				if (!strcasecmp("or",filter_op)) {
@@ -1810,14 +1811,16 @@
 	if (!table) {
 		table = osrfHashGet(core_meta, "source_definition");
 		buffer_fadd( tablebuf, "(%s)", table );
-		free(table);
 		table = buffer_data(tablebuf);
 		buffer_free(tablebuf);
+	} else {
+		table = strdup(table);
 	}
 
 	// Put it all together
 	buffer_fadd(sql_buf, "SELECT %s FROM %s AS \"%s\" ", col_list, table, core_class );
 	free(col_list);
+	free(table);
 
 	// Now, walk the join tree and add that clause
 	if ( join_hash ) {
@@ -2103,12 +2106,14 @@
 	if (!table) {
 		table = osrfHashGet(meta, "source_definition");
 		buffer_fadd( tablebuf, "(%s)", table );
-		free(table);
 		table = buffer_data(tablebuf);
 		buffer_free(tablebuf);
+	} else {
+		table = strdup(table);
 	}
 
 	buffer_fadd(sql_buf, "SELECT %s FROM %s AS \"%s\"", col_list, table, core_class );
+	free(table);
 
 	if ( join_hash ) {
 		char* join_clause = searchJOIN( join_hash, meta );



More information about the open-ils-commits mailing list