From: miker Date: Wed, 26 Sep 2007 17:56:02 +0000 (+0000) Subject: avoid freeing in-hash data (constification in osrfHash would be great!) X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8de5868eeca6ad50a2e0fabd5bbdae3698db54c8;p=Evergreen.git avoid freeing in-hash data (constification in osrfHash would be great!) git-svn-id: svn://svn.open-ils.org/ILS/trunk@7839 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 588b0b4ee1..3818d4bd3f 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -288,14 +288,12 @@ int osrfAppChildInit() { 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 @@ char* searchJOIN ( jsonObject* join_hash, osrfHash* leftmeta ) { 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 @@ char* searchJOIN ( jsonObject* join_hash, osrfHash* leftmeta ) { 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 @@ char* SELECT ( 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 @@ char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* m 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 );