fixing memleaks
authorMiloš Mulač <mulac@civ.zcu.cz>
Mon, 14 Jan 2008 12:27:08 +0000 (12:27 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Mon, 14 Jan 2008 12:27:08 +0000 (12:27 +0000)
org.glite.lb.server/src/db_store.c
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/query.c
org.glite.lb.server/src/store.c.T

index 6102b4f..36ec72e 100644 (file)
@@ -81,6 +81,8 @@ db_store(edg_wll_Context ctx,char *ucs, char *event)
    */
   if (ctx->isProxy && local_job) {
        if  (ev->any.priority & EDG_WLL_LOGFLAG_DIRECT) {
+               edg_wll_FreeEvent(ev);
+               free(ev);
                return 0;
        }
        else {
index b67a91f..a757dec 100644 (file)
@@ -558,12 +558,14 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
                                if (EEXIST == edg_wll_Error(ctx, NULL, NULL)) {
                                /* XXX: this should not happen */
                                        edg_wll_ResetError(ctx);
+                                       free(stmt); stmt = NULL;
                                        tagp++;
                                        continue;
                                }
                                else
                                        goto cleanup;
                        }
+                       free(stmt); stmt = NULL;
                        tagp++;
                }
        }
@@ -585,6 +587,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
        free(icvalues);
 
        if ((dbret = edg_wll_ExecSQL(ctx,stmt,NULL)) < 0) goto cleanup;
+       free(stmt); stmt = NULL;
 
        if (dbret == 0) {
                edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, &stat->pub, 1, &icnames, &icvalues);
@@ -599,6 +602,7 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
                free(icnames); free(icvalues);
 
                if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
+               free(stmt); stmt = NULL;
        }
 
        if (update) {
@@ -606,11 +610,13 @@ edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
                        "where jobid ='%|Ss' and ( seq<%d or version !='%|Ss')",
                        jobid_md5, seq, INTSTAT_VERSION);
                if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
+               free(stmt); stmt = NULL;
        }
        if (update) {
                trio_asprintf(&stmt, "delete from status_tags "
                        "where jobid ='%|Ss' and seq<%d", jobid_md5, seq);
                if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup;
+               free(stmt); stmt = NULL;
        }
 
 cleanup:
index aabe4e6..0c9f5be 100644 (file)
@@ -698,7 +698,6 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec)
                                        free(dbt);
                                        glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt);
                                        trio_asprintf(&out, "%s OR (e.time_stamp >= %s AND e.time_stamp <= %s)", conds, aux, dbt);
-                                       free(dbt);
                                        free(aux);
                                }
                                else if (ec[m][n].op == EDG_WLL_QUERY_OP_EQUAL) {
@@ -716,15 +715,16 @@ static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec)
                                free(dbt);
                                glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt);
                                trio_asprintf(&conds, "(e.time_stamp >= %s AND e.time_stamp <= %s)", aux, dbt);
-                               free(dbt);
                                free(aux);
                        }
                        else if (ec[m][n].op == EDG_WLL_QUERY_OP_EQUAL) {
                                trio_asprintf(&conds, "(e.time_stamp = %s AND e.usec = %d)",
                                                dbt, ec[m][n].value.t.tv_usec);
                        }
-                       else
+                       else {
                                trio_asprintf(&conds, "e.time_stamp %s %s", opToString(ec[m][n].op), dbt);
+                       }
+                       free(dbt);
                        break;
 
                case EDG_WLL_QUERY_ATTR_LEVEL:
index 98a7687..404f1f5 100644 (file)
@@ -101,6 +101,7 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq)
        
        if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0 || edg_wll_FetchRow(ctx,sh,1,NULL,&userid) < 0) goto clean;
        if (sh) glite_lbu_FreeStmt(&sh);
+       free(stmt); stmt = NULL;
 
 
 /* obtain next event sequence number */
@@ -146,6 +147,7 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq)
                        ssrc,e->any.host,
                        stamp,e->any.timestamp.tv_usec,
                        now_s, e->any.level,userid);
+               free(stamp);
 
                if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) {
                        if ((err = edg_wll_Error(ctx,NULL,NULL)) != EEXIST)
@@ -471,8 +473,10 @@ int store_job_server_proxy(edg_wll_Context ctx, edg_wll_Event *event)
                if (event->any.type == EDG_WLL_EVENT_REGJOB) {
                        trio_asprintf(&q,"select cert_subj from jobs,users where jobs.jobid='%|Ss'"
                                        " AND jobs.userid=users.userid",unique);
-                       if ( (nar = edg_wll_ExecSQL(ctx,q,&stmt)) < 0 || edg_wll_FetchRow(ctx,stmt,1,NULL,&owner) < 0 ) 
+                       if ( (nar = edg_wll_ExecSQL(ctx,q,&stmt)) < 0 || edg_wll_FetchRow(ctx,stmt,1,NULL,&owner) < 0 ) 
                                goto err;
+                       }
+                       free(q); q = NULL;
                        
                        if (nar) {
                                /* job is already registered */