ju = edg_wlc_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS,cond_where ? cond_where : "",cond_and_where ? cond_and_where : "");
 
        free(ju); ju = NULL;
+       free(cond_where); cond_where = NULL;
+       free(cond_and_where); cond_and_where = NULL;
        glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, jobq);
 
        if (edg_wll_ExecSQL(ctx,jobq,&jobs) < 0) goto err;
        if ( nid ) edg_wll_NotifIdFree(nid);
        free(jobq);
        glite_lbu_FreeStmt(&jobs);
+       free(cond_where);
+       free(cond_and_where);
        return edg_wll_Error(ctx,NULL,NULL);
 }
 
 
 {
        edg_wll_Stats *stats = default_stats;   /* XXX: hardcoded */
        int     i,j;
+       char *zero = NULL;
+       size_t zero_size = 0;
 
        for (i=0; stats[i].type; i++) {
-               char    fname[50],*zero;
+               char    fname[50];
 
                strcpy(fname,"/tmp/lb_stats.XXXXXX");
                stats[i].fd = mkstemp(fname);
                        stats[i].grpsize += sizeof(struct edg_wll_stats_archive)-sizeof(struct edg_wll_stats_cell);
                        stats[i].grpsize += stats[i].archives[j].length * sizeof(struct edg_wll_stats_cell);
                }
-               zero = calloc(1,stats[i].grpsize);
+               if (stats[i].grpsize > zero_size) {
+                       free(zero);
+                       zero = calloc(1, stats[i].grpsize);
+                       zero_size = stats[i].grpsize;
+               }
                write(stats[i].fd,zero,stats[i].grpsize);
                stats[i].map = mmap(NULL,stats[i].grpsize,PROT_READ|PROT_WRITE,MAP_SHARED,stats[i].fd,0);
                if (stats[i].map == MAP_FAILED) return edg_wll_SetError(ctx,errno,"mmap()");
                        stats[i].htab = NULL;
                }
        }
+       free(zero);
        return 0;
 }
 
 
        glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);
 
        if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
+       free(stmt);
 #endif
 
        return err;