Why does logging in destructor lead to segmentation fault?

cc cc at nevernet.com
Mon Sep 11 18:03:53 UTC 2023


On Monday, 11 September 2023 at 17:31:17 UTC, Vladimir Marchevsky 
wrote:
> https://run.dlang.io/is/NMMpLn - minimal example. Debugging on 
> Windows, it crashes on `synchronized(mutex)` with "Access 
> violation" trying to read at zero address.

```
core.exception.InvalidMemoryOperationError at src\core\lifetime.d(126): Invalid memory operation
```
`log()` allocates on the GC apparently, which can't occur when 
the druntime is being torn down and everything being finalized on 
program termination.

```d
~this() {
     printf("inFinalizer: %d\n", GC.inFinalizer);
     if (!GC.inFinalizer)
         log("dtor");
}
```



More information about the Digitalmars-d mailing list