Today I had a fun bug where apparently my stack got smashed, overriding the G++ return-point canary (I think that's the protection used).
My offending class was this:
class ClientSendContext : public SendContext
{
public:
ClientSendContext(UdpClient& client);
void send(boost::asio::const_buffer buffer);
private:
boost::asio::ip::udp::endpoint endpoint;
UdpClient& client;
};
The thing was, the client variable was initialized in the initializer list, but not the endpoint (it's not used in the ClientSendContext, since it only sends to one endpoint, but no matter). The smash-stack occured once every three times I executed my test (or something like that) which is weird, since I do the exact same thing (must be thread timing issue).
However, as soon I remove the endpoint variable, it works fine! How can this be? It wasn't used in any way, g++ didn't warn me about it... Valgrind was quiet aswell.
(Could someone with high rep please edit my question and add stack-smash or something like that as a tag?)
Alright, an update with more code, posted on pastebin:
http://pastebin.com/xiWx8xjV
That should be all the methods called. The inner most send method is part of a templated class. The same send method works fine when the UdpServer uses it.. I'm just a bit stumped right now.
EDIT: Code now put directly here:
void doTest(bool& failed)
{
ReceiveHelper helper(failed);
boost::threadpool::pool pool(2);
int port = 55600;
boost::asio::io_service service;
udp::endpoint thisPoint = udp::endpoint(address::from_string("127.0.0.1"),
port);
udp::endpoint receivePoint;
udp::socket socket(service, thisPoint);
socket.async_receive_from(boost::asio::buffer(helper.buffer), receivePoint, boost::bind(&ReceiveHelper::handleReceive,
&helper, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
pool.schedule(boost::bind(&boost::asio::io_service::run, &service));
voip::network::client::UdpClient client;
client.connect(thisPoint);
client.send(1, "Hello!");
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
service.stop();
}
class ReceiveHelper {
private:
bool& failed;
public:
ReceiveHelper(bool & failed) : failed(failed), buffer()
{
}
boost::array<uint8_t, BUF_SIZE> buffer;
void handleReceive(const boost::system::error_code & error, size_t numBytes)
{
if(numBytes != 8)
return;
if(std::string((char*)buffer.c_array(), 6) != "Hello!")
return;
failed = false;
}
};
void UdpClient::send(uint8_t handler, std::string message)
{ <-------------------------------------------------------------------------------------- Canary at this point fails
ClientSendContext context(*this);
ClientConnection::send(context, handler, message);
} <-------------------------------------------------------------------------------------- Canary at this point fails
void send(SendContext & sendContext, uint8_t handler, std::string & message)
{
uint8_t *array = new uint8_t[message.size() + 2];
memcpy(array, message.c_str(), message.size());
boost::asio::mutable_buffer buffer(array, message.size() + 2);
prepareMessage(handler, buffer);
sendContext.send(buffer);
delete[] array;
}
size_t prepareMessage(uint8_t handler, boost::asio::mutable_buffer message)
{
size_t messageLength = boost::asio::buffer_size(message);
uint8_t* data = boost::asio::buffer_cast<uint8_t*>(message);
data[messageLength - 1] = network::handler;
data[messageLength - 2] = handler;
return messageLength;
}
And the error message:
*** stack smashing detected ***: ./testclient terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x37)[0x58e9537]
/lib/libc.so.6(__fortify_fail+0x0)[0x58e9500]
./testclient(_ZN4voip7network6client9UdpClient4sendEhSs+0x85)[0x46b449]
./testclient(_ZN4voip4test6client18SuiteTestUdpClient6doTestERb+0x2dd)[0x44c7c1]
./testclient(_ZNK4voip4test6client18SuiteTestUdpClient17TestClientCanSend7RunImplEv+0x2f)[0x44c957]
./testclient(_ZN8UnitTest11ExecuteTestINS_4TestEEEvRT_RKNS_11TestDetailsE+0x9a)[0x469551]
./testclient(_ZN8UnitTest4Test3RunEv+0x23)[0x46920f]
./testclient(_ZNK8UnitTest10TestRunner7RunTestEPNS_11TestResultsEPNS_4TestEi+0x7c)[0x469b74]
./testclient(_ZNK8UnitTest10TestRunner10RunTestsIfINS_4TrueEEEiRKNS_8TestListEPKcRKT_i+0x8f)[0x469ddb]
./testclient(_ZN8UnitTest11RunAllTestsEv+0x53)[0x4697b7]
./testclient(main+0x9)[0x44ca62]
/lib/libc.so.6(__libc_start_main+0xfe)[0x5808d8e]
./testclient[0x44c429]
======= Memory map: ========
00400000-00494000 r-xp 00000000 08:05 150971 /home/max/Documents/c++proj/voip/build/testclient
00693000-00694000 r--p 00093000 08:05 150971 /home/max/Documents/c++proj/voip/build/testclient
00694000-00695000 rw-p 00094000 08:05 150971 /home/max/Documents/c++proj/voip/build/testclient
00695000-00696000 rw-p 00000000 00:00 0
04000000-04020000 r-xp 00000000 08:05 560792 /lib/ld-2.12.1.so
04020000-04022000 rw-p 00000000 00:00 0
0403f000-04045000 rw-p 00000000 00:00 0
04220000-04221000 r--p 00020000 08:05 560792 /lib/ld-2.12.1.so
04221000-04222000 rw-p 00021000 08:05 560792 /lib/ld-2.12.1.so
04222000-04223000 rw-p 00000000 00:00 0
04223000-04224000 rwxp 00000000 00:00 0
04a23000-04a24000 r-xp 00000000 08:05 145700 /usr/lib/valgrind/vgpreload_core-amd64-linux.so
04a24000-04c23000 ---p 00001000 08:05 145700 /usr/lib/valgrind/vgpreload_core-amd64-linux.so
04c23000-04c24000 r--p 00000000 08:05 145700 /usr/lib/valgrind/vgpreload_core-amd64-linux.so
04c24000-04c25000 rw-p 00001000 08:05 145700 /usr/lib/valgrind/vgpreload_core-amd64-linux.so
04c25000-04c2d000 r-xp 00000000 08:05 145715 /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
04c2d000-04e2c000 ---p 00008000 08:05 145715 /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
04e2c000-04e2d000 r--p 00007000 08:05 145715 /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
04e2d000-04e2e000 rw-p 00008000 08:05 145715 /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
04e2e000-04e46000 r-xp 00000000 08:05 557639 /lib/libpthread-2.12.1.so
04e46000-05045000 ---p 00018000 08:05 557639 /lib/libpthread-2.12.1.so
05045000-05046000 r--p 00017000 08:05 557639 /lib/libpthread-2.12.1.so
05046000-05047000 rw-p 00018000 08:05 557639 /lib/libpthread-2.12.1.so
05047000-0504b000 rw-p 00000000 00:00 0
0504b000-05133000 r-xp 00000000 08:05 656172 /usr/lib/libstdc++.so.6.0.14
05133000-05332000 ---p 000e8000 08:05 656172 /usr/lib/libstdc++.so.6.0.14
05332000-0533a000 r--p 000e7000 08:05 656172 /usr/lib/libstdc++.so.6.0.14
0533a000-0533c000 rw-p 000ef000 08:05 656172 /usr/lib/libstdc++.so.6.0.14
0533c000-05351000 rw-p 00000000 00:00 0
05351000-053d3000 r-xp 00000000 08:05 560787 /lib/libm-2.12.1.so
053d3000-055d2000 ---p 00082000 08:05 560787 /lib/libm-2.12.1.so
055d2000-055d3000 r--p 00081000 08:05 560787 /lib/libm-2.12.1.so
055d3000-055d4000 rw-p 00082000 08:05 560787 /lib/libm-2.12.1.so
055d4000-055e9000 r-xp 00000000 08:05 521495 /lib/libgcc_s.so.1
055e9000-057e8000 ---p 00015000 08:05 521495 /lib/libgcc_s.so.1
057e8000-057e9000 r--p 00014000 08:05 521495 /lib/libgcc_s.so.1
057e9000-057ea000 rw-p 00015000 08:05 521495 /lib/libgcc_s.so.1
057ea000-05964000 r-xp 00000000 08:05 557476 /lib/libc-2.12.1.so
05964000-05b63000 ---p 0017a000 08:05 557476 /lib/libc-2.12.1.so
05b63000-05b67000 r--p 00179000 08:05 557476 /lib/libc-2.12.1.so
05b67000-05b68000 rw-p 0017d000 08:05 557476 /lib/libc-2.12.1.so
05b68000-05b6d000 rw-p 00000000 00:00 0
05b6d000-05f6d000 rwxp 00000000 00:00 0
05f6d000-05f6e000 ---p 00000000 00:00 0
05f6e000-0676e000 rw-p 00000000 00:00 0
0676e000-0676f000 ---p 00000000 00:00 0
0676f000-06f6f000 rw-p 00000000 00:00 0
06f6f000-06f70000 ---p 00000000 00:00 0
06f70000-07770000 rw-p 00000000 00:00 0
07770000-07771000 ---p 00000000 00:00 0
07771000-07f71000 rw-p 00000000 00:00 0
38000000-381fc000 r-xp 00200000 08:05 145710 /usr/lib/valgrind/memcheck-amd64-linux
383fb000-383fe000 rw-p 003fb000 08:05 145710 /usr/lib/valgrind/memcheck-amd64-linux
383fe000-3927e000 rw-p 00000000 00:00 0
402001000-403272000 rwxp 00000000 00:00 0
403272000-403274000 ---p 00000000 00:00 0
403274000-403374000 rwxp 00000000 00:00 0
403374000-403376000 ---p 00000000 00:00 0
403376000-40583e000 rwxp 00000000 00:00 0
40583e000-405840000 ---p 00000000 00:00 0
405840000-405940000 rwxp 00000000 00:00 0
405940000-405942000 ---p 00000000 00:00 0
405942000-405946000 rwxp 00000000 00:00 0
405946000-405948000 ---p 00000000 00:00 0
405948000-405a48000 rwxp 00000000 00:00 0
405a48000-405a4a000 ---p 00000000 00:00 0
405a4a000-405a4e000 rwxp 00000000 00:00 0
405a4e000-405a50000 ---p 00000000 00:00 0
405a50000-405b50000 rwxp 00000000 00:00 0
405b50000-405b52000 ---p 00000000 00:00 0
405b52000-405b5a000 rwxp 00000000 00:00 0
405b5a000-405b5c000 ---p 00000000 00:00 0
405b5c000-405c5c000 rwxp 00000000 00:00 0
405c5c000-405c5e000 ---p 00000000 00:00 0
405c5e000-405c62000 rwxp 00000000 00:00 0
7feffd000-7ff001000 rwxp 00000000 00:00 0
7fffb9f36000-7fffb9f57000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
this error is (almost always) caused by appending more elements to an array/vector than said array/vector has been declared as having. therefore i would pay specific attention to all char and uint8 arrays in your code.
though the dump might make sense for someone who understands linux c++ profoundly, it makes no sense for mere mortals and debugging using it is not the fastest solution.
i like the old school approach: print flags to show up to what point your program goes without exceptions. you can usually isolate the offending array(s) this way quite quickly.
as an example, i was having the exact same problem with this code:
std::string GetTimeStringFromDump(unsigned char *bufDumpIn, int startDate) {
unsigned char bufOut[6];
for (int counter02=0;counter02<12;counter02++) {
bufOut[counter02] = bufDumpIn[counter02+startDate];
}
std::string unixTimeOut = GetTimeStringNew(bufOut);
std::cout << "UnixTimeOUT: " << unixTimeOut << std::endl;
return unixTimeOut;
}
the weirdest thing was that the error did NOT occur when i assigned a string that had 12 characters to bufOut (declared as having 6 elements), but rather after
return unixTimeOut;
nevertheless, i changed the declaration to
unsigned char bufOut[12];
and the problem was solved.
Related
i have a simple question about pointers , why when i tried to delete a pointer that is pointing into a pointer (the small pointer is pointing into a new variable (new memory allocation )) i always receive a run-time error ?? (as shown below :)) )
#include <iostream>
using namespace std;
int main() {
int *a=new int;
*a=10;
int **aa=&a;
cout<<*a<<endl;
cout<<**aa<<endl;
delete aa;// when i comment this line the program work as well as expectied
return 0;
}
and how can i delete a pointer that is pointing into another pointer ??
i receive this error when i try to run the previous code
10
10
*** Error in `/home/abdullah/CLionProjects/tstt1/cmake-build-debug/tstt1': munmap_chunk(): invalid pointer: 0x00007ffef8e9dbb0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7fa3a9c5ebfb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76fc6)[0x7fa3a9c64fc6]
/home/abdullah/CLionProjects/tstt1/cmake-build-debug/tstt1(+0xa4e)[0x5590e44c0a4e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fa3a9c0e2e1]
/home/abdullah/CLionProjects/tstt1/cmake-build-debug/tstt1(+0x8ba)[0x5590e44c08ba]
======= Memory map: ========
5590e44c0000-5590e44c1000 r-xp 00000000 08:07 1836009 /home/abdullah/CLionProjects/tstt1/cmake-build-debug/tstt1
5590e46c0000-5590e46c1000 r--p 00000000 08:07 1836009 /home/abdullah/CLionProjects/tstt1/cmake-build-debug/tstt1
5590e46c1000-5590e46c2000 rw-p 00001000 08:07 1836009 /home/abdullah/CLionProjects/tstt1/cmake-build-debug/tstt1
5590e50f2000-5590e5124000 rw-p 00000000 00:00 0 [heap]
7fa3a9bee000-7fa3a9d83000 r-xp 00000000 08:07 2761474 /usr/lib/x86_64-linux-gnu/libc-2.24.so
7fa3a9d83000-7fa3a9f83000 ---p 00195000 08:07 2761474 /usr/lib/x86_64-linux-gnu/libc-2.24.so
7fa3a9f83000-7fa3a9f87000 r--p 00195000 08:07 2761474 /usr/lib/x86_64-linux-gnu/libc-2.24.so
7fa3a9f87000-7fa3a9f89000 rw-p 00199000 08:07 2761474 /usr/lib/x86_64-linux-gnu/libc-2.24.so
7fa3a9f89000-7fa3a9f8d000 rw-p 00000000 00:00 0
7fa3a9f8d000-7fa3a9fa3000 r-xp 00000000 08:07 2761798 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3a9fa3000-7fa3aa1a2000 ---p 00016000 08:07 2761798 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3aa1a2000-7fa3aa1a3000 r--p 00015000 08:07 2761798 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3aa1a3000-7fa3aa1a4000 rw-p 00016000 08:07 2761798 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7fa3aa1a4000-7fa3aa2a7000 r-xp 00000000 08:07 2762304 /usr/lib/x86_64-linux-gnu/libm-2.24.so
7fa3aa2a7000-7fa3aa4a6000 ---p 00103000 08:07 2762304 /usr/lib/x86_64-linux-gnu/libm-2.24.so
7fa3aa4a6000-7fa3aa4a7000 r--p 00102000 08:07 2762304 /usr/lib/x86_64-linux-gnu/libm-2.24.so
7fa3aa4a7000-7fa3aa4a8000 rw-p 00103000 08:07 2762304 /usr/lib/x86_64-linux-gnu/libm-2.24.so
7fa3aa4a8000-7fa3aa61a000 r-xp 00000000 08:07 2762793 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fa3aa61a000-7fa3aa81a000 ---p 00172000 08:07 2762793 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fa3aa81a000-7fa3aa824000 r--p 00172000 08:07 2762793 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fa3aa824000-7fa3aa826000 rw-p 0017c000 08:07 2762793 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fa3aa826000-7fa3aa82a000 rw-p 00000000 00:00 0
7fa3aa82a000-7fa3aa84d000 r-xp 00000000 08:07 2761022 /usr/lib/x86_64-linux-gnu/ld-2.24.so
7fa3aaa2e000-7fa3aaa32000 rw-p 00000000 00:00 0
7fa3aaa49000-7fa3aaa4d000 rw-p 00000000 00:00 0
7fa3aaa4d000-7fa3aaa4e000 r--p 00023000 08:07 2761022 /usr/lib/x86_64-linux-gnu/ld-2.24.so
7fa3aaa4e000-7fa3aaa4f000 rw-p 00024000 08:07 2761022 /usr/lib/x86_64-linux-gnu/ld-2.24.so
7fa3aaa4f000-7fa3aaa50000 rw-p 00000000 00:00 0
7ffef8e7e000-7ffef8e9f000 rw-p 00000000 00:00 0 [stack]
7ffef8ed9000-7ffef8edc000 r--p 00000000 00:00 0 [vvar]
7ffef8edc000-7ffef8ede000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
any ideas ? :(
aa is pointing to a which is a stack variable. You can only delete objects that were created using new.
Are you trying to delete the int that you created using new? In that case you would want to try delete *aa.
I need help in debugging the below code
server.cpp
void *task1(void *);
static int connFd;
static const char *hash_key;
int main(int argc, char **argv)
{
int server_fd, new_socket, valread;
struct sockaddr_in address,clntAdd;
int opt = 1;
int addrlen = sizeof(address);
int getopt_ret=0;
int long_index=0;
socklen_t len;
string message;
string salt;
int iteration_count=10;
pthread_t threadA[3];
hash_key=message.c_str();
if ((hash_key != NULL) && (hash_key[0] == '\0')) {
logger("key is empty\n");
return -1;
}
// Creating socket file descriptor
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
logger("socket failed");
exit(EXIT_FAILURE);
}
//fcntl(server_fd, F_SETFL, O_NONBLOCK);
bzero((char*) &address, sizeof(address));
// Forcefully attaching socket to the port 8080
//~ if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT,
//~ &opt, sizeof(opt)))
//~ {
//~ logger("setsockopt");
//~ exit(EXIT_FAILURE);
//~ }
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_addr.s_addr = inet_addr("192.168.2.184");
address.sin_port = htons( PORT );
// Forcefully attaching socket to the port 8080
if (bind(server_fd, (struct sockaddr *)&address,
sizeof(address))<0)
{
logger("bind failed");
exit(EXIT_FAILURE);
}
if (listen(server_fd, 3) < 0)
{
logger("listen");
exit(EXIT_FAILURE);
}
len = sizeof(clntAdd);
int noThread = 0;
while (true)
{
cout << "Listening" << endl;
//this is where client connects. svr will hang in this mode until client conn
connFd = accept(server_fd, (struct sockaddr *)&clntAdd, &len);
cout << connFd << endl;
if (connFd < 0)
{
cerr << "Cannot accept connection" << endl;
return 0;
}
else
{
cout << "Connection successful" << endl;
}
pthread_create(&threadA[noThread], NULL, task1, NULL);
noThread++;
}
for(int i = 0; i < 3; i++)
{
pthread_join(threadA[i], NULL);
}
}
void *task1 (void *dummyPt)
{
cout << "Thread No: " << pthread_self() << endl;
char test[1024];
bzero(test, 1024);
bool loop = false;
while(!loop)
{
bzero(test, 1024);
read(connFd, test, 1024);
string tester (test);
cout << tester << endl;
//send(connFd , hash_key , strlen(hash_key) , 0 );
write(connFd,hash_key,strlen(hash_key));
if(tester == "exit")
break;
}
cout << "\nClosing thread and conn" << endl;
close(connFd);
}
while i run the script it gives the following error.
*** Error in `./key_server': free(): invalid pointer: 0x00007f361a97b6e8 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x740ef)[0x7f361c1f30ef]
/lib64/libc.so.6(+0x79646)[0x7f361c1f8646]
/lib64/libc.so.6(+0x7a393)[0x7f361c1f9393]
/usr/lib64/libstdc++.so.6(_ZNSsD2Ev+0x3e)[0x7f361cb11b6e]
./key_server[0x402583]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f361c19f725]
./key_server[0x401dd9]
======= Memory map: ========
00400000-00408000 r-xp 00000000 08:02 261726 /home/b g/Encryption/key_server
00607000-00608000 r--p 00007000 08:02 261726 /home/b g/Encryption/key_server
00608000-00609000 rw-p 00008000 08:02 261726 /home/b g/Encryption/key_server
01b06000-01b38000 rw-p 00000000 00:00 0 [heap]
7f36007d9000-7f36007da000 ---p 00000000 00:00 0
7f36007da000-7f3600fda000 rw-p 00000000 00:00 0
7f3600fda000-7f3600fdb000 ---p 00000000 00:00 0
7f3600fdb000-7f36017db000 rw-p 00000000 00:00 0
7f36017db000-7f36017dc000 ---p 00000000 00:00 0
7f36017dc000-7f3601fdc000 rw-p 00000000 00:00 0
7f3601fdc000-7f3601fdd000 ---p 00000000 00:00 0
7f3601fdd000-7f36027dd000 rw-p 00000000 00:00 0
7f36027dd000-7f36027de000 ---p 00000000 00:00 0
7f36027de000-7f3602fde000 rw-p 00000000 00:00 0
7f3602fde000-7f3602fdf000 ---p 00000000 00:00 0
7f3602fdf000-7f36037df000 rw-p 00000000 00:00 0
7f36037df000-7f36037e0000 ---p 00000000 00:00 0
7f36037e0000-7f3603fe0000 rw-p 00000000 00:00 0
7f3603fe0000-7f3603fe1000 ---p 00000000 00:00 0
7f3603fe1000-7f36047e1000 rw-p 00000000 00:00 0
7f36047e1000-7f36047e2000 ---p 00000000 00:00 0
7f36047e2000-7f3604fe2000 rw-p 00000000 00:00 0
7f3604fe2000-7f3604fe3000 ---p 00000000 00:00 0
7f3604fe3000-7f36057e3000 rw-p 00000000 00:00 0
7f36057e3000-7f36057e4000 ---p 00000000 00:00 0
7f36057e4000-7f3605fe4000 rw-p 00000000 00:00 0
7f3605fe4000-7f3605fe5000 ---p 00000000 00:00 0
7f3605fe5000-7f36067e5000 rw-p 00000000 00:00 0
7f36067e5000-7f36067e6000 ---p 00000000 00:00 0
7f36067e6000-7f3606fe6000 rw-p 00000000 00:00 0
7f3606fe6000-7f3606fe7000 ---p 00000000 00:00 0
7f3606fe7000-7f36077e7000 rw-p 00000000 00:00 0
7f36077e7000-7f36077e8000 ---p 00000000 00:00 0
7f36077e8000-7f3607fe8000 rw-p 00000000 00:00 0
7f3607fe8000-7f3607fe9000 ---p 00000000 00:00 0
7f3607fe9000-7f36087e9000 rw-p 00000000 00:00 0
7f36087e9000-7f36087ea000 ---p 00000000 00:00 0
7f36087ea000-7f3608fea000 rw-p 00000000 00:00 0
7f3608fea000-7f3608feb000 ---p 00000000 00:00 0
7f3608feb000-7f36097eb000 rw-p 00000000 00:00 0
7f36097eb000-7f36097ec000 ---p 00000000 00:00 0
7f36097ec000-7f3609fec000 rw-p 00000000 00:00 0
7f3609fec000-7f3609fed000 ---p 00000000 00:00 0
7f3609fed000-7f360a7ed000 rw-p 00000000 00:00 0
7f360a7ed000-7f360a7ee000 ---p 00000000 00:00 0
7f360a7ee000-7f360afee000 rw-p 00000000 00:00 0
7f360afee000-7f360afef000 ---p 00000000 00:00 0
7f360afef000-7f360b7ef000 rw-p 00000000 00:00 0
7f360b7ef000-7f360b7f0000 ---p 00000000 00:00 0
7f360b7f0000-7f360bff0000 rw-p 00000000 00:00 0
7f360bff0000-7f360bff1000 ---p 00000000 00:00 0
7f360bff1000-7f360c7f1000 rw-p 00000000 00:00 0
7f360c7f1000-7f360c7f2000 ---p 00000000 00:00 0
7f360c7f2000-7f360cff2000 rw-p 00000000 00:00 0
7f360cff2000-7f360cff3000 ---p 00000000 00:00 0
7f360cff3000-7f360d7f3000 rw-p 00000000 00:00 0
7f360d7f3000-7f360d7f4000 ---p 00000000 00:00 0
7f360d7f4000-7f360dff4000 rw-p 00000000 00:00 0
7f360dff4000-7f360dff5000 ---p 00000000 00:00 0
7f360dff5000-7f360e7f5000 rw-p 00000000 00:00 0
7f360e7f5000-7f360e7f6000 ---p 00000000 00:00 0
7f360e7f6000-7f360eff6000 rw-p 00000000 00:00 0
7f360eff6000-7f360eff7000 ---p 00000000 00:00 0
7f360eff7000-7f360f7f7000 rw-p 00000000 00:00 0
7f360f7f7000-7f360f7f8000 ---p 00000000 00:00 0
7f360f7f8000-7f360fff8000 rw-p 00000000 00:00 0
7f360fff8000-7f360fff9000 ---p 00000000 00:00 0
7f360fff9000-7f36107f9000 rw-p 00000000 00:00 0
7f36107f9000-7f36107fa000 ---p 00000000 00:00 0
7f36107fa000-7f3610ffa000 rw-p 00000000 00:00 0
7f3610ffa000-7f3610ffb000 ---p 00000000 00:00 0
7f3610ffb000-7f36117fb000 rw-p 00000000 00:00 0
7f36117fb000-7f36117fc000 ---p 00000000 00:00 0
7f36117fc000-7f3611ffc000 rw-p 00000000 00:00 0
7f3611ffc000-7f3611ffd000 ---p 00000000 00:00 0
7f3611ffd000-7f36127fd000 rw-p 00000000 00:00 0
7f36127fd000-7f36127fe000 ---p 00000000 00:00 0
7f36127fe000-7f3612ffe000 rw-p 00000000 00:00 0
7f3612ffe000-7f3612fff000 ---p 00000000 00:00 0
7f3612fff000-7f36137ff000 rw-p 00000000 00:00 0
7f36137ff000-7f3613800000 ---p 00000000 00:00 0
7f3613800000-7f3614000000 rw-p 00000000 00:00 0
7f3614000000-7f3614021000 rw-p 00000000 00:00 0
7f3614021000-7f3618000000 ---p 00000000 00:00 0
7f3618177000-7f3618178000 ---p 00000000 00:00 0
7f3618178000-7f3618978000 rw-p 00000000 00:00 0
7f3618978000-7f3618979000 ---p 00000000 00:00 0
7f3618979000-7f3619179000 rw-p 00000000 00:00 0
7f3619179000-7f361917a000 ---p 00000000 00:00 0
7f361917a000-7f361997a000 rw-p 00000000 00:00 0
7f361997a000-7f361997b000 ---p 00000000 00:00 0
7f361997b000-7f361a17b000 rw-p 00000000 00:00 0
7f361a17b000-7f361a17c000 ---p 00000000 00:00 0
7f361a17c000-7f361a97c000 rw-p 00000000 00:00 0
7f361a97c000-7f361a97d000 ---p 00000000 00:00 0
7f361a97d000-7f361b17d000 rw-p 00000000 00:00 0
7f361b17d000-7f361b17e000 ---p 00000000 00:00 0
7f361b17e000-7f361b97e000 rw-p 00000000 00:00 0
7f361b97e000-7f361b97f000 ---p 00000000 00:00 0
7f361b97f000-7f361c17f000 rw-p 00000000 00:00 0
7f361c17f000-7f361c31a000 r-xp 00000000 08:02 260631 /lib64/ libc-2.22.so
7f361c31a000-7f361c51a000 ---p 0019b000 08:02 260631 /lib64/ libc-2.22.so
7f361c51a000-7f361c51e000 r--p 0019b000 08:02 260631 /lib64/ libc-2.22.so
7f361c51e000-7f361c520000 rw-p 0019f000 08:02 260631 /lib64/ libc-2.22.so
7f361c520000-7f361c524000 rw-p 00000000 00:00 0
7f361c524000-7f361c53b000 r-xp 00000000 08:02 261723 /lib64/ libgcc_s.so.1
7f361c53b000-7f361c73a000 ---p 00017000 08:02 261723 /lib64/ libgcc_s.so.1
7f361c73a000-7f361c73b000 r--p 00016000 08:02 261723 /lib64/ libgcc_s.so.1
7f361c73b000-7f361c73c000 rw-p 00017000 08:02 261723 /lib64/ libgcc_s.so.1
7f361c73c000-7f361c837000 r-xp 00000000 08:02 260639 /lib64/ libm-2.22.so
7f361c837000-7f361ca37000 ---p 000fb000 08:02 260639 /lib64/ libm-2.22.so
7f361ca37000-7f361ca38000 r--p 000fb000 08:02 260639 /lib64/ libm-2.22.so
7f361ca38000-7f361ca39000 rw-p 000fc000 08:02 260639 /lib64/ libm-2.22.so
7f361ca39000-7f361cbb4000 r-xp 00000000 08:02 652006 /usr/li b64/libstdc++.so.6.0.25
7f361cbb4000-7f361cdb4000 ---p 0017b000 08:02 652006 /usr/li b64/libstdc++.so.6.0.25
7f361cdb4000-7f361cdbe000 r--p 0017b000 08:02 652006 /usr/li b64/libstdc++.so.6.0.25
7f361cdbe000-7f361cdc0000 rw-p 00185000 08:02 652006 /usr/li b64/libstdc++.so.6.0.25
7f361cdc0000-7f361cdc3000 rw-p 00000000 00:00 0
7f361cdc3000-7f361cddb000 r-xp 00000000 08:02 260659 /lib64/ libpthread-2.22.so
7f361cddb000-7f361cfda000 ---p 00018000 08:02 260659 /lib64/ libpthread-2.22.so
7f361cfda000-7f361cfdb000 r--p 00017000 08:02 260659 /lib64/ libpthread-2.22.so
7f361cfdb000-7f361cfdc000 rw-p 00018000 08:02 260659 /lib64/ libpthread-2.22.so
7f361cfdc000-7f361cfe0000 rw-p 00000000 00:00 0
7f361cfe0000-7f361d001000 r-xp 00000000 08:02 260609 /lib64/ ld-2.22.so
7f361d1ec000-7f361d1f2000 rw-p 00000000 00:00 0
7f361d200000-7f361d201000 rw-p 00000000 00:00 0
7f361d201000-7f361d202000 r--p 00021000 08:02 260609 /lib64/ ld-2.22.so
7f361d202000-7f361d203000 rw-p 00022000 08:02 260609 /lib64/ ld-2.22.so
7f361d203000-7f361d204000 rw-p 00000000 00:00 0
7ffdd756f000-7ffdd7590000 rw-p 00000000 00:00 0 [stack]
7ffdd75bf000-7ffdd75c2000 r--p 00000000 00:00 0 [vvar]
7ffdd75c2000-7ffdd75c4000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsysca ll]
Aborted (core dumped)
This is usually one of two things: Your pointer is getting corrupted or you are freeing it twice.
Since you are using glibc I assume it's Linux. If not this probably still helps.
Install valgrind and run your program using
valgrind your-binary
Valgrind will track memory allocations and freeing and even if memory is initialized before use and give you a much better error. If that isn't enough to spot your bug there are many options to add more tests that you can read about in the manpage.
I want to keep an array of data index by a string and I thought I'd best use std::map for this purpose. I have below example code:
typedef struct MyType_s {
long long timestamp;
int cnt;
bool parked;
}MyType;
static MyType *list = {0};
static int listcnt = 0;
//-------------------------------------------------------------------------------------------------
int map_add_item(std::map<std::string, MyType*> *pmap, std::string str, long long tmestmp)
{
if (listcnt == 0){
list =(MyType*)malloc(sizeof(MyType));
if (list)
listcnt++;
else
return ENOMEM;
}
if (realloc(list,sizeof(MyType)*(++listcnt))==0)
return ENOMEM;
list->timestamp = tmestmp;
if (!(str.length()&&tmestmp&&pmap))
return EINVAL*-1;
if (pmap->insert(std::make_pair(str, &list[listcnt-1])).second == false){
pmap->find(str)->second->timestamp = tmestmp;
return EEXIST*-1;
}
return OK;
}
which compiles fine but I get a mem dump like this when I run it:
*** Error in `./std_map': double free or corruption (fasttop): 0x000000000226ec20 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f19fb6267e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f19fb62f37a]
/lib/x86_64-linux-gnu/libc.so.6(+0x83350)[0x7f19fb632350]
/lib/x86_64-linux-gnu/libc.so.6(realloc+0x179)[0x7f19fb633839]
./std_map[0x4013c8]
./std_map[0x40198d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f19fb5cf830]
./std_map[0x401259]
======= Memory map: ========
00400000-00404000 r-xp 00000000 08:02 6054199 /path/to/src/tmp/std_map
00604000-00605000 r--p 00004000 08:02 6054199 /path/to/src/tmp/std_map
00605000-00606000 rw-p 00005000 08:02 6054199 /path/to/src/tmp/std_map
0225d000-0228f000 rw-p 00000000 00:00 0 [heap]
7f19f4000000-7f19f4021000 rw-p 00000000 00:00 0
7f19f4021000-7f19f8000000 ---p 00000000 00:00 0
7f19fb2a6000-7f19fb3ae000 r-xp 00000000 08:02 28971840 /lib/x86_64-linux-gnu/libm-2.23.so
7f19fb3ae000-7f19fb5ad000 ---p 00108000 08:02 28971840 /lib/x86_64-linux-gnu/libm-2.23.so
7f19fb5ad000-7f19fb5ae000 r--p 00107000 08:02 28971840 /lib/x86_64-linux-gnu/libm-2.23.so
7f19fb5ae000-7f19fb5af000 rw-p 00108000 08:02 28971840 /lib/x86_64-linux-gnu/libm-2.23.so
7f19fb5af000-7f19fb76f000 r-xp 00000000 08:02 28971844 /lib/x86_64-linux-gnu/libc-2.23.so
7f19fb76f000-7f19fb96f000 ---p 001c0000 08:02 28971844 /lib/x86_64-linux-gnu/libc-2.23.so
7f19fb96f000-7f19fb973000 r--p 001c0000 08:02 28971844 /lib/x86_64-linux-gnu/libc-2.23.so
7f19fb973000-7f19fb975000 rw-p 001c4000 08:02 28971844 /lib/x86_64-linux-gnu/libc-2.23.so
7f19fb975000-7f19fb979000 rw-p 00000000 00:00 0
7f19fb979000-7f19fb98f000 r-xp 00000000 08:02 28971397 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f19fb98f000-7f19fbb8e000 ---p 00016000 08:02 28971397 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f19fbb8e000-7f19fbb8f000 rw-p 00015000 08:02 28971397 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f19fbb8f000-7f19fbd01000 r-xp 00000000 08:02 23072621 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f19fbd01000-7f19fbf01000 ---p 00172000 08:02 23072621 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f19fbf01000-7f19fbf0b000 r--p 00172000 08:02 23072621 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f19fbf0b000-7f19fbf0d000 rw-p 0017c000 08:02 23072621 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f19fbf0d000-7f19fbf11000 rw-p 00000000 00:00 0
7f19fbf11000-7f19fbf37000 r-xp 00000000 08:02 28971842 /lib/x86_64-linux-gnu/ld-2.23.so
7f19fc0fc000-7f19fc102000 rw-p 00000000 00:00 0
7f19fc135000-7f19fc136000 rw-p 00000000 00:00 0
7f19fc136000-7f19fc137000 r--p 00025000 08:02 28971842 /lib/x86_64-linux-gnu/ld-2.23.so
7f19fc137000-7f19fc138000 rw-p 00026000 08:02 28971842 /lib/x86_64-linux-gnu/ld-2.23.so
7f19fc138000-7f19fc139000 rw-p 00000000 00:00 0
7ffd68bf4000-7ffd68c16000 rw-p 00000000 00:00 0 [stack]
7ffd68d88000-7ffd68d8b000 r--p 00000000 00:00 0 [vvar]
7ffd68d8b000-7ffd68d8d000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Command terminated
gdb doesn't give me much more information too.
This is after I call the function like this from main():
int main()
{
int ret = 0;
std::map<std::string, MyType*> mapOfWords;
std::cout << map_add_item(&mapOfWords,"earth",time(NULL)+1) << std::endl;
return 0;
}
I'm wondering what I'm doing wrong, double free or corruption obviously is a hint but I'm not sure how to interpret this and I can't pinpoint the problem....
For a working solution, I replaced the global static variable and the pointers in the map with data that is located directly in the map. Plus I removed the typedef from the struct and declared it the C++ way instead, as in:
std::map<std::string, MyType> *pmap
struct MyType {
long long timestamp;
int cnt;
bool parked;
};
I am trying to study the effect of pthread based Multi-threading code modifications on VIRTUAL memory on a 64-bit Centos based Linux system
I am attaching a spreadsheet where the observations were made on VIRTUAL MEMORY (using Linux based top command) with increasing the number of threads and each thread is allocating 1MB each.
I am pasting C++ code used for observation (below) for the reference:
From the observations made shown in the table below, for a single thread allocating 1MB data VIRTUAL memory used is 89.824MB, for 2 threads allocating 1MB each VIRTUAL memory is 165.604MB, for 3 threads allocating 1MB each VIRTUAL memory is 235MB and then onwards VIRTUAL memory increases by 1MB per thread.
Click here to view the table having observations made
To summarize, VIRTUAL memory starts with 89MB, becomes double after adding 2nd thread, again becomes almost double after adding 3rd thread, then increases by 1MB for addition of each thread, each allocating 1MB of heap.
Can anyone explain why is this behavior exhibited by the system ?
Please post if you need any other details. Looking forward for the help.
Note:
the code was compiled using g++ (g++ -o vma CODE_FILE.cpp -lpthread)
only 1MB of heap was allocated by each thread but were not populated
the generated binary size is only ~9KB (got using ls command)
#include <iostream>
#include <pthread.h>
using namespace std;
/*
NOTE: Make sure you provide NUM_THREADS in the range (1..5)
*/
#define NUM_THREADS 5
struct thread_struct
{
int id;
char *msg;
};
void *thrdFunc(void *i)
{
char *it = (char*)i;
cout << "\nthis is thread named :"<< it ;
char *mallocBlk = new char [1000000];
}
int main()
{
int rc = 0;
void *status;
char threadNames[8][8] = { "Thread1" , "Thread2", "Thread3", "Thread4", "Thread5", "Thread6", "Thread7", "Thread8"};
pthread_t threads[NUM_THREADS];
thread_struct thrStructs[NUM_THREADS];
cout << "\nIn Main, creating threads!" ;
/*
Create threads
*/
for (int i = 0; i < NUM_THREADS; i++)
{
rc = pthread_create(&threads[i], NULL, thrdFunc, &threadNames[i] );
if (rc)
{
cout << "Thrd" << i+1 << " cant be created";
}
}
/*
Wait till all the threads complete
*/
for (int i = 0; i < NUM_THREADS; i++)
{
pthread_join(threads[i], &status);
}
cout << endl;
cout << "Done! Waiting for your input!";
cin.get();
return 0;
}
Below is the memory map for 5 threads:
[rebaca#localhost stackoverflow]$ cat /proc/31528/maps
00400000-00401000 r-xp 00000000 fd:02 20451094 /home/rebaca/stackoverflow/vma
00601000-00602000 rw-p 00001000 fd:02 20451094 /home/rebaca/stackoverflow/vma
01784000-017a5000 rw-p 00000000 00:00 0 [heap]
305b400000-305b420000 r-xp 00000000 fd:00 1703944 /lib64/ld-2.12.so
305b61f000-305b620000 r--p 0001f000 fd:00 1703944 /lib64/ld-2.12.so
305b620000-305b621000 rw-p 00020000 fd:00 1703944 /lib64/ld-2.12.so
305b621000-305b622000 rw-p 00000000 00:00 0
305b800000-305b98a000 r-xp 00000000 fd:00 1703966 /lib64/libc-2.12.so
305b98a000-305bb8a000 ---p 0018a000 fd:00 1703966 /lib64/libc-2.12.so
305bb8a000-305bb8e000 r--p 0018a000 fd:00 1703966 /lib64/libc-2.12.so
305bb8e000-305bb90000 rw-p 0018e000 fd:00 1703966 /lib64/libc-2.12.so
305bb90000-305bb94000 rw-p 00000000 00:00 0
305bc00000-305bc17000 r-xp 00000000 fd:00 1703968 /lib64/libpthread-2.12.so
305bc17000-305be17000 ---p 00017000 fd:00 1703968 /lib64/libpthread-2.12.so
305be17000-305be18000 r--p 00017000 fd:00 1703968 /lib64/libpthread-2.12.so
305be18000-305be19000 rw-p 00018000 fd:00 1703968 /lib64/libpthread-2.12.so
305be19000-305be1d000 rw-p 00000000 00:00 0
305c800000-305c883000 r-xp 00000000 fd:00 1704110 /lib64/libm-2.12.so
305c883000-305ca82000 ---p 00083000 fd:00 1704110 /lib64/libm-2.12.so
305ca82000-305ca83000 r--p 00082000 fd:00 1704110 /lib64/libm-2.12.so
305ca83000-305ca84000 rw-p 00083000 fd:00 1704110 /lib64/libm-2.12.so
3066800000-3066816000 r-xp 00000000 fd:00 1704139 /lib64/libgcc_s-4.4.7-20120601.so.1
3066816000-3066a15000 ---p 00016000 fd:00 1704139 /lib64/libgcc_s-4.4.7-20120601.so.1
3066a15000-3066a16000 rw-p 00015000 fd:00 1704139 /lib64/libgcc_s-4.4.7-20120601.so.1
3066c00000-3066ce8000 r-xp 00000000 fd:00 809560 /usr/lib64/libstdc++.so.6.0.13
3066ce8000-3066ee8000 ---p 000e8000 fd:00 809560 /usr/lib64/libstdc++.so.6.0.13
3066ee8000-3066eef000 r--p 000e8000 fd:00 809560 /usr/lib64/libstdc++.so.6.0.13
3066eef000-3066ef1000 rw-p 000ef000 fd:00 809560 /usr/lib64/libstdc++.so.6.0.13
3066ef1000-3066f06000 rw-p 00000000 00:00 0
7fd3ec000000-7fd3ec115000 rw-p 00000000 00:00 0
7fd3ec115000-7fd3f0000000 ---p 00000000 00:00 0
7fd3f0000000-7fd3f0115000 rw-p 00000000 00:00 0
7fd3f0115000-7fd3f4000000 ---p 00000000 00:00 0
7fd3f4000000-7fd3f4115000 rw-p 00000000 00:00 0
7fd3f4115000-7fd3f8000000 ---p 00000000 00:00 0
7fd3f8000000-7fd3f8115000 rw-p 00000000 00:00 0
7fd3f8115000-7fd3fc000000 ---p 00000000 00:00 0
7fd3fc000000-7fd3fc115000 rw-p 00000000 00:00 0
7fd3fc115000-7fd400000000 ---p 00000000 00:00 0
7fd4032b6000-7fd4032b7000 ---p 00000000 00:00 0
7fd4032b7000-7fd403cb7000 rw-p 00000000 00:00 0
7fd403cb7000-7fd403cb8000 ---p 00000000 00:00 0
7fd403cb8000-7fd4046b8000 rw-p 00000000 00:00 0
7fd4046b8000-7fd4046b9000 ---p 00000000 00:00 0
7fd4046b9000-7fd4050b9000 rw-p 00000000 00:00 0
7fd4064bb000-7fd4064c1000 rw-p 00000000 00:00 0
7fd4064db000-7fd4064de000 rw-p 00000000 00:00 0
7ffc72456000-7ffc7246b000 rw-p 00000000 00:00 0 [stack]
7ffc72568000-7ffc72569000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
I recently got this error. The weird thing is, that I am not always getting this error message...
*** glibc detected *** ./a.out: malloc(): memory corruption (fast): 0x0000000002134dc0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x76a16)[0x7fa62b164a16]
/lib/x86_64-linux-gnu/libc.so.6(+0x7a2f8)[0x7fa62b1682f8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x70)[0x7fa62b1698a0]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znwm+0x1d)[0x7fa62b97607d]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs4_Rep9_S_createEmmRKSaIcE+0x59)[0x7fa62b9d1999]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs4_Rep8_M_cloneERKSaIcEm+0x28)[0x7fa62b9d2708]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs7reserveEm+0x30)[0x7fa62b9d27f0]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSs6appendEPKcm+0xb5)[0x7fa62b9d2ab5]
./a.out[0x40758f]
./a.out[0x403279]
./a.out[0x405202]
./a.out[0x406332]
./a.out[0x406c90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7fa62b10cead]
./a.out[0x402189]
======= Memory map: ========
00400000-0040e000 r-xp 00000000 08:05 6166978 /root/tradingbot/bot2/a.out
0060d000-0060e000 rw-p 0000d000 08:05 6166978 /root/tradingbot/bot2/a.out
02132000-02153000 rw-p 00000000 00:00 0 [heap]
7fa624000000-7fa624021000 rw-p 00000000 00:00 0
7fa624021000-7fa628000000 ---p 00000000 00:00 0
7fa62b0ee000-7fa62b270000 r-xp 00000000 08:05 12715768 /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b270000-7fa62b470000 ---p 00182000 08:05 12715768 /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b470000-7fa62b474000 r--p 00182000 08:05 12715768 /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b474000-7fa62b475000 rw-p 00186000 08:05 12715768 /lib/x86_64-linux-gnu/libc-2.13.so
7fa62b475000-7fa62b47a000 rw-p 00000000 00:00 0
7fa62b47a000-7fa62b48f000 r-xp 00000000 08:05 12715492 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa62b48f000-7fa62b68f000 ---p 00015000 08:05 12715492 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa62b68f000-7fa62b690000 rw-p 00015000 08:05 12715492 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa62b690000-7fa62b711000 r-xp 00000000 08:05 12715766 /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b711000-7fa62b910000 ---p 00081000 08:05 12715766 /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b910000-7fa62b911000 r--p 00080000 08:05 12715766 /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b911000-7fa62b912000 rw-p 00081000 08:05 12715766 /lib/x86_64-linux-gnu/libm-2.13.so
7fa62b912000-7fa62b9fa000 r-xp 00000000 08:05 7345862 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62b9fa000-7fa62bbfa000 ---p 000e8000 08:05 7345862 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62bbfa000-7fa62bc02000 r--p 000e8000 08:05 7345862 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62bc02000-7fa62bc04000 rw-p 000f0000 08:05 7345862 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
7fa62bc04000-7fa62bc19000 rw-p 00000000 00:00 0
7fa62bc19000-7fa62bc39000 r-xp 00000000 08:05 12715773 /lib/x86_64-linux-gnu/ld-2.13.so
7fa62be10000-7fa62be15000 rw-p 00000000 00:00 0
7fa62be35000-7fa62be38000 rw-p 00000000 00:00 0
7fa62be38000-7fa62be39000 r--p 0001f000 08:05 12715773 /lib/x86_64-linux-gnu/ld-2.13.so
7fa62be39000-7fa62be3a000 rw-p 00020000 08:05 12715773 /lib/x86_64-linux-gnu/ld-2.13.so
7fa62be3a000-7fa62be3b000 rw-p 00000000 00:00 0
7fffb0149000-7fffb016a000 rw-p 00000000 00:00 0 [stack]
7fffb019f000-7fffb01a1000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted
Here is what I was doing...
I am creating n objects of a class dynamically and storing them in a vector (C++). Then with an iterator I access each object, and deference it to access the object's members. I am also reading some text files, so edited them by hand during runtime. I don't know which part of the code I should place here, but this is where it crashed exactly:
if( last_op_number == 1 ){
it = n_bots.end();// Grabs iterator and go to the end of the vector; This is where the last OP1 bot is located
bot *botop1 = &(*it); // Dereference iterator to have a pointer to that specific bot
/* 3) Set the real buy and sell prices */
botop1->real_bpsp(price_ex1,price_ex2);
}
// Clear text files
OKC->clear_pos();
OKC2->clear_pos();
updates_balance(); // Updates balances
green_light = 1; // Tell bot manager that we are good to go!
Any ideas of what's going on?
Thank you!
You should use n_bots.back() instead of n_bots.end().