小编Esk*_*nen的帖子

gcc/linux:CppuTest使用静态向量显示内存泄漏,误报?

在xxxx.h文件中:

struct dn_instance_pair
{
    std::string theDn;
    int theInstance;
};
typedef struct dn_instance_pair t_dn_inst_pair;

struct table_rowid_type
{
    char theTable[101];
    sqlite3_int64 theRowid;
    int operation;
};

// static class members
static vector<t_dn_inst_pair> dninstList;
static vector<t_table_rowid_type> tablerowidList;
Run Code Online (Sandbox Code Playgroud)

在xxxx.cpp中

// declaration of vectors.
// Included to this post only for completeness.
vector<t_dn_inst_pair> xxxx::dninstList;
vector<t_table_rowid_type> xxxx::tablerowidList;
Run Code Online (Sandbox Code Playgroud)

这些向量在静态回调函数中处理,因此它们也必须是静态的.

在cpputest中,当尝试在这些向量中的任何一个中添加某些内容时,会发生故障:

Leak size: 8 Allocated at: <unknown> and line: 0. Type: "new" Content: "<\ufffdP@"
Run Code Online (Sandbox Code Playgroud)

添加到向量中的东西是自动变量,它发生在正常函数中:

t_dn_inst_pair thePair;
thePair.theDn = updated_dn;
thePair.theInstance = updated_instance;
Run Code Online (Sandbox Code Playgroud)

在测试用例结束时清除向量:

xxxx::yyyy()->dninstList.clear();
Run Code Online (Sandbox Code Playgroud)

(yyyy()返回指向单例xxxx对象的指针)

页面http://blog.objectmentor.com/articles/2010/02/04/cpputest-recent-experiences 讨论了相同类型的内存泄漏: …

c++ linux gcc memory-leaks cpputest

6
推荐指数
1
解决办法
1740
查看次数

标签 统计

c++ ×1

cpputest ×1

gcc ×1

linux ×1

memory-leaks ×1