在 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)
我如何告诉 Splintmysql_close
正在释放内存?文件的特殊注释mysql.h
?
编辑:好的,也许是releases *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@*/;