mardi 3 janvier 2017

std::vector throwing error on push_back

In the code pasted below I got a SIGSEGV when executing the following statement:

message.push_back((*iv)->id);( frame #9 in gdb)

I analyzed coreDump with gdb. (I am pasting stack trace below). Also I found that length and capacity of message vector are same, 64. So it seems to insert a new value vector needs to be expanded and its throwing error in process of expansion. There are some questions like this, but it seems its different than my case. Also in different runs of code I am getting SIGSEGV or SIGABORT at different points, but all of them are related to insert in an std:vector. I am not pasting all the other gdb traces as it will be too much date. But If required I can put that too.

Some other info:

vector message is of type msgT which is unsigned long and (*iv)->id is of type unsigned int. Notice the vector in frame 11. Its capacity is -18 and length 12.

But that is expected to have 150 elements. When I print its size while execution it does prints 150. Is there something wrong? Or I am misinterpreting gdbs output.

Machine specs:

Linux m4 3.19.0-65-generic #73~14.04.1-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux

Memory:

7 GB ram. Processes never used more than 1% of total system memory.(I was analyzing top while the execution)

Question:

What could be the reason for the error?

Full code:

bool CR::sendRatesToPort(portIdT portNum){
    std::unordered_map<mapIdT,GSP*>::iterator sPort;
    std::unordered_map<flowIdT,GF*>::iterator it, end;
    std::vector<GF*>::iterator iv, ev;
    vector<msgT> message;
    sPort = senders.find(portNum);
    sPort->second->lastRateSentTime = getTimeMillis();
    for(iv = sPort->second->aFV.begin(), ev = sPort->second->aFV.end(); iv != ev ; ++iv){
        rateT rate = (*iv)->getRate();
        if (rate<=0){
            continue;
        }
        message.push_back((*iv)->id);
        message.push_back(rate);
    }
    if(message.size()>0){
        if(sendMessageToPort(sPort->second->getSocketFd(),Utils::rateUpdate, message)){
            return true;
        }else{
            return false;
        }
    }else{
        return true;
    }
  }

gdb stack trace:

  0 0x00007f17980a773f in malloc_consolidate (av=av@entry=0x7f17983e7760 <main_arena>) at malloc.c:4165
  1 0x00007f17980a8ce8 in _int_malloc (av=0x7f17983e7760 <main_arena>, bytes=1024) at malloc.c:3423
  2 0x00007f17980ab6c0 in __GI___libc_malloc (bytes=1024) at malloc.c:2891
  3 0x00007f1798662dad in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  4 0x00000000004056a3 in __gnu_cxx::new_allocator<unsigned long>::allocate (this=0x7ffc7c7fdc30, __n=128) at /usr/include/c++/4.8/ext/new_allocator.h:104
  5 0x000000000040512c in std::_Vector_base<unsigned long, std::allocator<unsigned long> >::_M_allocate (this=0x7ffc7c7fdc30, __n=128) at /usr/include/c++/4.8/bits/stl_vector.h:168
  6 0x000000000040afa5 in std::vector<unsigned long, std::allocator<unsigned long> >::_M_emplace_back_aux<unsigned long>(unsigned long&&) (this=0x7ffc7c7fdc30)
  at /usr/include/c++/4.8/bits/vector.tcc:404
  7 0x000000000040a2f2 in std::vector<unsigned long, std::allocator<unsigned long> >::emplace_back<unsigned long>(unsigned long&&) (this=0x7ffc7c7fdc30) at /usr/include/c++/4.8/bits/vector.tcc:101
  8 0x000000000040983b in std::vector<unsigned long, std::allocator<unsigned long> >::push_back(unsigned long&&) (this=0x7ffc7c7fdc30, 
  __x=<unknown type in /home/ajajoo/coflow-in-cpp-executable/Debug/coflow-in-cpp, CU 0x18375, DIE 0x29bea>) at /usr/include/c++/4.8/bits/stl_vector.h:920
  9 0x000000000043bd46 in CR::sendRatesToPort (this=0x7ffc7c7fdec0, portNum=79) at ../src/global/coordinator/CoordinatorReal.cpp:191
  10 0x000000000043b561 in CR::run (this=0x7ffc7c7fdec0) at ../src/global/coordinator/CR.cpp:105
  11 0x000000000043ad5e in CR::CR (this=0x7ffc7c7fdec0, portIps=std::vector of length 12, capacity -18 = {...}, 
  traceFilePath=0x7ffc7c7ff860 "inputs/cppTrace/coordinatorCppTrace.txt", 
  SPN="x\"z\001\000\000\000\000\000\020\000\000\000\000\000\000\250\"z\001\000\000\000\000ԑ\221\230\027\177\000\000\330\066\r%\000\000\000\000\226{җ\027\177\000\000\000\000\000\000\000\000\000\000\312\f\221\230\027\177\000\000Q\301w\b\000\000\000\000ԑ\221\230\027\177\000\000x\"z\001\000\000\000\000(vd\230\001\000\000\000\020\000z\001\000\000\000\000\300\004z\001\000\000\000\000\300\004z\001", '\000' <repeats 12 times>, "\250\"z\001\000\000\000\000 \000\000\000\001", '\000' <repeats 11 times>, "\320\r\221\230\027\177\000\000\300?z\001\000\000\000\000pDz\001\000\000\000\000\300Gz\001\000\000\000\000\221\001\000\000\000\360CD\000\000\000\000\000"..., outputFileDiscriminator="") at ../src/global/coordinator/CR.cpp:46
  12 0x00000000004416b4 in main (argc=6, argv=0x7ffc7c7fe908) at ../src/coflow-in-cpp.cpp:35

Aucun commentaire:

Enregistrer un commentaire