From 845b6acb42fe02c9896853fcf86a449c5af3704a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Mon, 21 Jul 2008 13:28:43 +0000 Subject: [PATCH] Indexing fixes: - DB module: tiny cleanups - LB: proper copy only not buildin indices, memleaks --- org.glite.lb.server/src/bkindex.c | 23 ++++++++++++++++++----- org.glite.lb.server/src/index.c.T | 16 ++++++++++------ org.glite.lbjp-common.db/src/db.c | 10 ++++++---- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/org.glite.lb.server/src/bkindex.c b/org.glite.lb.server/src/bkindex.c index bc6a47b..0870024 100644 --- a/org.glite.lb.server/src/bkindex.c +++ b/org.glite.lb.server/src/bkindex.c @@ -53,13 +53,13 @@ int main(int argc,char **argv) char *fname = "-"; int dump = 0, really = 0, verbose = 0, remove_all = 0; edg_wll_Context ctx; - edg_wll_QueryRec **old_indices,**new_indices; + edg_wll_QueryRec **old_indices = NULL,**new_indices; edg_wll_QueryRec *new_columns[CI_MAX],*old_columns[CI_MAX]; int add_columns[CI_MAX],drop_columns[CI_MAX]; int add_indices[CI_MAX],drop_indices[CI_MAX]; edg_wll_IColumnRec *added_icols; int nadd_icols; - char **index_names; + char **index_names = NULL; int i,j,k; int nnew,nold,nadd,ndrop; char *stmt; @@ -104,7 +104,7 @@ int main(int argc,char **argv) if (dump) { if (edg_wll_DumpIndexConfig(ctx,fname,old_indices)) do_exit(ctx,EX_SOFTWARE); - else if ( !remove_all ) return 0; + else if ( !remove_all ) goto quit; } if (remove_all) { @@ -126,7 +126,7 @@ int main(int argc,char **argv) free(cname); } if (verbose) puts(" done"); - return 0; + goto quit; } if (edg_wll_ParseIndexConfig(ctx,fname,&new_indices)) @@ -256,14 +256,27 @@ int main(int argc,char **argv) if (verbose) { printf("\t%s(%s) ... ",n,l); fflush(stdout); } if (really) { asprintf(&stmt,"create index `%s` on states(%s)",n,l); - free(n); free(l); if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); free(stmt); } + free(n); free(l); if (verbose) puts(really ? "done" : ""); } +quit: + if (index_names) { + for (i = 0; index_names[i]; i++) free(index_names[i]); + free(index_names); + } + if (old_indices) { + for (i = 0; old_indices[i]; i++) { + for (j = 0; old_indices[i][j].attr; j++) edg_wll_QueryRecFree(&old_indices[i][j]); + free(old_indices[i]); + } + free(old_indices); + } edg_wll_Close(ctx); + edg_wll_FreeContext(ctx); return 0; } diff --git a/org.glite.lb.server/src/index.c.T b/org.glite.lb.server/src/index.c.T index 8f72332..de8a715 100644 --- a/org.glite.lb.server/src/index.c.T +++ b/org.glite.lb.server/src/index.c.T @@ -99,6 +99,11 @@ static int parse_indices(edg_wll_Context ctx,char **keys,char ***column_names,co cols[nkeys] = 0; idx = realloc(idx,(nkeys+2) * sizeof idx[0]); idx[nkeys] = idx[nkeys+1] = NULL; + if (keys_out) { + *keys_out = realloc(*keys_out, (nkeys + 2) * sizeof(char *)); + (*keys_out)[nkeys] = strdup(keys[i]); + (*keys_out)[nkeys + 1] = NULL; + } for (j = 0; column_names[i][j]; j++) { if (cols[nkeys] <= j) { @@ -124,16 +129,15 @@ next_index: for (j = 0; column_names[i][j]; j++) free(column_names[i][j]); free(column_names[i]); column_names[i] = NULL; + free(keys[i]); + keys[i] = NULL; + // just for escaping from nested cycles ; /* prevent compiler to complain */ } - + free(column_names); + free(keys); free(cols); - if (keys_out) *keys_out = keys; - else { - for (i=0; i