GC issue? List.pool overwritten by allocated object

Denis Feklushkin feklushkin.denis at gmail.com
Sun May 18 12:32:23 UTC 2025


On Saturday, 17 May 2025 at 20:31:22 UTC, Denis Feklushkin wrote:

> I'm really tired of researching this issue. Maybe someone else 
> also interested?
>
> Just made a branch with latest dirty debug changes:
> ```
> git clone --branch=manual_reduce 
> git at github.com:denizzzka/pukan.git
> ```
> commit: 34dff13e76bb6ffbe9053eb8cad8f8f33a850b94

I managed to reduce the GC calls to several thousands (yes!) 
small `GC.malloc()`/`GC.free()` calls and get rid of third-party 
libraries (vulkan, etc). Actually, I just recorded all 
allocations/deallocations that my D code makes and then trimmed 
them a bit because the error still reproduceable. I hope that 
this is not a problem in the approach itself.

Sample now looks like one file ([ZIP archive 
link](https://github.com/denizzzka/pukan/raw/f3bcf6a22201eac2092c9e08ef9f01176e10d25d/issue_sample.zip)):
```d
/+ dub.sdl:
	name "issue"
+/
// How to run: dub run --single code.d

import core.memory: GC;

auto gc_malloc(T...)(T a)
{
     auto r = GC.malloc(a);
     assert(r !is null);
     return r;
}

auto gc_free(T...)(T a) => GC.free(a);

void main() {

version(linux)
version(DigitalMars)
{
     import etc.linux.memoryerror;
     registerMemoryAssertHandler();
}

void* ptr_0x7f5b360f3008 = gc_malloc(72, 0x1);
void* ptr_0x7f5b360f4008 = gc_malloc(8, 0x0);
void* ptr_0x7f5b360f5008 = gc_malloc(24, 0xa);
[...]
void* ptr_0x7f5b3611b968 = gc_malloc(12, 0x0);
void* ptr_0x7f5b3611b988 = gc_malloc(12, 0x0);

}

```

After compiling by DMD v2.111.0 execution returns:
```
> dub run --single code.d --compiler=dmd
     Starting Performing "debug" build using dmd for x86_64.
     Building issue ~master: building configuration [application]
      Linking issue
      Running issue
core.exception.AssertError@/usr/include/dmd/druntime/import/etc/linux/memoryerror.d(415): segmentation fault: null pointer read/write operation
----------------
??:? _d_assert_msg [0x55f779816710]
/usr/include/dmd/druntime/import/etc/linux/memoryerror.d:415 
extern (C) nothrow @nogc void 
etc.linux.memoryerror.registerMemoryAssertHandler!().registerMemoryAssertHandler()._d_handleSignalAssert(int, core.sys.posix.signal.siginfo_t*, void*) [0x55f7798165f3]
??:? [0x7fdfed618def]
??:? rt_finalize2 [0x55f77981d75b]
??:? rt_finalizeFromGC [0x55f7798486ba]
??:? nothrow ulong 
core.internal.gc.impl.conservative.gc.Gcx.sweep() [0x55f77983e478]
??:? nothrow ulong 
core.internal.gc.impl.conservative.gc.Gcx.fullcollect(bool, bool) 
[0x55f77983f5a5]
??:? nothrow ulong 
core.internal.gc.impl.conservative.gc.ConservativeGC.runLocked!(core.internal.gc.impl.conservative.gc.ConservativeGC.fullCollect().go(core.internal.gc.impl.conservative.gc.Gcx*), core.internal.gc.impl.conservative.gc.Gcx*).runLocked(ref core.internal.gc.impl.conservative.gc.Gcx*) [0x55f7798442e2]
??:? nothrow ulong 
core.internal.gc.impl.conservative.gc.ConservativeGC.fullCollect() [0x55f77983ba9f]
??:? nothrow void 
core.internal.gc.impl.conservative.gc.ConservativeGC.collect() 
[0x55f77983ba7d]
??:? gc_term [0x55f7798280c7]
??:? rt_term [0x55f77981d002]
??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int 
function(char[][])*).runAll() [0x55f779816d60]
??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) 
[0x55f779816c49]
??:? _d_run_main2 [0x55f779816bb2]
??:? _d_run_main [0x55f77981699b]
/usr/include/dmd/druntime/import/core/internal/entrypoint.d:29 
main [0x55f779816485]
??:? [0x7fdfed602ca7]
??:? __libc_start_main [0x7fdfed602d64]
??:? _start [0x55f779801670]
Error Program exited with code 1
```



More information about the Digitalmars-d mailing list