I am having trouble deleting my pointers that I have created. The program creates a double pointer to point to the threads. Then it creates threads dynamically. At the end it deletes them but I am getting a glibc error. It uses boost to create the threads. What is really puzzling is that I delete a similar double pointer the same exact way and that executes fine. The issue is at the end of the code block under the heading of /*clean up*/:
boost :: thread** thrds;
//create threads and bind to p_variantforloop_t
thrds = new boost::thread*[numThreads];
for (int i = 1; i <= numThreads; i++)
thrds[i] = new boost::thread(boost::bind(&p_variantforloop_t,
E, A, D, (i*n-n)/i ,(i*n)/n, numThreads, n));
/* join threads */
for (int i = 0; i < numThreads; i++)
thrds[i]->join();
/* cleanup */
for (int i = 0; i < numThreads; i++)
delete thrds[i];
delete[] thrds;
the error is:
*** glibc detected *** ./hw9: munmap_chunk(): invalid pointer: 0x0957d480 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x264591]
/lib/tls/i686/cmov/libc.so.6(+0x6c80e)[0x26580e]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x529741]
./hw9[0x804a0d1]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x20fbd6]
./hw9[0x8049871]
======= Memory map: ========
001f9000-0034c000 r-xp 00000000 08:02 1128663 /lib/tls/i686/cmov/libc-2.11.1.so
0034c000-0034d000 ---p 00153000 08:02 1128663 /lib/tls/i686/cmov/libc-2.11.1.so
0034d000-0034f000 r--p 00153000 08:02 1128663 /lib/tls/i686/cmov/libc-2.11.1.so
0034f000-00350000 rw-p 00155000 08:02 1128663 /lib/tls/i686/cmov/libc-2.11.1.so
00350000-00353000 rw-p 00000000 00:00 0
0046e000-00557000 r-xp 00000000 08:02 982712 /usr/lib/libstdc++.so.6.0.13
00557000-00558000 ---p 000e9000 08:02 982712 /usr/lib/libstdc++.so.6.0.13
00558000-0055c000 r--p 000e9000 08:02 982712 /usr/lib/libstdc++.so.6.0.13
0055c000-0055d000 rw-p 000ed000 08:02 982712 /usr/lib/libstdc++.so.6.0.13
0055d000-00564000 rw-p 00000000 00:00 0
005ad000-005d1000 r-xp 00000000 08:02 1130719 /lib/tls/i686/cmov/libm-2.11.1.so
005d1000-005d2000 r--p 00023000 08:02 1130719 /lib/tls/i686/cmov/libm-2.11.1.so
005d2000-005d3000 rw-p 00024000 08:02 1130719 /lib/tls/i686/cmov/libm-2.11.1.so
00950000-00965000 r-xp 00000000 08:02 1130743 /lib/tls/i686/cmov/libpthread-2.11.1.so
00965000-00966000 r--p 00014000 08:02 1130743 /lib/tls/i686/cmov/libpthread-2.11.1.so
00966000-00967000 rw-p 00015000 08:02 1130743 /lib/tls/i686/cmov/libpthread-2.11.1.so
00967000-00969000 rw-p 00000000 00:00 0
00a67000-00a7a000 r-xp 00000000 08:02 176445 /usr/lib/libboost_thread.so.1.40.0
00a7a000-00a7b000 r--p 00013000 08:02 176445 /usr/lib/libboost_thread.so.1.40.0
00a7b000-00a7c000 rw-p 00014000 08:02 176445 /usr/lib/libboost_thread.so.1.40.0
00bc7000-00be2000 r-xp 00000000 08:02 1128318 /lib/ld-2.11.1.so
00be2000-00be3000 r--p 0001a000 08:02 1128318 /lib/ld-2.11.1.so
00be3000-00be4000 rw-p 0001b000 08:02 1128318 /lib/ld-2.11.1.so
00c34000-00c3b000 r-xp 00000000 08:02 1130745 /lib/tls/i686/cmov/librt-2.11.1.so
00c3b000-00c3c000 r--p 00006000 08:02 1130745 /lib/tls/i686/cmov/librt-2.11.1.so
00c3c000-00c3d000 rw-p 00007000 08:02 1130745 /lib/tls/i686/cmov/librt-2.11.1.so
00ccf000-00cd0000 r-xp 00000000 00:00 0 [vdso]
00e85000-00ea2000 r-xp 00000000 08:02 1128359 /lib/libgcc_s.so.1
00ea2000-00ea3000 r--p 0001c000 08:02 1128359 /lib/libgcc_s.so.1
00ea3000-00ea4000 rw-p 0001d000 08:02 1128359 /lib/libgcc_s.so.1
08048000-0804e000 r-xp 00000000 00:1d 10184 /home/tparisi/Desktop/source_code_hw5/hw9
0804e000-0804f000 r--p 00005000 00:1d 10184 /home/tparisi/Desktop/source_code_hw5/hw9
0804f000-08050000 rw-p 00006000 00:1d 10184 /home/tparisi/Desktop/source_code_hw5/hw9
0957d000-0959e000 rw-p 00000000 00:00 0 [heap]
b68bf000-b68c0000 ---p 00000000 00:00 0
b68c0000-b70c0000 rw-p 00000000 00:00 0
b70c0000-b70c1000 ---p 00000000 00:00 0
b70c1000-b78c4000 rw-p 00000000 00:00 0
b78e8000-b78eb000 rw-p 00000000 00:00 0
bfc07000-bfc1c000 rw-p 00000000 00:00 0 [stack]
Aborted
You omit first element of the array when creating thread object. It stays with uninitialized pointer value, causing the invalid pointer error later.
There is also an issue of writing to memory immediately after the last element of array, which you also do in the problematic loop (i.e. the first for in your code).
Related
I'm trying to execute a very basic C++ program that interacts with MySQL. I implemented the very beginning of the tutorial for MySQL Connector/C++, but I keep getting a segfault when I try to execute that code. Here is the code that I'm trying to execute:
try
{
sql::mysql::MySQL_Driver *driver = NULL;
sql::Connection *conn = NULL;
driver = sql::mysql::get_mysql_driver_instance();
if (driver != NULL)
{
conn = driver->connect("127.0.0.1:3306", "root", "root");
cout << "Test" << endl;
}
delete conn;
conn = NULL;
}
When I execute this code, "Test" gets printed, but I get the following error:
*** Error in `./test': free(): invalid pointer: 0x00007f0a9a292158 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f0a999a87e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f0a999b137a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f0a999b553c]
./test(_ZN3sql9SQLStringD1Ev+0x18)[0x401296]
/lib/x86_64-linux-gnu/libc.so.6(+0x39ff8)[0x7f0a9996aff8]
/lib/x86_64-linux-gnu/libc.so.6(+0x3a045)[0x7f0a9996b045]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf7)[0x7f0a99951837]
./test[0x400e79]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 6167619
/home/lichtsb1/local/src/ddsWork/mysqlTest/test
00601000-00602000 r--p 00001000 08:01 6167619
/home/lichtsb1/local/src/ddsWork/mysqlTest/test
00602000-00603000 rw-p 00002000 08:01 6167619
/home/lichtsb1/local/src/ddsWork/mysqlTest/test
02357000-023aa000 rw-p 00000000 00:00 0
[heap]
7f0a94000000-7f0a94021000 rw-p 00000000 00:00 0
7f0a94021000-7f0a98000000 ---p 00000000 00:00 0
7f0a989a8000-7f0a98ab0000 r-xp 00000000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98ab0000-7f0a98caf000 ---p 00108000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98caf000-7f0a98cb0000 r--p 00107000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98cb0000-7f0a98cb1000 rw-p 00108000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98cb1000-7f0a98cb4000 r-xp 00000000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98cb4000-7f0a98eb3000 ---p 00003000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98eb3000-7f0a98eb4000 r--p 00002000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98eb4000-7f0a98eb5000 rw-p 00003000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98eb5000-7f0a99074000 r-xp 00000000 08:01 7733609
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libcrypto.so.1.0.0
7f0a99074000-7f0a99273000 ---p 001bf000 08:01 7733609
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libcrypto.so.1.0.0
7f0a99273000-7f0a9929a000 rw-p 001be000 08:01 7733609
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libcrypto.so.1.0.0
7f0a9929a000-7f0a9929d000 rw-p 00000000 00:00 0
7f0a9929d000-7f0a99302000 r-xp 00000000 08:01 7733606
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libssl.so.1.0.0
7f0a99302000-7f0a99502000 ---p 00065000 08:01 7733606
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libssl.so.1.0.0
7f0a99502000-7f0a9950c000 rw-p 00065000 08:01 7733606
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libssl.so.1.0.0
7f0a9950c000-7f0a99513000 r-xp 00000000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99513000-7f0a99712000 ---p 00007000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99712000-7f0a99713000 r--p 00006000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99713000-7f0a99714000 rw-p 00007000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99714000-7f0a9972c000 r-xp 00000000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9972c000-7f0a9992b000 ---p 00018000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9992b000-7f0a9992c000 r--p 00017000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9992c000-7f0a9992d000 rw-p 00018000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9992d000-7f0a99931000 rw-p 00000000 00:00 0
7f0a99931000-7f0a99af1000 r-xp 00000000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99af1000-7f0a99cf1000 ---p 001c0000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99cf1000-7f0a99cf5000 r--p 001c0000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99cf5000-7f0a99cf7000 rw-p 001c4000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99cf7000-7f0a99cfb000 rw-p 00000000 00:00 0
7f0a99cfb000-7f0a99d11000 r-xp 00000000 08:01 43254905
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f0a99d11000-7f0a99f10000 ---p 00016000 08:01 43254905
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f0a99f10000-7f0a99f11000 rw-p 00015000 08:01 43254905
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f0a99f11000-7f0a9a083000 r-xp 00000000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a083000-7f0a9a283000 ---p 00172000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a283000-7f0a9a28d000 r--p 00172000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a28d000-7f0a9a28f000 rw-p 0017c000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a28f000-7f0a9a293000 rw-p 00000000 00:00 0
7f0a9a293000-7f0a9a6ed000 r-xp 00000000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9a6ed000-7f0a9a8ed000 ---p 0045a000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9a8ed000-7f0a9a8f8000 r--p 0045a000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9a8f8000-7f0a9aab7000 rw-p 00465000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9aab7000-7f0a9aabd000 rw-p 00000000 00:00 0
7f0a9aabd000-7f0a9aae3000 r-xp 00000000 08:01 43253979
/lib/x86_64-linux-gnu/ld-2.23.so
7f0a9ac7b000-7f0a9acb7000 r--s 00000000 08:01 16523805
/var/cache/nscd/services
7f0a9acb7000-7f0a9acbe000 rw-p 00000000 00:00 0
7f0a9ace0000-7f0a9ace2000 rw-p 00000000 00:00 0
7f0a9ace2000-7f0a9ace3000 r--p 00025000 08:01 43253979
/lib/x86_64-linux-gnu/ld-2.23.so
7f0a9ace3000-7f0a9ace4000 rw-p 00026000 08:01 43253979
/lib/x86_64-linux-gnu/ld-2.23.so
7f0a9ace4000-7f0a9ace5000 rw-p 00000000 00:00 0
7ffe3b05c000-7ffe3b07e000 rw-p 00000000 00:00 0
[stack]
7ffe3b0dd000-7ffe3b0e0000 r--p 00000000 00:00 0
[vvar]
7ffe3b0e0000-7ffe3b0e2000 r-xp 00000000 00:00 0
[vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
[vsyscall]
Aborted (core dumped)
This is so basic - what am I doing wrong?
Thank you very much for any help.
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 was working on aqua-sim that is based on ns2 for my ubuntu and i'm getting a buffer overflow error and i can't figure out how to trace this kind of error.
i tried to debug using gdb but with no luck as i don't know how to trace the error, can someone please let me know where should i look based on the following error segment:
num_nodes is set 10
INITIALIZE THE LIST xListHead
Starting Simulation...
GOD: the old file name istest.data
GOD: the new file name isunderwater.data
*** buffer overflow detected ***: ns terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f57d8e347e5]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f57d8ed611c]
/lib/x86_64-linux-gnu/libc.so.6(+0x117120)[0x7f57d8ed4120]
/lib/x86_64-linux-gnu/libc.so.6(+0x116689)[0x7f57d8ed3689]
/lib/x86_64-linux-gnu/libc.so.6(_IO_default_xsputn+0x80)[0x7f57d8e386b0]
/lib/x86_64-linux-gnu/libc.so.6(_IO_vfprintf+0xc90)[0x7f57d8e0ae00]
/lib/x86_64-linux-gnu/libc.so.6(__vsprintf_chk+0x84)[0x7f57d8ed3714]
/lib/x86_64-linux-gnu/libc.so.6(__sprintf_chk+0x7d)[0x7f57d8ed366d]
ns[0x57ea03]
ns[0x57eb44]
ns[0x415367]
ns[0x4162e6]
ns[0x416d8c]
ns[0x5b3894]
ns[0x5b85d5]
ns[0x5bdf12]
ns[0x5c0372]
ns[0x5e7de9]
ns[0x5ec6c0]
ns[0x5e7e99]
ns[0x5ec6c0]
ns[0x613615]
ns[0x613803]
ns[0x5b8705]
ns[0x5bdf12]
ns[0x5c0372]
ns[0x5e7de9]
ns[0x5ec6c0]
ns[0x613615]
ns[0x613803]
ns[0x5b85d5]
ns[0x5bdf12]
ns[0x5c0372]
ns[0x5c1c37]
ns[0x603321]
ns[0x606936]
ns[0x405abe]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f57d8ddd830]
ns[0x410f59]
======= Memory map: ========
00400000-00766000 r-xp 00000000 08:06 2491295 /home/me/Aqua-Sim/Aqua-Sim-1.0/ns-2.30/ns
00965000-00967000 r--p 00365000 08:06 2491295 /home/me/Aqua-Sim/Aqua-Sim-1.0/ns-2.30/ns
00967000-009f2000 rw-p 00367000 08:06 2491295 /home/me/Aqua-Sim/Aqua-Sim-1.0/ns-2.30/ns
009f2000-00a00000 rw-p 00000000 00:00 0
00c2e000-01085000 rw-p 00000000 00:00 0 [heap]
7f57d8ad0000-7f57d8dbd000 r--p 00000000 08:06 2627421 /usr/lib/locale/locale-archive
7f57d8dbd000-7f57d8f7d000 r-xp 00000000 08:06 1179887 /lib/x86_64-linux-gnu/libc-2.23.so
7f57d8f7d000-7f57d917d000 ---p 001c0000 08:06 1179887 /lib/x86_64-linux-gnu/libc-2.23.so
7f57d917d000-7f57d9181000 r--p 001c0000 08:06 1179887 /lib/x86_64-linux-gnu/libc-2.23.so
7f57d9181000-7f57d9183000 rw-p 001c4000 08:06 1179887 /lib/x86_64-linux-gnu/libc-2.23.so
7f57d9183000-7f57d9187000 rw-p 00000000 00:00 0
7f57d9187000-7f57d919d000 r-xp 00000000 08:06 1184430 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f57d919d000-7f57d939c000 ---p 00016000 08:06 1184430 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f57d939c000-7f57d939d000 rw-p 00015000 08:06 1184430 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f57d939d000-7f57d9517000 r-xp 00000000 08:06 2621627 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24
7f57d9517000-7f57d9716000 ---p 0017a000 08:06 2621627 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24
7f57d9716000-7f57d9720000 r--p 00179000 08:06 2621627 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24
7f57d9720000-7f57d9722000 rw-p 00183000 08:06 2621627 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.24
7f57d9722000-7f57d9725000 rw-p 00000000 00:00 0
7f57d9725000-7f57d982d000 r-xp 00000000 08:06 1179880 /lib/x86_64-linux-gnu/libm-2.23.so
7f57d982d000-7f57d9a2c000 ---p 00108000 08:06 1179880 /lib/x86_64-linux-gnu/libm-2.23.so
7f57d9a2c000-7f57d9a2d000 r--p 00107000 08:06 1179880 /lib/x86_64-linux-gnu/libm-2.23.so
7f57d9a2d000-7f57d9a2e000 rw-p 00108000 08:06 1179880 /lib/x86_64-linux-gnu/libm-2.23.so
7f57d9a2e000-7f57d9a31000 r-xp 00000000 08:06 1179868 /lib/x86_64-linux-gnu/libdl-2.23.so
7f57d9a31000-7f57d9c30000 ---p 00003000 08:06 1179868 /lib/x86_64-linux-gnu/libdl-2.23.so
7f57d9c30000-7f57d9c31000 r--p 00002000 08:06 1179868 /lib/x86_64-linux-gnu/libdl-2.23.so
7f57d9c31000-7f57d9c32000 rw-p 00003000 08:06 1179868 /lib/x86_64-linux-gnu/libdl-2.23.so
7f57d9c32000-7f57d9c58000 r-xp 00000000 08:06 1179846 /lib/x86_64-linux-gnu/ld-2.23.so
7f57d9e37000-7f57d9e3d000 rw-p 00000000 00:00 0
7f57d9e54000-7f57d9e57000 rw-p 00000000 00:00 0
7f57d9e57000-7f57d9e58000 r--p 00025000 08:06 1179846 /lib/x86_64-linux-gnu/ld-2.23.so
7f57d9e58000-7f57d9e59000 rw-p 00026000 08:06 1179846 /lib/x86_64-linux-gnu/ld-2.23.so
7f57d9e59000-7f57d9e5a000 rw-p 00000000 00:00 0
7ffeddbfa000-7ffeddc1c000 rw-p 00000000 00:00 0 [stack]
7ffeddc4b000-7ffeddc4d000 r--p 00000000 00:00 0 [vvar]
7ffeddc4d000-7ffeddc4f000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)
my gcc is 4.9,on ns-2.30, and ubuntu 16.04
I am having this segmentation fault after a colleague of mine committed some new features on our project. The new feature has no impact on the following function, but only increases the QString argument size.
After some debugging, I've figured out that segmentation fault was happening after the following function return.
I need to know why does it is happening and why my workaround worked, and if the workaround is safe?
I must say that the following snippet it is working on older version of Qt (5.3.1 with gcc 4.8) that I have now installed (Qt 5.9 with gcc 7.0).
It also works nicely on Debug rather that Release compiling mode on Qt.
Finally, I don't want to discuss the effectiveness of this encryption method, but the entitled problem.
The crashes happens immediately after function returning, I have no idea why.
QString Utility::encrypt(QString text)
{
QByteArray textUtf8 = text.toUtf8();
// Convert QString to Char
const char *srcString = textUtf8.constData();
char encrypted[ textUtf8.size() ];
// Copy Char by Char
strcpy(encrypted,srcString);
for(int u=0; u<textUtf8.size(); u++ ){
encrypted[u]++;
}
return QString::fromUtf8(encrypted);
}
The output from Segmentation fault is:
*** Error in `/home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree': free(): invalid pointer: 0x0000000001cfc800 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7eff199067e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7eff1990f37a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7eff1991353c]
/home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree[0x40171f]
/home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree[0x401344]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7eff198af830]
/home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree[0x4014b9]
======= Memory map: ========
00400000-00403000 r-xp 00000000 08:01 2098854 /home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree
00602000-00603000 r--p 00002000 08:01 2098854 /home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree
00603000-00604000 rw-p 00003000 08:01 2098854 /home/user/workspace/build-swFree-Desktop_Qt_5_9_1_GCC_64bit-Release/swFree
01cdd000-01d1f000 rw-p 00000000 00:00 0 [heap]
7eff10000000-7eff10021000 rw-p 00000000 00:00 0
7eff10021000-7eff14000000 ---p 00000000 00:00 0
7eff162bb000-7eff16594000 r--p 00000000 08:01 2752945 /usr/lib/locale/locale-archive
7eff16594000-7eff16602000 r-xp 00000000 08:01 529479 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
7eff16602000-7eff16802000 ---p 0006e000 08:01 529479 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
7eff16802000-7eff16803000 r--p 0006e000 08:01 529479 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
7eff16803000-7eff16804000 rw-p 0006f000 08:01 529479 /lib/x86_64-linux-gnu/libpcre.so.3.13.2
7eff16804000-7eff1690c000 r-xp 00000000 08:01 529373 /lib/x86_64-linux-gnu/libm-2.23.so
7eff1690c000-7eff16b0b000 ---p 00108000 08:01 529373 /lib/x86_64-linux-gnu/libm-2.23.so
7eff16b0b000-7eff16b0c000 r--p 00107000 08:01 529373 /lib/x86_64-linux-gnu/libm-2.23.so
7eff16b0c000-7eff16b0d000 rw-p 00108000 08:01 529373 /lib/x86_64-linux-gnu/libm-2.23.so
7eff16b0d000-7eff16c1c000 r-xp 00000000 08:01 529394 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2
7eff16c1c000-7eff16e1b000 ---p 0010f000 08:01 529394 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2
7eff16e1b000-7eff16e1c000 r--p 0010e000 08:01 529394 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2
7eff16e1c000-7eff16e1d000 rw-p 0010f000 08:01 529394 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2
7eff16e1d000-7eff16e1e000 rw-p 00000000 00:00 0
7eff16e1e000-7eff16e1f000 r-xp 00000000 08:01 2763515 /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0.4800.2
7eff16e1f000-7eff1701e000 ---p 00001000 08:01 2763515 /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0.4800.2
7eff1701e000-7eff1701f000 r--p 00000000 08:01 2763515 /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0.4800.2
7eff1701f000-7eff17020000 rw-p 00001000 08:01 2763515 /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0.4800.2
7eff17020000-7eff17023000 r-xp 00000000 08:01 529264 /lib/x86_64-linux-gnu/libdl-2.23.so
7eff17023000-7eff17222000 ---p 00003000 08:01 529264 /lib/x86_64-linux-gnu/libdl-2.23.so
7eff17222000-7eff17223000 r--p 00002000 08:01 529264 /lib/x86_64-linux-gnu/libdl-2.23.so
7eff17223000-7eff17224000 rw-p 00003000 08:01 529264 /lib/x86_64-linux-gnu/libdl-2.23.so
7eff17224000-7eff1723d000 r-xp 00000000 08:01 529327 /lib/x86_64-linux-gnu/libz.so.1.2.8
7eff1723d000-7eff1743c000 ---p 00019000 08:01 529327 /lib/x86_64-linux-gnu/libz.so.1.2.8
7eff1743c000-7eff1743d000 r--p 00018000 08:01 529327 /lib/x86_64-linux-gnu/libz.so.1.2.8
7eff1743d000-7eff1743e000 rw-p 00019000 08:01 529327 /lib/x86_64-linux-gnu/libz.so.1.2.8
7eff1743e000-7eff18c21000 r--p 00000000 08:01 2379568 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicudata.so.56.1
7eff18c21000-7eff18e20000 ---p 017e3000 08:01 2379568 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicudata.so.56.1
7eff18e20000-7eff18e21000 r--p 017e2000 08:01 2379568 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicudata.so.56.1
7eff18e21000-7eff18fc6000 r-xp 00000000 08:01 2379575 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicuuc.so.56.1
7eff18fc6000-7eff191c6000 ---p 001a5000 08:01 2379575 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicuuc.so.56.1
7eff191c6000-7eff191d6000 r--p 001a5000 08:01 2379575 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicuuc.so.56.1
7eff191d6000-7eff191d7000 rw-p 001b5000 08:01 2379575 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicuuc.so.56.1
7eff191d7000-7eff191d9000 rw-p 00000000 00:00 0
7eff191d9000-7eff19462000 r-xp 00000000 08:01 2379569 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicui18n.so.56.1
7eff19462000-7eff19661000 ---p 00289000 08:01 2379569 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicui18n.so.56.1
7eff19661000-7eff1966f000 r--p 00288000 08:01 2379569 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicui18n.so.56.1
7eff1966f000-7eff19671000 rw-p 00296000 08:01 2379569 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libicui18n.so.56.1
7eff19671000-7eff19672000 rw-p 00000000 00:00 0
7eff19672000-7eff1968a000 r-xp 00000000 08:01 529099 /lib/x86_64-linux-gnu/libpthread-2.23.so
7eff1968a000-7eff19889000 ---p 00018000 08:01 529099 /lib/x86_64-linux-gnu/libpthread-2.23.so
7eff19889000-7eff1988a000 r--p 00017000 08:01 529099 /lib/x86_64-linux-gnu/libpthread-2.23.so
7eff1988a000-7eff1988b000 rw-p 00018000 08:01 529099 /lib/x86_64-linux-gnu/libpthread-2.23.so
7eff1988b000-7eff1988f000 rw-p 00000000 00:00 0
7eff1988f000-7eff19a4f000 r-xp 00000000 08:01 529417 /lib/x86_64-linux-gnu/libc-2.23.so
7eff19a4f000-7eff19c4f000 ---p 001c0000 08:01 529417 /lib/x86_64-linux-gnu/libc-2.23.so
7eff19c4f000-7eff19c53000 r--p 001c0000 08:01 529417 /lib/x86_64-linux-gnu/libc-2.23.so
7eff19c53000-7eff19c55000 rw-p 001c4000 08:01 529417 /lib/x86_64-linux-gnu/libc-2.23.so
7eff19c55000-7eff19c59000 rw-p 00000000 00:00 0
7eff19c59000-7eff19c6f000 r-xp 00000000 08:01 529390 /lib/x86_64-linux-gnu/libgcc_s.so.1
7eff19c6f000-7eff19e6e000 ---p 00016000 08:01 529390 /lib/x86_64-linux-gnu/libgcc_s.so.1
7eff19e6e000-7eff19e6f000 rw-p 00015000 08:01 529390 /lib/x86_64-linux-gnu/libgcc_s.so.1
7eff19e6f000-7eff19fe1000 r-xp 00000000 08:01 2764170 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7eff19fe1000-7eff1a1e1000 ---p 00172000 08:01 2764170 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7eff1a1e1000-7eff1a1eb000 r--p 00172000 08:01 2764170 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7eff1a1eb000-7eff1a1ed000 rw-p 0017c000 08:01 2764170 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7eff1a1ed000-7eff1a1f1000 rw-p 00000000 00:00 0
7eff1a1f1000-7eff1a71b000 r-xp 00000000 08:01 2380819 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Core.so.5.9.1
7eff1a71b000-7eff1a91a000 ---p 0052a000 08:01 2380819 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Core.so.5.9.1
7eff1a91a000-7eff1a926000 r--p 00529000 08:01 2380819 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Core.so.5.9.1
7eff1a926000-7eff1a928000 rw-p 00535000 08:01 2380819 /opt/Qt5.9.1/5.9.1/gcc_64/lib/libQt5Core.so.5.9.1
7eff1a928000-7eff1a92b000 rw-p 00000000 00:00 0
7eff1a92b000-7eff1a951000 r-xp 00000000 08:01 524312 /lib/x86_64-linux-gnu/ld-2.23.so
7eff1ab21000-7eff1ab2b000 rw-p 00000000 00:00 0
7eff1ab4d000-7eff1ab50000 rw-p 00000000 00:00 0
7eff1ab50000-7eff1ab51000 r--p 00025000 08:01 524312 /lib/x86_64-linux-gnu/ld-2.23.so
7eff1ab51000-7eff1ab52000 rw-p 00026000 08:01 524312 /lib/x86_64-linux-gnu/ld-2.23.so
7eff1ab52000-7eff1ab53000 rw-p 00000000 00:00 0
7ffe006ae000-7ffe006cf000 rw-p 00000000 00:00 0 [stack]
7ffe006e2000-7ffe006e4000 r--p 00000000 00:00 0 [vvar]
7ffe006e4000-7ffe006e6000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
The workaround I've figured out was the following:
char encrypted[ textUtf8.size() + 1 ];
However, I confess that I don't know why it worked. Could someone explain it?
Is there any better solution?
The problem is that data in the QByteArray returned by text.toUtf8() is not NUL-terminated, and strcpy() expects a NUL-terminated string... since it doesn't get one, it will happily keep copying extra garbage-bytes past the end of your encrypted array until it finally does encounter a zero-byte somewhere, and corrupt your stack, which leads to the crash when the function returns.
Also, your encrypted array is not large enough to hold the NUL byte that strcpy() wants to place in it.
A fix would be something like this:
char encrypted[ textUtf8.size() + 1 ]; // +1 to hold the NUL terminator byte
memcpy(encrypted, srcString, textUtf8.size() );
encrypted[textUtf8.size()] = '\0'; // place NUL-terminator byte
[...]
Also, a portability note: dynamically-sized arrays aren't part of the C++ standard, so your declaring char encrypted[ textUtf8.size() + 1]; is working for you only because your compiler includes a non-standard extension to enable that. If you want your code to be portable (as all self-respecting Qt code should be ;)), you may want to use a std::vector or other similar higher-level mechanism instead of a dynamically-sized array.
char encrypted[ textUtf8.size() + 1 ];
Because of size we have to use a null character to terminate a string array
For example try this
#include<iostream>
#include<string>
using namespace std;
int main()
{
char textUtf8[5] ="hello";
}
You will see warning "Initializer string for char array is too long"
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().