Gcc / linux: CppuTest showing memory leak using static vectors, false positives?

in the xxxx.h file:

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;

at 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;

These vectors are processed in static callback functions, so they must also be static.

In cpputest, when you try to add something to one of these vectors, it crashes:

Leak size: 8 Allocated at: <unknown> and line: 0. Type: "new" Content: "<\ufffdP@"

Things added to the vector are automatic variables, and this happens in a normal function:

t_dn_inst_pair thePair;
thePair.theDn = updated_dn;
thePair.theInstance = updated_instance;

At the end of the test case, the vector is cleared:

xxxx::yyyy()->dninstList.clear();

(yyyy () returns a pointer to a plain xxxx object)

The http://blog.objectmentor.com/articles/2010/02/04/cpputest-recent-experiences page discusses the same memory leaks:

"This is a false positive. This is a one-time allocation and a side effect of C ++ memory allocation and static initialization."

, : ?

br Esko

+5
1

valgrind? , " " , " ". , ( .)

, vector::clear() , , capacity() .

, :

vector<t_dn_inst_pair>().swap(xxxx::yyyy()->dninstList);

() , .

P.S. , , yyyy()->dninstList (.. operator->), ? xxxx::dninstList ( , .)

+3

All Articles