在 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)
如何告诉 Splint mysql_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@*/;
最佳答案
我认为正确的注释应该是:
void STDCALL mysql_close(/*@special@*/ /*@notnull@*/ MYSQL *sock)
/*@releases sock@*/;
您错过的关键是 /*@special@*/
注释,这是“激活”所谓的状态子句所必需的。来自 Splint 的文档,7.4 State Clauses :
The
/*@special@*/
annotation is used to mark a parameter, global variable, or return value that is described using state clauses.
关于mysql - Splint 不知道库函数正在释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25186861/