3

C で MySQL を使用する場合、次のように MySQL API を使用してメモリを解放します。

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

しかし、Splint はそれmysql_closeが実際にメモリを解放していることを認識していないため、次のエラーが発生します。

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)

mysql_closeSplint にメモリの割り当てを解除していることを伝えるにはどうすればよいですか? mysql.hファイルへの特別な注釈?

EDITreleases *p :ヘッダー ファイルで使用できる場合は、おそらく注釈です。しようとします。

編集 2 : に追加/*@releases *sock@*/されましたmysql.hが、次のエラーが発生します:

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

これは の署名ですmysql_close:

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

1 に答える 1