Hi David,

You need to add an annotation to your DeAllocateStruct procedure to
document that it deallocates the passed pointer:

  int DeAllocateStruct(/*@only@*/ struct testStruct **local);

See http://www.splint.org/manual/html/sec5.html for more on the /*@only@*/
annotation.

--- Dave

On Thu, 19 Sep 2002, David Djajaputra wrote:

> Perhaps this is because I'm doing something really stupid here, but I
> have not been able to modify the following simple test program to clear
> all splint complaints. The main problem is splint doesn't seem able to
> recognize that I deallocate my pointers using the DeAllocateStruct
> routine. And I don't want to use the -mustfreefresh flag because I do
> want to check the other situations where I free my memory explicitly in
> the main program. Any suggestions/comments?
>
> Thanks.
>
> David
>
>
>
>
>
>
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> struct testStruct
> {
>   char *testStructString;
> };
>
> int DeAllocateStruct(struct testStruct **local);
>
> /*====================================================================*/
>
> int main ()
> {
>   struct testStruct *localStruct;
>   struct testStruct *secondStruct;
>
>   char *localString1  = "1 localStruct\n";
>   char *localString2  = "2 localStruct\n";
>   char *secondString1 = "1 secondStruct\n";
>   char *secondString2 = "2 secondStruct\n";
>
>
> /*====================================================================*/
>
>   localStruct  = malloc(sizeof(localStruct));
>
>   if (localStruct != NULL) {
>     printf("\nlocalStruct ready to work\n");
>
>     localStruct->testStructString = malloc(sizeof(localString1));
>
>     if (localStruct->testStructString != NULL) {
>       strcpy(localStruct->testStructString,localString1);
>       printf("string = %s",localStruct->testStructString);
>
>       strcpy((*localStruct).testStructString,localString2);
>       printf("string = %s",(*localStruct).testStructString);
>     }
>   }
>
>
> /*====================================================================*/
>
>   secondStruct = malloc(sizeof(secondStruct));
>
>   if (secondStruct != NULL) {
>     printf("\nsecondStruct ready to work\n");
>
>     secondStruct->testStructString = malloc(sizeof(secondString1));
>
>     if (secondStruct->testStructString != NULL) {
>       strcpy(secondStruct->testStructString,secondString1);
>       printf("string = %s",secondStruct->testStructString);
>
>       strcpy((*secondStruct).testStructString,secondString2);
>       printf("string = %s",(*secondStruct).testStructString);
>     }
>   }
>
>
> /*====================================================================*/
>
>   (void) DeAllocateStruct(&localStruct);
>   (void) DeAllocateStruct(&secondStruct);
>
>
> /*====================================================================*/
>
>   /* The following will never be executed if the deallocation is
> successful */
>
>   if (localStruct != NULL) {
>     printf("string = %s",localStruct->testStructString);
>   }
>
>   if (secondStruct != NULL) {
>     printf("string = %s",secondStruct->testStructString);
>   }
>
>   return(0);
> }
> /*====================================================================*/
>
>
>
>
>
> int DeAllocateStruct(struct testStruct **local)
> {
>   free((*local)->testStructString);
>   (*local)->testStructString = NULL;
>
>   free(*local);
>   *local = NULL;
>
>   return(0);
> }
> /*====================================================================*/
>

Reply via email to