mysql - Splint 不知道库函数正在释放内存

标签 mysql c splint

在 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/

相关文章:

mysql - order by 在 union 子句中返回错误

c - 使用## 的 token 串联不起作用?

c - 将正弦波值从数组发送到音频输出

c - C 移位表达式是否具有无符号类型?为什么 Splint 会警告右移?

c - 夹板在结构内关闭文件指针后涉嫌内存泄漏

c - 夹板调试解析错误

mySQL多数据解析查询

php - 在 php 中查询分层的 mysql 表

mysql - SQL INNER JOIN 多表错误

c - 分配链表后出现段错误