emacs-devel
[Top][All Lists]
Advanced

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

Re: warnings compiling emacs28 with gcc 12.1


From: Andreas Schwab
Subject: Re: warnings compiling emacs28 with gcc 12.1
Date: Thu, 28 Jul 2022 20:31:59 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1.90 (gnu/linux)

On Jul 28 2022, Eli Zaretskii wrote:

>> From: Óscar Fuentes <ofv@wanadoo.es>
>> Date: Thu, 28 Jul 2022 19:12:00 +0200
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> >> and there's another one about free that looks a bit scary:
>> >> 
>> >>    alloc.c: In function ‘lisp_free’:
>> >>    alloc.c:1052:3: warning: pointer ‘block’ used after ‘free’ 
>> >> [-Wuse-after-free]
>> >>     1052 |   mem_delete (mem_find (block));
>> >>          |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> >>    alloc.c:1050:3: note: call to ‘free’ here
>> >>     1050 |   free (block);
>> >>          |   ^~~~~~~~~~~~
>> >
>> > Another nonsense.  Look in mem_find, and you will see that it uses its
>> > argument as just a number, it never dereferences it.
>> 
>> The warning is not about dereferencing the pointer.
>
> What other problems could be caused by using it after freeing it?

Evan just reading the value of a pointer after free is undefined.  If
you want to preserve its bit pattern, you need to convert it to an
integer type before the call to free.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]