Indexing fixes:
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 21 Jul 2008 13:28:43 +0000 (13:28 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 21 Jul 2008 13:28:43 +0000 (13:28 +0000)
- DB module: tiny cleanups
- LB: proper copy only not buildin indices, memleaks

org.glite.lb.server/src/bkindex.c
org.glite.lb.server/src/index.c.T
org.glite.lbjp-common.db/src/db.c

index bc6a47b..0870024 100644 (file)
@@ -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;
 }
index 8f72332..de8a715 100644 (file)
@@ -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<nkeys; i++) free(keys[i]); 
-               free(keys);
-       }
        *index_out = idx;
 
        return edg_wll_ResetError(ctx);
index 5738141..0686f62 100644 (file)
@@ -409,14 +409,13 @@ int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***k
 
                if (i == nkeys) {
                        keys = realloc(keys,(i+2) * sizeof keys[0]);
-                       keys[i] = showcol[Key_name];
+                       keys[i] = strdup(showcol[Key_name]);
 //printf("** KEY [%d] %s\n", i, keys[i]);
                        keys[i+1] = NULL;
                        cols = realloc(cols,(i+1) * sizeof cols[0]); 
                        cols[i] = 0;
                        idx = realloc(idx,(i+2) * sizeof idx[0]);
                        idx[i] = idx[i+1] = NULL;
-                       showcol[Key_name] = NULL;
                        nkeys++;
                }
 
@@ -429,7 +428,7 @@ int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***k
                idx[i][j] = strdup(showcol[Column_name]);
 //printf("****** [%d, %d] %s\n", i, j, idx[i][j]);
 //FIXME: needed?idx[i][j].value.i = atoi(showcol[Sub_part]);
-               for (i = 0; i<(sizeof(showcol)/sizeof(showcol[0])); i++) free(showcol[i]);
+               for (i = 0; i<ret; i++) free(showcol[i]);
        }
 
        glite_lbu_FreeStmt(&stmt);
@@ -449,7 +448,10 @@ int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***k
        }
 
        if (key_names) *key_names = keys;
-       else free(keys);
+       else {
+               for (i = 0; keys[i]; i++) free(keys[i]);
+               free(keys);
+       }
        *column_names = idx;
 
        return STATUS(ctx);