Date: Sat, 26 Jul 2025 12:13:49 +0200
On 25/07/2025 13:17, Frederick Virchanza Gotham via Std-Proposals wrote:
> I'm writing some code at the moment, and the destructor looks like this:
>
> ~Governor(void) noexcept
> {
> try
> {
> delete this->p;
> }
> catch(...){}
>
> this->p = (void*)0xdeadbeef;
> }
>
> I've set the pointer to 0xdeadbeef because I want to make sure that
> there's nowhere else in the code that this particular object gets
> deleted. If another part of the code goes to delete the object a
> second time, it will segfault on 0xdeadbeef -- which is exactly what I
> want to happen because I want the debugger to catch it.
>
> If alternatively I were to do:
>
> this->p = nullptr;
>
> then a double-delete won't be caught by the compiler because "delete
> nullptr" is harmless.
>
The way to handle your situation seems fairly obvious to me, since you
are trying to find problems when running within a debugger:
const int deadbeaf { };
const void * badptr { &deadbeaf };
Then when you start your debugger, put a data watchpoint (read/write
access) on the symbol "deadbeaf". Any time your code tries to access
that address, your debugger halts the code.
> I'm writing some code at the moment, and the destructor looks like this:
>
> ~Governor(void) noexcept
> {
> try
> {
> delete this->p;
> }
> catch(...){}
>
> this->p = (void*)0xdeadbeef;
> }
>
> I've set the pointer to 0xdeadbeef because I want to make sure that
> there's nowhere else in the code that this particular object gets
> deleted. If another part of the code goes to delete the object a
> second time, it will segfault on 0xdeadbeef -- which is exactly what I
> want to happen because I want the debugger to catch it.
>
> If alternatively I were to do:
>
> this->p = nullptr;
>
> then a double-delete won't be caught by the compiler because "delete
> nullptr" is harmless.
>
The way to handle your situation seems fairly obvious to me, since you
are trying to find problems when running within a debugger:
const int deadbeaf { };
const void * badptr { &deadbeaf };
Then when you start your debugger, put a data watchpoint (read/write
access) on the symbol "deadbeaf". Any time your code tries to access
that address, your debugger halts the code.
Received on 2025-07-26 10:13:59