Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Leak  at pvmfstartpvmd.c:64

Categories: LANG.ALLOC.LEAK CWE:401 CWE:771 CWE:773
Warning ID: 2946.3029
Procedure: pvmfstartpvmd_
Trace: View
Modified: Wed Sep 2 12:54:24 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
ProblemLineSource
   /u1/paul/SATE/2010/c/pvm/pvm3/libfpvm/LINUX64/pvmfstartpvmd.c
   Enter pvmfstartpvmd_
 30 pvmfstartpvmd_ (args_ptr, block, info, args_len) 
 31 char * args_ptr; int args_len;
 32 int *block;
 33 int *info;
 34 {
 35     char *nargs;                        /* args (null terminated) */ 
 36     int ac = 0;                         /* # of agruments initialize to 0 */ 
 37     char **av;                          /* argument vector */ 
 38     register char *ch;                  /* temp char pointer */ 
 39     register char *beg;                 /* pointer to begining of word */ 
 40     register char *end;                 /* pointer to end of word */ 
 41     register int len;                   /* length of word */ 
 42     register int i;                     /* loop index */ 
 43  
 44 #if ( DEBUG ) 
 45     /* printout incoming nargs */ 
 46     printf( "%d \"%s\"\n", args_len, args_ptr ); 
 47 #endif 
 48     /* Some Fortran compilers allow for strings of zero length */ 
 49     if ( args_len == 0 ) {      /* null args */ 
 50         av = (char **)0;                /* make av a null pointer */ 
 51         goto pvmd;
 52     } else {                            /* something in args */ 
 53         if ( ( nargs = TALLOC( args_len + 1, char, "nargs" ) ) 
 54             == NULL ) {
 55             pvmlogerror("pvmfstartpvmd() can't get memory\n");
 56             goto bail;
 57         }
 58         /* copy args (ftocptr() could have been used for that) */ 
 59         strncpy( nargs, args_ptr, args_len );
 60         nargs[args_len] = '\0'; /* terminate with null */   /* Buffer Underrun (ID: 2948.3031) */
 61     }
 62     ch = nargs;                         /* pointer at the begining of nargs */ 
 63     /* assume a max of 32 args (8 should be OK from pvmd3(3PVM)) */ 
referenced by returned value64     if ( ( av = TALLOC( 32, char *, "av" ) ) == NULL ) {     /* Leak */
 65         pvmlogerror("pvmfstartpvmd() can't get memory\n");
 66         PVM_FREE( nargs );              /* avoid memory leeks */ 
 67         goto bail;
 68     }
 69     /* at this point nargs contain at least 1 char */ 
referenced by av70     for ( ; ; ) {
 71         /* move forward until no space nor tab */ 
 72         for( ; *ch == ' ' || *ch == '\t'; ch++ );
 73         beg = ch;                       /* that's the begining of a word */ 
 74         /* move forward until space, tab or null */ 
 75         for( ; *ch != ' ' && *ch != '\t' && *ch != '\0'; ch++ );
 76         end = ch;                       /* that's the end of a word */ 
 77         len = end - beg;                /* length of the word */ 
 78         /* if nothing else then space, tab or null has been found */ 
 79         /* then end of nargs is reached (exit point of loop) */ 
 80         if ( len == 0 ) break;
 81         /* allocate memory for word in agument vector */ 
 82         if ( ( av[ac] = TALLOC( len + 1, char, "av[ac]" ) ) == NULL ) {
 83             pvmlogerror("pvmfstartpvmd() can't get memory\n");
 84             PVM_FREE( nargs );          /* avoid memory leeks */ 
 85             for ( i = 0; i < ac; i++ )
 86                 PVM_FREE( av[i] );
 87             goto bail;
 88         }
 89         strncpyav[ac], beg, len );    /* copy word to arg vector */ 
 90         *( av[ac] + len ) = '\0';       /* null terminate word */   /* Buffer Underrun (ID: 2947.3030) */
 91         ac++;                           /* increment arg counter */ 
 92     }
 93 #if ( DEBUG ) 
 94     printf( "ac is %d\n", ac ); 
 95 #endif 
 96     if ( ac == 0 ) {
 97         /* no args found */ 
   ...
 102         /* printout result */ 
 103         for ( i = 0; i < ac; i++ )
 104             printf( "av[%2d] is \"%s\"\n", i, av[i] ); 
 105 #endif 
 106     }
 107     PVM_FREE( nargs );                  /* free allocated memory */ 
 108  pvmd
 109     /* hopefully pvm_start_pvmd is freeing allocated mem for av */ 
 110     *info = pvm_start_pvmd( ac, av, *block );
 111     return;
 112  bail: 
 113     *info = -1;
leaked114     return;
 115 } 
Preconditions
$param_4 = -1
$heap_253490 = 32
strlen(&$heap_253490) = 1
((char*)&$heap_253490)[1] = 0
pvmmytid != -1
Postconditions
bytes_after(&$heap_253490)' = $param_4 + 1
$heap_253490' is allocated by malloc
$heap_253490' is freed
bytes_before(&$heap_253490)' = 0
((char*)&$heap_253490)[-1]' = 0




Change Warning 2946.3029 : Leak

Priority:
State:
Finding:
Owner:
Note: