public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: LIU Hao <lh_mouse@126.com>
To: Georg-Johann Lay <avr@gjlay.de>, gcc-help@gcc.gnu.org
Subject: Re: g++ problem with order of evaluation of arguments of delete.
Date: Thu, 4 May 2023 17:58:33 +0800	[thread overview]
Message-ID: <1c8956a4-f0ab-e1a8-54ec-b8f7860e990f@126.com> (raw)
In-Reply-To: <7a44d8e8-19aa-79f7-f018-7d976b258ac7@gjlay.de>


[-- Attachment #1.1: Type: text/plain, Size: 1563 bytes --]

在 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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

  reply	other threads:[~2023-05-04  9:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04  9:45 Georg-Johann Lay
2023-05-04  9:58 ` LIU Hao [this message]
2023-05-04 10:02   ` Jonathan Wakely
2023-05-04 10:00 ` Marc Glisse
2023-05-04 10:06 ` Jonathan Wakely
2023-05-04 10:12   ` Jonathan Wakely
2023-05-04 10:25     ` Jonathan Wakely
2023-05-04 10:54       ` Georg-Johann Lay
2023-05-04 10:38     ` Georg-Johann Lay
2023-05-04 10:44       ` Jonathan Wakely
2023-05-10  1:31     ` LIU Hao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c8956a4-f0ab-e1a8-54ec-b8f7860e990f@126.com \
    --to=lh_mouse@126.com \
    --cc=avr@gjlay.de \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).