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 9134677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:42:22+00:00 2026-06-17T08:42:22+00:00

My program exits when main function tries to run some class (Rock) more than

  • 0

My program exits when main function tries to run some class (Rock) more than once with a double free or corruption glibc error.

Valgrind returns:

==18672== Conditional jump or move depends on uninitialised value(s)
==18672==    at 0x56F8554: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<unsigned long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /usr/lib64/libstdc++.so.6.0.17)
==18672==    by 0x56F876C: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /usr/lib64/libstdc++.so.6.0.17)
==18672==    by 0x56FB945: std::ostream& std::ostream::_M_insert<unsigned long>(unsigned long) (in /usr/lib64/libstdc++.so.6.0.17)
==18672==    by 0x431515: Rock::saveClustering(std::set<Attribution, std::less<Attribution>, std::allocator<Attribution> >) (rock.cpp:1406)
==18672==    by 0x430C66: Rock::startRock() (rock.cpp:1321)
==18672==    by 0x45DABC: main (main.cpp:207)
==18672==  Uninitialised value was created by a stack allocation
==18672==    at 0x42FF39: Rock::getFinalList(std::vector<Rock::BestLabel, std::allocator<Rock::BestLabel> >&) (rock.cpp:1139)
==18672== 
==18672== 
==18672== HEAP SUMMARY:
==18672==     in use at exit: 292 bytes in 11 blocks
==18672==   total heap usage: 86,558 allocs, 86,547 frees, 21,133,326 bytes allocated
==18672== 
==18672== 292 (52 direct, 240 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 11
==18672==    at 0x4C2BCFB: malloc (vg_replace_malloc.c:270)
==18672==    by 0x5F7FC94: nss_parse_service_list (in /lib64/libc-2.15.so)
==18672==    by 0x5F80173: __nss_database_lookup (in /lib64/libc-2.15.so)
==18672==    by 0xC1C15DB: ???
==18672==    by 0x5F3592B: getpwuid_r@@GLIBC_2.2.5 (in /lib64/libc-2.15.so)
==18672==    by 0x5050638: pqGetpwuid (in /opt/postgres_home/lib/libpq.so.5.3)
==18672==    by 0x503C3BD: pqGetHomeDirectory (in /opt/postgres_home/lib/libpq.so.5.3)
==18672==    by 0x503CCD4: getPgPassFilename (in /opt/postgres_home/lib/libpq.so.5.3)
==18672==    by 0x503F78A: PasswordFromFile (in /opt/postgres_home/lib/libpq.so.5.3)
==18672==    by 0x503FAAB: connectOptions2 (in /opt/postgres_home/lib/libpq.so.5.3)
==18672==    by 0x503FD77: PQconnectStart (in /opt/postgres_home/lib/libpq.so.5.3)
==18672==    by 0x503FDA5: PQconnectdb (in /opt/postgres_home/lib/libpq.so.5.3)
==18672== 
==18672== LEAK SUMMARY:
==18672==    definitely lost: 52 bytes in 1 blocks
==18672==    indirectly lost: 240 bytes in 10 blocks
==18672==      possibly lost: 0 bytes in 0 blocks
==18672==    still reachable: 0 bytes in 0 blocks
==18672==         suppressed: 0 bytes in 0 blocks

I’m not used to Valgring. Does it say that there was unitialized memory that was not free regarding postgres database access? The method I used to fetch the data was:

void Comum::fetchDB ( string sql_statement )
{
    string conn_str ( "dbname=" + getDbName() + " user=" + getDbUser() );
    pqxx::connection conn (conn_str);
    pqxx::work txn (conn);              // ex: domain = "voice"
    pqxx::result r = txn.exec (sql_statement);

    if ( r.size () == 0 ) {
        std::cerr << "No records found for '" << domain << "'." << endl;
        exit (12);
    }

    txn.commit ();

    for (unsigned int u = 0; u != getNrFields (); ++u) {
        vector <string> v;
        v.reserve (r.size());
        db_fetched.push_back (v);
    }

    for (unsigned int rownum = 0; rownum != r.size(); ++rownum) {
        const pqxx::result::tuple row = r[rownum];

        for (unsigned int colnum = 0; colnum != row.size(); ++colnum) {
            const pqxx::result::field f = row[colnum];
            db_fetched [colnum].push_back( f.c_str() );
        }
    }
    conn.disconnect();
}

Regarding the first line of Valgrind’s output Conditional jump or move depends on unitialized value(s) the saveClusteringmethod is like follows:

void Rock::saveClustering (const set<Attribution> result)
{
    string rock_dir = "rock";
    string parent_dir = "output";
    string dir = parent_dir + "/" + rock_dir;

    // Create directory.
    createDir (parent_dir);
    createDir (dir);

    // Build filename.
    string filename;

    map<unsigned int, AttType>::const_iterator citype = att_type.begin();
    while (citype != att_type.end()) {
        filename += citype->second.getName();
        if (++citype != att_type.end()) {
            filename += "-";
        }
    }

    filename = parent_dir + "/" + rock_dir + "/" + filename + "-" + currentDateTime() + ".txt";
    ofstream myfile(filename.c_str());

    if (myfile.is_open()) {
        for ( set<Attribution>::const_iterator ci = result.begin();ci != result.end(); ++ci ) {
            myfile << ci->id << "\t";

            for (vector<unsigned int>::const_iterator enci = ci->encodings.begin(); enci != ci->encodings.end(); ++enci) {
                myfile << *enci << "\t";
            }

            myfile << ci->type << "\t" << ci->assignment << endl;  // 1406 LINE
        }
        myfile << endl;
        myfile.close();

    } else {
        cerr << "It was not possible to save decoder filename " << filename << endl;
        cerr << "Press any key <ENTER> to continue.";
    }
}

I just can’t see what’s wrong and can’t provide a small workable program.

  • 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-17T08:42:23+00:00Added an answer on June 17, 2026 at 8:42 am

    There are two separate problems in the valgrind output.

    The first is the use of uninitialized memory, which it tells you was created on the stack at rock.cpp line 1139

    ==18672==    at 0x42FF39: Rock::getFinalList(std::vector<Rock::BestLabel, std::allocator<Rock::BestLabel> >&) (rock.cpp:1139)
    

    Look at that line and initialize the variable.

    The second problem is a memory leak, apparently from the Postgres API. That’s almost certainly not the cause of your crash.

    Neither of these looks like the cause of a double free error, that’s most likely caused by not implementing a correct copy constructor or copy assignment operator in your class.

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

Sidebar

Related Questions

How does a thread knows when to exit? SITUATION: -while the main program must
My C++ program exits with a std::logic_error and I'd like to track down the
I'd like the program to exit if the input number is less than 0,
Does there exist a free Windows software program that will help you generate regular
The main() function creates a thread that is supposed to live until the user
I have a main function that does a lot of IO. At one point,
So in class we are making a Java program. We are trying to use
I'm trying to compile/run my program (which is working fine on Windows/MSVC) on Fedora/gcc.
I was trying to run a small test program on Xcode (4.2) using C++
This is my program: #include <gtkmm.h> int main (int argc, char* argv[]) { Gtk::Main

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.