#include <iostream> #include <memory> #include <vector> #include <string> using namespace std; int main() { vector<shared_ptr<string>> values; auto smart_ptr = make_shared<string>("hello"); values.emplace_back(smart_ptr); string* raw_ptr = smart_ptr.get(); values.emplace_back(raw_ptr); cout << "I reached to the end" << endl; // your code goes here return 0; }
Standard input is empty
I reached to the end
*** Error in `./prog': free(): invalid pointer: 0x0000558efce4dc30 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x70bcb)[0x2ba616673bcb] /lib/x86_64-linux-gnu/libc.so.6(+0x76f96)[0x2ba616679f96] /lib/x86_64-linux-gnu/libc.so.6(+0x7778e)[0x2ba61667a78e] ./prog(+0x1349)[0x558efb0c7349] ./prog(+0xf8b)[0x558efb0c6f8b] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x2ba6166232b1] ./prog(+0x109a)[0x558efb0c709a] ======= Memory map: ======== 2ba615923000-2ba615946000 r-xp 00000000 fd:00 2840974 /lib/x86_64-linux-gnu/ld-2.24.so 2ba615946000-2ba61594a000 rw-p 00000000 00:00 0 2ba615953000-2ba615958000 rw-p 00000000 00:00 0 2ba615b46000-2ba615b47000 r--p 00023000 fd:00 2840974 /lib/x86_64-linux-gnu/ld-2.24.so 2ba615b47000-2ba615b48000 rw-p 00024000 fd:00 2840974 /lib/x86_64-linux-gnu/ld-2.24.so 2ba615b48000-2ba615b49000 rw-p 00000000 00:00 0 2ba615b49000-2ba615cbb000 r-xp 00000000 fd:00 2967755 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2ba615cbb000-2ba615ebb000 ---p 00172000 fd:00 2967755 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2ba615ebb000-2ba615ec5000 r--p 00172000 fd:00 2967755 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2ba615ec5000-2ba615ec7000 rw-p 0017c000 fd:00 2967755 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2ba615ec7000-2ba615ecb000 rw-p 00000000 00:00 0 2ba615ecb000-2ba615fce000 r-xp 00000000 fd:00 2841003 /lib/x86_64-linux-gnu/libm-2.24.so 2ba615fce000-2ba6161cd000 ---p 00103000 fd:00 2841003 /lib/x86_64-linux-gnu/libm-2.24.so 2ba6161cd000-2ba6161ce000 r--p 00102000 fd:00 2841003 /lib/x86_64-linux-gnu/libm-2.24.so 2ba6161ce000-2ba6161cf000 rw-p 00103000 fd:00 2841003 /lib/x86_64-linux-gnu/libm-2.24.so 2ba6161cf000-2ba6161e5000 r-xp 00000000 fd:00 2840941 /lib/x86_64-linux-gnu/libgcc_s.so.1 2ba6161e5000-2ba6163e4000 ---p 00016000 fd:00 2840941 /lib/x86_64-linux-gnu/libgcc_s.so.1 2ba6163e4000-2ba6163e5000 r--p 00015000 fd:00 2840941 /lib/x86_64-linux-gnu/libgcc_s.so.1 2ba6163e5000-2ba6163e6000 rw-p 00016000 fd:00 2840941 /lib/x86_64-linux-gnu/libgcc_s.so.1 2ba6163e6000-2ba6163fe000 r-xp 00000000 fd:00 2840960 /lib/x86_64-linux-gnu/libpthread-2.24.so 2ba6163fe000-2ba6165fd000 ---p 00018000 fd:00 2840960 /lib/x86_64-linux-gnu/libpthread-2.24.so 2ba6165fd000-2ba6165fe000 r--p 00017000 fd:00 2840960 /lib/x86_64-linux-gnu/libpthread-2.24.so 2ba6165fe000-2ba6165ff000 rw-p 00018000 fd:00 2840960 /lib/x86_64-linux-gnu/libpthread-2.24.so 2ba6165ff000-2ba616603000 rw-p 00000000 00:00 0 2ba616603000-2ba616798000 r-xp 00000000 fd:00 2841097 /lib/x86_64-linux-gnu/libc-2.24.so 2ba616798000-2ba616997000 ---p 00195000 fd:00 2841097 /lib/x86_64-linux-gnu/libc-2.24.so 2ba616997000-2ba61699b000 r--p 00194000 fd:00 2841097 /lib/x86_64-linux-gnu/libc-2.24.so 2ba61699b000-2ba61699d000 rw-p 00198000 fd:00 2841097 /lib/x86_64-linux-gnu/libc-2.24.so 2ba61699d000-2ba6169a1000 rw-p 00000000 00:00 0 2ba618000000-2ba618021000 rw-p 00000000 00:00 0 2ba618021000-2ba61c000000 ---p 00000000 00:00 0 558efb0c6000-558efb0c8000 r-xp 00000000 fd:00 26707972 /home/mOg4Od/prog 558efb2c8000-558efb2c9000 r--p 00002000 fd:00 26707972 /home/mOg4Od/prog 558efb2c9000-558efb2ca000 rw-p 00003000 fd:00 26707972 /home/mOg4Od/prog 558efce3c000-558efce6e000 rw-p 00000000 00:00 0 [heap] 7ffea5c9f000-7ffea5cc0000 rw-p 00000000 00:00 0 [stack] 7ffea5dce000-7ffea5dd0000 r-xp 00000000 00:00 0 [vdso] 7ffea5dd0000-7ffea5dd2000 r--p 00000000 00:00 0 [vvar] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]