Splint doesn't know the library function is freeing memory

When using MySQL in C, you free memory using the MySQL API, for example:

MYSQL* connection = NULL;
connection = mysql_init(NULL);
// Stuff...
mysql_close(connection);

      

But Splint doesn't know what is mysql_close

actually freeing memory, so I get this error:

Fresh storage connection not released before return
A memory leak has been detected. Storage allocated locally is 
not released before the last reference to it is lost. (Use 
-mustfreefresh to inhibit warning)

      

How do I tell Splint what is mysql_close

freeing memory? Special annotation for the file mysql.h

?

EDIT : OK, maybe an annotation releases *p

if this can be used in the header file. Try it.

EDIT 2 : Added /*@releases *sock@*/

in mysql.h

, but now get this error:

Releases clauses includes *sock of non-dynamically allocated
              type MYSQL
A declaration uses an invalid annotation. (Use -annotationerror to inhibit
warning)

      

This is a sign mysql_close

:

void STDCALL mysql_close(/*@notnull@*/ MYSQL *sock) /*@releases *sock@*/;

      

+3


source to share


1 answer


I believe the correct annotation would be:

void STDCALL mysql_close(/*@special@*/ /*@notnull@*/ MYSQL *sock)
    /*@releases sock@*/;

      



The key you missed is the annotation /*@special@*/

that is required to "activate" the so-called states. From Splint documentation, 7.4. State classes :

Annotation is /*@special@*/

used to denote a parameter, global variable, or return value, which is described using state positions.

+1


source







All Articles