Re: g++ problem with order of evaluation of arguments of delete.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



在 2023/5/4 17:45, Georg-Johann Lay 写道:
My question: Is this a GCC problem, or a problem with the code and sequence points?

I recommend you learn about smart pointers and stop managing object lifetime by hand.



lh_mouse@lhmouse-xps ~/Desktop $ g++-12 test.cc -fsanitize=address,undefined -g -O2
lh_mouse@lhmouse-xps ~/Desktop $ ./a.out
=================================================================
==75277==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000030 at pc 0x55629bb062b1 bp 0x7ffe92a56000 sp 0x7ffe92a55ff0
READ of size 8 at 0x602000000030 thread T0
    #0 0x55629bb062b0 in main /home/lh_mouse/Desktop/test.cc:33
    #1 0x7f6d4aff8d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #2 0x7f6d4aff8e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #3 0x55629bb06394 in _start (/home/lh_mouse/Desktop/a.out+0x2394)

0x602000000030 is located 0 bytes inside of 8-byte region [0x602000000030,0x602000000038)
freed by thread T0 here:
#0 0x7f6d4bc20530 in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:164
    #1 0x55629bb0626d in Lexer::~Lexer() /home/lh_mouse/Desktop/test.cc:20
    #2 0x55629bb0626d in main /home/lh_mouse/Desktop/test.cc:33

previously allocated by thread T0 here:
#0 0x7f6d4bc1f488 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x55629bb061cc in main /home/lh_mouse/Desktop/test.cc:31






--
Best regards,
LIU Hao

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux