Thread: Some strange behavior related to my map

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    269

    Some strange behavior related to my map

    I am using valgrind to test, and I get this output (this is an MPI process running on a supercomputer)

    Code:
    ==22894== Conditional jump or move depends on uninitialised value(s)
    ==22894==    at 0x413E29: std::_Rb_tree<int, std::pair<int const, _tx_info_server*>, std::_Select1st<std::pair<int const, _tx_info_server*> >, std::less<int>, std::allocator<std::pair<int const, _tx_info_server*> > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair<int const, _tx_info_server*> const&) (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x414284: std::_Rb_tree<int, std::pair<int const, _tx_info_server*>, std::_Select1st<std::pair<int const, _tx_info_server*> >, std::less<int>, std::allocator<std::pair<int const, _tx_info_server*> > >::_M_insert_unique_(std::_Rb_tree_const_iterator<std::pair<int const, _tx_info_server*> >, std::pair<int const, _tx_info_server*> const&) (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x414649: std::map<int, _tx_info_server*, std::less<int>, std::allocator<std::pair<int const, _tx_info_server*> >>::insert(std::_Rb_tree_iterator<std::pair<int const, _tx_info_server*> >, std::pair<int const, _tx_info_server*> const&) (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x4146F0: std::map<int, _tx_info_server*, std::less<int>, std::allocator<std::pair<int const, _tx_info_server*> > >::operator[](int const&) (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x40CC29: mpi_process_transaction(mpi_tx*, ompi_status_public_t*, MSG_TAG) (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x40CFC3: make_progress(bool) (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x434F17: nssi_service_start (in /gscratch2/jdayal/txserver)
    ==22894==    by 0x40E46C: main (in /gscratch2/jdayal/txserver)
    ==22894==  Uninitialised value was created by a stack allocation
    ==22894==    at 0x41464C: std::map<int, _tx_info_server*, std::less<int>, std::allocator<std::pair<int const, _tx_info_server*> > >::operator[](int const&) (in /gscratch2/jdayal/txserver)
    It looks like the problem is me calling the map in the function mpi_process_transaction.

    These functions, and the map, are declared in my tx_server.cpp file (which is what contains the main for txserver).

    At the top of this file, I create the map this way:

    Code:
    map<int, tx_info_server*> current_tx_map;
    Then, I use it accordingly (this is in the function mpi_process_transaction):

    Code:
    tx_info_server * info = new tx_info_server(tx->tx_id);                                                                                                                                                            
    current_tx_map[info->tx_id] = info;

    Any idea as to what I'm doing wrong?


    I should note, that if I don't use valgrind, it crashes. If I do use valgrind, it throws some errors, like above, but continues with its normal operation!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    info->tx_id is definitely uninitialized here. The whole entire info structure doesn't contain any valid values. (Unless your constructor magically fills it in?) Perhaps you meant to fill it in at some point?

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by tabstop View Post
    info->tx_id is definitely uninitialized here. The whole entire info structure doesn't contain any valid values. (Unless your constructor magically fills it in?) Perhaps you meant to fill it in at some point?
    Sorry, I should have posted the struct and constructor.

    Code:
    struct _tx_info_server                                                                                                                                        
    {                                                                                                                                                             
        int tx_id;                                                                                                                                                
        int num_sub_tx;                                                                                                                                           
        int completed_sub_tx_count;                                                                                                                               
        tx_status STATUS;                                                                                                                                         
        time_t start_time;                                                                                                                                        
        std::list<tx_sub_info_server*> sub_trans;                                                                                                                 
        mpi_info mpi;                                                                                                                                             
        _tx_info_server(int id)                                                                                                                                   
            {                                                                                                                                                     
                mpi.num_msgs = 0;                                                                                                                                 
                mpi.call_count = 0;                                                                                                                               
                mpi.element_size = 0;                                                                                                                             
                mpi.offset = 0;                                                                                                                                   
                mpi.buf = NULL;                                                                                                                                   
                tx_id = id;                                                                                                                                       
            }                                                                                                                                                     
    };
    typedef struct _tx_info_server tx_info_server;
    So there, I am setting the tx_id

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Looking forward, it also says:
    Uninitialised value was created by a stack allocation
    Perhaps tx (where we are getting tx->tx_id from) is uninitialized?

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by tabstop View Post
    Looking forward, it also says:

    Perhaps tx (where we are getting tx->tx_id from) is uninitialized?
    Thanks for your help! You're always there for me lol.

    did a print on tx->tx_id, and it was able to print the correct tx_id.

    I am really perplexed. Something here is the root of that openmpi malloc problem I was having earlier.

    The strange thing is, it works with valgrind, it just shows the errors and proceeds. When I turn off valgrind, it crashes.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you have a way to get line numbers (i.e. using -g when compiling)? There are two code places listed using [] (the one you bolded, and the very last one, and the code addresses differ) so making sure you've got hold of the right one might be a good idea.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Sounds like an uninitialised variable kind of problem alright.
    Try making a minimal but complete example program that produces the problem, possibly starting from a copy of your original program and chopping bits out until there is only as much code as required to produce the problem.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange behavior of pthread_create
    By np2k in forum Linux Programming
    Replies: 13
    Last Post: 05-12-2010, 02:48 AM
  2. Strange behavior
    By onako in forum C++ Programming
    Replies: 1
    Last Post: 05-01-2010, 07:00 AM
  3. strange std::map behavior
    By manav in forum C++ Programming
    Replies: 63
    Last Post: 04-11-2008, 08:00 AM
  4. Strange behavior of Strings
    By shyam168 in forum C Programming
    Replies: 9
    Last Post: 03-27-2006, 07:41 AM
  5. strange behavior
    By agarwaga in forum C Programming
    Replies: 1
    Last Post: 10-17-2005, 12:03 PM