Issue 23106 - the simple main() leaks 72 bytes
Summary: the simple main() leaks 72 bytes
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-12 11:51 UTC by basile-z
Modified: 2024-12-07 13:42 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2022-05-12 11:51:46 UTC
```
module a;

int main()
{
    return 0;
}               
```

valgrind ./a

```
==1210593== For lists of detected and suppressed errors, rerun with: -s
==1210593== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
[basile@pc temp]$ valgrind --leak-check=full --show-leak-kinds=all ./a
==1210595== Memcheck, a memory error detector
==1210595== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1210595== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==1210595== Command: ./a
==1210595== 
==1210595== 
==1210595== HEAP SUMMARY:
==1210595==     in use at exit: 96 bytes in 2 blocks
==1210595==   total heap usage: 151 allocs, 149 frees, 15,080 bytes allocated
==1210595== 
==1210595== 24 bytes in 1 blocks are still reachable in loss record 1 of 2
==1210595==    at 0x4839747: malloc (vg_replace_malloc.c:306)
==1210595==    by 0x483BD32: realloc (vg_replace_malloc.c:834)
==1210595==    by 0x437361: _D4core8internal9container6common8xreallocFNbNiPvmZQe (in /home/basile/Bureau/temp/a)
==1210595==    by 0x445872: _D4core8internal2gc4impl5protoQo7ProtoGC8addRangeMFNbNiPvmxC8TypeInfoZv (in /home/basile/Bureau/temp/a)
==1210595==    by 0x43763B: gc_addRange (in /home/basile/Bureau/temp/a)
==1210595==    by 0x439441: _D2rt6memory16initStaticDataGCFZ14__foreachbody1MFNbNiKSQCc19sections_elf_shared3DSOZi (in /home/basile/Bureau/temp/a)
==1210595==    by 0x43B93F: _D2rt19sections_elf_shared3DSO7opApplyFMDFKSQBqQBqQyZiZi (in /home/basile/Bureau/temp/a)
==1210595==    by 0x4393E4: _D2rt6memory16initStaticDataGCFZv (in /home/basile/Bureau/temp/a)
==1210595==    by 0x437EC4: rt_init (in /home/basile/Bureau/temp/a)
==1210595==    by 0x434B67: _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv (in /home/basile/Bureau/temp/a)
==1210595==    by 0x434B04: _D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv (in /home/basile/Bureau/temp/a)
==1210595==    by 0x434A65: _d_run_main2 (in /home/basile/Bureau/temp/a)
==1210595== 
==1210595== 72 bytes in 1 blocks are still reachable in loss record 2 of 2
==1210595==    at 0x483BCE8: realloc (vg_replace_malloc.c:834)
==1210595==    by 0x465FB5: _d_register_manual_gc (in /home/basile/Bureau/temp/a)
==1210595==    by 0x46E69C: __libc_csu_init (in /home/basile/Bureau/temp/a)
==1210595==    by 0x4A2D16D: (below main) (in /usr/lib64/libc-2.32.so)
==1210595== 
==1210595== LEAK SUMMARY:
==1210595==    definitely lost: 0 bytes in 0 blocks
==1210595==    indirectly lost: 0 bytes in 0 blocks
==1210595==      possibly lost: 0 bytes in 0 blocks
==1210595==    still reachable: 96 bytes in 2 blocks
==1210595==         suppressed: 0 bytes in 0 blocks
==1210595== 
==1210595== For lists of detected and suppressed errors, rerun with: -s
==1210595== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
```

seems to be caused by the gc initialization
Comment 1 basile-z 2023-07-14 21:33:02 UTC
==117347== Memcheck, a memory error detector
==117347== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==117347== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==117347== Command: /tmp/temp_7F336C18C4D0
==117347== 
==117347== realloc() with size 0
==117347==    at 0x4848A40: realloc (vg_replace_malloc.c:1649)
==117347==    by 0x4389F1: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x439608: rt.minfo.ModuleGroup.sortCtors() (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4398DC: rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x439D31: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4398BC: rt_moduleCtor (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x436F39: rt_init (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x433BD7: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x433B75: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).tryExec(scope void() delegate) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x433ADE: _d_run_main2 (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4338C7: _d_run_main (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4337E1: main (entrypoint.d:29)
==117347==  Address 0x4b50c00 is 0 bytes inside a block of size 104 alloc'd
==117347==    at 0x484382F: malloc (vg_replace_malloc.c:431)
==117347==    by 0x438947: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x439608: rt.minfo.ModuleGroup.sortCtors() (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4398DC: rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x439D31: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4398BC: rt_moduleCtor (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x436F39: rt_init (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x433BD7: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x433B75: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).tryExec(scope void() delegate) (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x433ADE: _d_run_main2 (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4338C7: _d_run_main (in /tmp/temp_7F336C18C4D0)
==117347==    by 0x4337E1: main (entrypoint.d:29)
==117347== 
==117347== 
==117347== HEAP SUMMARY:
==117347==     in use at exit: 72 bytes in 2 blocks
==117347==   total heap usage: 101 allocs, 99 frees, 9,040 bytes allocated
==117347== 
==117347== LEAK SUMMARY:
==117347==    definitely lost: 0 bytes in 0 blocks
==117347==    indirectly lost: 0 bytes in 0 blocks
==117347==      possibly lost: 0 bytes in 0 blocks
==117347==    still reachable: 72 bytes in 2 blocks
==117347==         suppressed: 0 bytes in 0 blocks
==117347== Rerun with --leak-check=full to see details of leaked memory
==117347== 
==117347== For lists of detected and suppressed errors, rerun with: -s
==117347== ERROR SUMMARY: 16 errors from 1 contexts (suppressed: 0 from 0)
[basile@pc styx]$
Comment 2 Dennis 2024-04-05 15:16:49 UTC
Since we now have proper valgrind support including a test in the test suite (https://github.com/dlang/dmd/pull/15304), can you still reproduce this?
Comment 3 Alisa Lain 2024-04-10 11:11:49 UTC
I'm not the author of this issue, but I can still replicate it. Same thing 72 bytes.

Compiling with both dmd and dub produces this leak and turning on -betterC switch fixes issue.

Also, just a note, changing compiler to LDC makes it even worse (going to report on their repo).
Comment 4 dlangBugzillaToGithub 2024-12-07 13:42:02 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17446

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB