From 3f114a71c561643b1360f5ac33bf747639d37395 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Wed, 13 Feb 2013 14:27:40 +0100 Subject: [PATCH] QA corner: try to fix 450 kB memleak in bkserver slaves. --- org.glite.lb.server/src/notif_match.c | 4 ++++ org.glite.lb.server/src/stats.c | 11 +++++++++-- org.glite.lb.server/src/store.c.T | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.glite.lb.server/src/notif_match.c b/org.glite.lb.server/src/notif_match.c index 0190547..edaeb9e 100644 --- a/org.glite.lb.server/src/notif_match.c +++ b/org.glite.lb.server/src/notif_match.c @@ -113,6 +113,8 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *oldstat, cons 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; @@ -217,6 +219,8 @@ 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); } diff --git a/org.glite.lb.server/src/stats.c b/org.glite.lb.server/src/stats.c index 58a43a2..5b58a00 100644 --- a/org.glite.lb.server/src/stats.c +++ b/org.glite.lb.server/src/stats.c @@ -83,9 +83,11 @@ int edg_wll_InitStatistics(edg_wll_Context ctx) { 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); @@ -99,7 +101,11 @@ int edg_wll_InitStatistics(edg_wll_Context ctx) 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()"); @@ -119,6 +125,7 @@ int edg_wll_InitStatistics(edg_wll_Context ctx) stats[i].htab = NULL; } } + free(zero); return 0; } diff --git a/org.glite.lb.server/src/store.c.T b/org.glite.lb.server/src/store.c.T index 87573b1..a67435b 100644 --- a/org.glite.lb.server/src/store.c.T +++ b/org.glite.lb.server/src/store.c.T @@ -577,6 +577,7 @@ static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,const char *ulm,char 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; -- 1.8.2.3