Notes
This function is in beta test. Please help improve it in the issues
here.
================================================================= ==31623==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000010 at pc 0x564597d3157f bp 0x7ffe37507a40 sp 0x7ffe37507a30 READ of size 4 at 0x602000000010 thread T0 #0 0x564597d3157e in case4() (/out/package/dlist_mem+0x1557e) #1 0x564597d2f071 in main (/out/package/dlist_mem+0x13071) #2 0x7f73c9061b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96) #3 0x564597d2f619 in _start (/out/package/dlist_mem+0x13619) 0x602000000010 is located 0 bytes inside of 4-byte region [0x602000000010,0x602000000014) freed by thread T0 here: #0 0x7f73ca7d49c8 in operator delete(void*, unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe19c8) #1 0x564597d313c1 in case4() (/out/package/dlist_mem+0x153c1) #2 0x60300000006f (<unknown module>) previously allocated by thread T0 here: #0 0x7f73ca7d3448 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0448) #1 0x564597d3105
Hints
Your answer may be identical to the JOJ answer in the first several lines.
However, the main problem you meet now is Runtime Error. And the exit code of your program is 1, which should be 0.
Please double check your code to solve this problem and try again.
Your Answer
JOJ Answer
Test success.