Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:19:00+00:00 2026-06-04T22:19:00+00:00

in xxxx.h file: struct dn_instance_pair { std::string theDn; int theInstance; }; typedef struct dn_instance_pair

  • 0

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

in 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 handled in static callback functions, so they must be static too.

In cpputest, when trying to add something in either one of these vectors, a failure happens:

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

The stuff added to a vector are automatic variables and it happens in a normal function:

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

The vector is cleared in the end of the test case:

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

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

Page http://blog.objectmentor.com/articles/2010/02/04/cpputest-recent-experiences
discusses the same kind of memory leak:

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

So my question is:
Is this failure genuinely a false positive ?

br Esko

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:19:02+00:00Added an answer on June 4, 2026 at 10:19 pm

    Have you checked with valgrind? It will distinguish leaked memory that is “definitely lost” from memory that is “still reachable”. If it’s a false positive it should be still reachable (via pointers in the vector.)

    Remember that vector::clear() just destroys the elements, it doesn’t deallocate any memory, so capacity() will remain the same.

    You could do the swap trick to force the vector to deallocate its memory:

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

    That creates a temporary (empty) vector and swaps it with your vector, so your vector’s elements and allocated memory will be transferred to the temporary and then destroyed at the end of the statement.

    P.S. Singletons suck, don’t use them, but why do you access the vector as yyyy()->dninstList (i.e. using operator->) if it’s a static member? You could either say xxxx::dninstList or make it a non-static member and access it via the singleton object (but don’t forget that singletons suck.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
I need to return a string in the form xxx-xxxx where xxx is a
I am looking to find this in a string: XXXX-XXX-XXX Where the X is
My regex pattern looks something like <xxxx location=file path/level1/level2 xxxx some=xxx> I am only
i have a file of numbers like that : XXX are unknow numbers XXXX
Hi i have my text file in this format **4 1250000209852 01 XXXX XXXX
If you have using XXXX.YYYY; at the top of a C# file, do you
{net04:~/xxxx/wip} gcc -o write_test write_test.c In file included from write_test.c:4: global.h:10: warning: `b' initialized
I have a external xxxx.js file where its contents are in non-understandable format. Eg:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.