From b24c11f89613f6d9ed3429e642b0c4bd610efd7e Mon Sep 17 00:00:00 2001 From: "Matthias Huetsch [mhu]" Date: Thu, 25 Nov 2010 14:13:43 +0100 Subject: #i115784# dmake: fix memory errors uncovered by valgrind and other tools. --- dmake/unix/runargv.c | 171 +++++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 87 deletions(-) (limited to 'dmake/unix') diff --git a/dmake/unix/runargv.c b/dmake/unix/runargv.c index 4be342bbb273..e8e39d21bd3d 100644 --- a/dmake/unix/runargv.c +++ b/dmake/unix/runargv.c @@ -878,41 +878,36 @@ int wfc; /* Never change MAXPROCESS after _procs is allocated. */ if( _procs_size != Max_proc ) { - /* If procs was never initialize this is OK, do it now. */ - if( _procs == NIL(PR) ) { - _procs_size = Max_proc; - TALLOC( _procs, Max_proc, PR ); + /* If procs was never initialize this is OK, do it now. */ + if( _procs == NIL(PR) ) { + _procs_size = Max_proc; + TALLOC( _procs, Max_proc, PR ); #if defined(USE_CREATEPROCESS) - TALLOC( _wpList, Max_proc, HANDLE ); + TALLOC( _wpList, Max_proc, HANDLE ); - /* Signed int values are cast to DMHANDLE in various places, use this - * sanity check to verify that DMHANDLE is large enough. */ - if( sizeof(int) > sizeof(DMHANDLE) ) - Fatal( "Internal Error: Check type of DMHANDLE!" ); + /* Signed int values are cast to DMHANDLE in various places, use this + * sanity check to verify that DMHANDLE is large enough. */ + if( sizeof(int) > sizeof(DMHANDLE) ) + Fatal( "Internal Error: Check type of DMHANDLE!" ); #endif - } - else { - Fatal( "MAXPROCESS changed from `%d' to `%d' after a command was executed!", _procs_size, Max_proc ); - } + } + else { + Fatal( "MAXPROCESS changed from `%d' to `%d' after a command was executed!", _procs_size, Max_proc ); + } } if( Measure & M_RECIPE ) Do_profile_output( "s", M_RECIPE, target ); - /* If _use_i!=-1 then this function is called by _finished_child() - * ( through runargv() ). */ + /* If _use_i ! =-1 then this function is called by _finished_child() ( through runargv() ), + and we re-use the process queue number given by _use_i. */ if( (i = _use_i) == -1 ) { - for( i=0; ipr_valid = 1; pp->pr_pid = pid.pid; @@ -921,7 +916,9 @@ int wfc; pp->pr_ignore = ignore; pp->pr_last = last; pp->pr_wfc = wfc; - /* Freed above and after the last recipe in _finished child(). */ + + if( pp->pr_dir != NIL(char) ) + FREE(pp->pr_dir); pp->pr_dir = DmStrDup(Get_current_dir()); Current_target = NIL(CELL); @@ -953,80 +950,80 @@ _finished_child(cid, status)/* DMHANDLE cid; int status; { - register int i; - char *dir; - - if((int)cid < 1) { /* Force int. */ - /* internal command */ - i = -((int)cid); - } - else { - for( i=0; ice_attr & A_ERROR ) { - _procs[i].pr_last = TRUE; - goto ABORT_REMAINDER_OF_RECIPE; - } + if ( _procs[i].pr_target->ce_attr & A_ERROR ) { + _procs[i].pr_last = TRUE; + goto ABORT_REMAINDER_OF_RECIPE; + } - _procs[i].pr_recipe = rp->prp_next; + _procs[i].pr_recipe = rp->prp_next; - _use_i = i; - /* Run next recipe line. The rp->prp_attr propagates a possible - * wfc condition. */ - runargv( _procs[i].pr_target, rp->prp_group, - rp->prp_last, rp->prp_attr, &rp->prp_cmd ); - _use_i = -1; + _use_i = i; + /* Run next recipe line. The rp->prp_attr propagates a possible + * wfc condition. */ + runargv( _procs[i].pr_target, rp->prp_group, + rp->prp_last, rp->prp_attr, &rp->prp_cmd ); + _use_i = -1; - FREE( rp->prp_cmd ); - FREE( rp ); + FREE( rp->prp_cmd ); + FREE( rp ); - /* If all process queues are used wait for the next process to - * finish. Is this really needed here? */ - if( _proc_cnt == Max_proc ) { - Wait_for_child( FALSE, -1 ); - } - } - else { - /* empty the queue on abort. */ - if( _abort_flg ) - _procs[i].pr_recipe = NIL(RCP); + /* If all process queues are used wait for the next process to + * finish. Is this really needed here? */ + if( _proc_cnt == Max_proc ) { + Wait_for_child( FALSE, -1 ); + } + } + else { + /* empty the queue on abort. */ + if( _abort_flg ) + _procs[i].pr_recipe = NIL(RCP); - Handle_result(status,_procs[i].pr_ignore,_abort_flg,_procs[i].pr_target); + Handle_result(status,_procs[i].pr_ignore,_abort_flg,_procs[i].pr_target); - ABORT_REMAINDER_OF_RECIPE: - if( _procs[i].pr_last ) { - FREE(_procs[i].pr_dir ); /* Set in _add_child() */ + ABORT_REMAINDER_OF_RECIPE: + if( _procs[i].pr_last ) { + FREE(_procs[i].pr_dir ); _procs[i].pr_dir = NIL(char); /* Set in _add_child() */ - if( !Doing_bang ) { + if( !Doing_bang ) { /* Update_time_stamp() triggers the deletion of intermediate * targets. This starts a new process queue, so we have to * clear the _use_i variable. */ @@ -1035,12 +1032,12 @@ int status; _use_i = -1; Update_time_stamp( _procs[i].pr_target ); _use_i = my_use_i; - } } - } + } + } - Set_dir(dir); - FREE(dir); + Set_dir(dir); + FREE(dir); } -- cgit