Hi guys,

If I check this with splint 3.0.1.6 +checks:

#include <stdlib.h>

/*@null@*/ /*@only@*/
static char *glob1 = NULL ;
/*@null@*/ /*@only@*/
static char *glob2 = NULL ;

int main( void )
{
#if 0
  if ( glob1 != NULL ) {
    return -1 ;
  }

  if ( glob2 != NULL ) {
    return -1 ;
  }
#else
  if (( glob1 != NULL ) ||
      ( glob2 != NULL )) {
    return -1 ;
  }
#endif

  glob2 = malloc(( size_t )256 ) ;
  free( glob2 ) ;
  glob2 = NULL ;

  return 0 ;
}

I get a warning with the combined test (the #else case):

onlyglob.c: (in function main)
onlyglob.c(25,3): Only storage glob2 (type char *) not released before
                     assignment: glob2 = malloc((size_t)256)
  A memory leak has been detected. Only-qualified storage is not released
  before the last reference to it is lost. (Use -mustfreeonly to inhibit
  warning)
   onlyglob.c(6,14): Storage glob2 becomes only

It seems I have to separate out the tests (the #if case) to make it
clear to Splint that glob2 is unallocated before I assign to it.

Now I know this, I can work around the problem by un-compounding my
sanity checks, but is this a bug or a feature in Splint? :->

Jon


Reply via email to