opendlang / opend

Boost Software License 1.0
89 stars 20 forks source link

LDC: Valgrind detect memory leak #68

Open kassane opened 7 months ago

kassane commented 7 months ago

Arch: x86-64 (zen3) OS: ArchLinux (glibc)

Note: on alpine-musl not issue.

build - output ```bash $> cat hello.d void main() {} $> ldc2 hello.d $> valgrind --leak-check=full --show-leak-kinds=all ./hello ==109403== Memcheck, a memory error detector ==109403== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==109403== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==109403== Command: ./hello ==109403== ==109403== ==109403== HEAP SUMMARY: ==109403== in use at exit: 96 bytes in 2 blocks ==109403== total heap usage: 229 allocs, 227 frees, 47,488 bytes allocated ==109403== ==109403== 24 bytes in 1 blocks are still reachable in loss record 1 of 2 ==109403== at 0x484ABC0: realloc (vg_replace_malloc.c:1690) ==109403== by 0x128800: core.internal.container.common.xrealloc(void*, ulong) (in /home/kassane/Downloads/hello) ==109403== by 0x128475: core.internal.container.array.Array!(core.gc.gcinterface.Range).Array.insertBack!().insertBack(core.gc.gcinterface.Range) (in /home/kassane/Downloads/hello) ==109403== by 0x147CEC: _DThn16_4core8internal2gc4impl5protoQo7ProtoGC8addRangeMFNbNiPvmxC8TypeInfoZv (in /home/kassane/Downloads/hello) ==109403== by 0x122C0D: rt.memory.initStaticDataGC().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109403== by 0x1241D8: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109403== by 0x121853: rt_init (in /home/kassane/Downloads/hello) ==109403== by 0x121CFC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109403== by 0x121C36: _d_run_main2 (in /home/kassane/Downloads/hello) ==109403== by 0x121A8C: _d_run_main (in /home/kassane/Downloads/hello) ==109403== by 0x1217F1: main (in /home/kassane/Downloads/hello) ==109403== ==109403== 72 bytes in 1 blocks are still reachable in loss record 2 of 2 ==109403== at 0x484ABC0: realloc (vg_replace_malloc.c:1690) ==109403== by 0x13B191: core.gc.registry.registerGCFactory(immutable(char)[], core.gc.gcinterface.GC() function) (in /home/kassane/Downloads/hello) ==109403== by 0x49B1DFD: call_init (libc-start.c:145) ==109403== by 0x49B1DFD: __libc_start_main@@GLIBC_2.34 (libc-start.c:347) ==109403== by 0x1216E4: (below main) (in /home/kassane/Downloads/hello) ==109403== ==109403== LEAK SUMMARY: ==109403== definitely lost: 0 bytes in 0 blocks ==109403== indirectly lost: 0 bytes in 0 blocks ==109403== possibly lost: 0 bytes in 0 blocks ==109403== still reachable: 96 bytes in 2 blocks ==109403== suppressed: 0 bytes in 0 blocks ==109403== ==109403== For lists of detected and suppressed errors, rerun with: -s ==109403== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```
static-build - output ```bash $> valgrind --leak-check=full --show-leak-kinds=all ./hello ==109547== Memcheck, a memory error detector ==109547== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==109547== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==109547== Command: ./hello ==109547== ==109547== Syscall param set_robust_list(head) points to uninitialised byte(s) ==109547== at 0x47E34A: __tls_init_tp (in /home/kassane/Downloads/hello) ==109547== by 0x434C12: __libc_setup_tls (in /home/kassane/Downloads/hello) ==109547== by 0x434768: (below main) (in /home/kassane/Downloads/hello) ==109547== Address 0x4000870 is in the brk data segment 0x4000000-0x4000eff ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x45B9F7: malloc (in /home/kassane/Downloads/hello) ==109547== by 0x47CCCD: _dl_get_origin (in /home/kassane/Downloads/hello) ==109547== by 0x47FCB6: _dl_non_dynamic_init (in /home/kassane/Downloads/hello) ==109547== by 0x481768: __libc_init_first (in /home/kassane/Downloads/hello) ==109547== by 0x43485D: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x45BAB9: malloc (in /home/kassane/Downloads/hello) ==109547== by 0x47CCCD: _dl_get_origin (in /home/kassane/Downloads/hello) ==109547== by 0x47FCB6: _dl_non_dynamic_init (in /home/kassane/Downloads/hello) ==109547== by 0x481768: __libc_init_first (in /home/kassane/Downloads/hello) ==109547== by 0x43485D: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x45A490: _int_malloc (in /home/kassane/Downloads/hello) ==109547== by 0x45B282: tcache_init.part.0 (in /home/kassane/Downloads/hello) ==109547== by 0x45BAC3: malloc (in /home/kassane/Downloads/hello) ==109547== by 0x47CCCD: _dl_get_origin (in /home/kassane/Downloads/hello) ==109547== by 0x47FCB6: _dl_non_dynamic_init (in /home/kassane/Downloads/hello) ==109547== by 0x481768: __libc_init_first (in /home/kassane/Downloads/hello) ==109547== by 0x43485D: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x404A24: _d_dso_registry (in /home/kassane/Downloads/hello) ==109547== by 0x4348F4: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x453EAA: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x453EDD: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x453EF8: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451229: __libc_cleanup_push_defer (in /home/kassane/Downloads/hello) ==109547== by 0x44E555: _IO_link_in (in /home/kassane/Downloads/hello) ==109547== by 0x44BFED: _IO_new_file_init_internal (in /home/kassane/Downloads/hello) ==109547== by 0x44944D: __fopen_internal (in /home/kassane/Downloads/hello) ==109547== by 0x454043: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451275: __libc_cleanup_pop_restore (in /home/kassane/Downloads/hello) ==109547== by 0x44E609: _IO_link_in (in /home/kassane/Downloads/hello) ==109547== by 0x44BFED: _IO_new_file_init_internal (in /home/kassane/Downloads/hello) ==109547== by 0x44944D: __fopen_internal (in /home/kassane/Downloads/hello) ==109547== by 0x454043: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451229: __libc_cleanup_push_defer (in /home/kassane/Downloads/hello) ==109547== by 0x43F6BE: __vfscanf_internal (in /home/kassane/Downloads/hello) ==109547== by 0x49B552: __isoc23_sscanf (in /home/kassane/Downloads/hello) ==109547== by 0x45412C: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451275: __libc_cleanup_pop_restore (in /home/kassane/Downloads/hello) ==109547== by 0x43FA37: __vfscanf_internal (in /home/kassane/Downloads/hello) ==109547== by 0x49B552: __isoc23_sscanf (in /home/kassane/Downloads/hello) ==109547== by 0x45412C: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451229: __libc_cleanup_push_defer (in /home/kassane/Downloads/hello) ==109547== by 0x44E199: _IO_un_link.part.0 (in /home/kassane/Downloads/hello) ==109547== by 0x448E34: fclose (in /home/kassane/Downloads/hello) ==109547== by 0x454072: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451275: __libc_cleanup_pop_restore (in /home/kassane/Downloads/hello) ==109547== by 0x44E352: _IO_un_link.part.0 (in /home/kassane/Downloads/hello) ==109547== by 0x448E34: fclose (in /home/kassane/Downloads/hello) ==109547== by 0x454072: pthread_getattr_np (in /home/kassane/Downloads/hello) ==109547== by 0x40D8E1: core.thread.osthread.attachThread(core.thread.threadbase.ThreadBase) (in /home/kassane/Downloads/hello) ==109547== by 0x40DE48: thread_init (in /home/kassane/Downloads/hello) ==109547== by 0x401B2E: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x459569: _int_free (in /home/kassane/Downloads/hello) ==109547== by 0x45C0E0: free (in /home/kassane/Downloads/hello) ==109547== by 0x403360: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]) (in /home/kassane/Downloads/hello) ==109547== by 0x403FD8: rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x4044B8: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401B38: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x459569: _int_free (in /home/kassane/Downloads/hello) ==109547== by 0x45B507: _int_realloc (in /home/kassane/Downloads/hello) ==109547== by 0x45C4F5: realloc (in /home/kassane/Downloads/hello) ==109547== by 0x40343A: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]) (in /home/kassane/Downloads/hello) ==109547== by 0x403FD8: rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x4044B8: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401B38: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x459569: _int_free (in /home/kassane/Downloads/hello) ==109547== by 0x45B507: _int_realloc (in /home/kassane/Downloads/hello) ==109547== by 0x45C4F5: realloc (in /home/kassane/Downloads/hello) ==109547== by 0x403D43: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]).doSort(ulong, ref immutable(object.ModuleInfo)*[]) (in /home/kassane/Downloads/hello) ==109547== by 0x40348C: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]) (in /home/kassane/Downloads/hello) ==109547== by 0x403FD8: rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x4044B8: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401B38: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x459569: _int_free (in /home/kassane/Downloads/hello) ==109547== by 0x45C0E0: free (in /home/kassane/Downloads/hello) ==109547== by 0x4034D5: rt.minfo.ModuleGroup.sortCtors(immutable(char)[]) (in /home/kassane/Downloads/hello) ==109547== by 0x403FD8: rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x4044B8: rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401B38: rt_init (in /home/kassane/Downloads/hello) ==109547== by 0x401FDC: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x4287BF: rt.profilegc._staticDtor_L94_C1() (in /home/kassane/Downloads/hello) ==109547== by 0x404105: rt.minfo.rt_moduleTlsDtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x40450E: rt.sections_elf_shared.DSO.opApplyReverse(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401BF5: rt_term (in /home/kassane/Downloads/hello) ==109547== by 0x402031: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x45C077: free (in /home/kassane/Downloads/hello) ==109547== by 0x42882C: rt.profilegc._staticDtor_L94_C1() (in /home/kassane/Downloads/hello) ==109547== by 0x404105: rt.minfo.rt_moduleTlsDtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x40450E: rt.sections_elf_shared.DSO.opApplyReverse(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401BF5: rt_term (in /home/kassane/Downloads/hello) ==109547== by 0x402031: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x413D17: rt.lifetime._staticDtor_L534_C1() (in /home/kassane/Downloads/hello) ==109547== by 0x404105: rt.minfo.rt_moduleTlsDtor().__foreachbody1(ref rt.sections_elf_shared.DSO) (in /home/kassane/Downloads/hello) ==109547== by 0x40450E: rt.sections_elf_shared.DSO.opApplyReverse(scope int(ref rt.sections_elf_shared.DSO) delegate) (in /home/kassane/Downloads/hello) ==109547== by 0x401BF5: rt_term (in /home/kassane/Downloads/hello) ==109547== by 0x402031: rt.dmain2._d_run_main2(char[][], ulong, extern(C) int(char[][]) function).runAll() (in /home/kassane/Downloads/hello) ==109547== by 0x401F16: _d_run_main2 (in /home/kassane/Downloads/hello) ==109547== by 0x401D6C: _d_run_main (in /home/kassane/Downloads/hello) ==109547== by 0x401AD1: main (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x459569: _int_free (in /home/kassane/Downloads/hello) ==109547== by 0x45C0E0: free (in /home/kassane/Downloads/hello) ==109547== by 0x408AEF: core.internal.container.common.xrealloc(void*, ulong) (in /home/kassane/Downloads/hello) ==109547== by 0x4083B8: core.internal.container.array.Array!(rt.sections_elf_shared.DSO*).Array.popBack() (in /home/kassane/Downloads/hello) ==109547== by 0x404813: _d_dso_registry (in /home/kassane/Downloads/hello) ==109547== by 0x43258B: call_fini (in /home/kassane/Downloads/hello) ==109547== by 0x435790: __run_exit_handlers (in /home/kassane/Downloads/hello) ==109547== by 0x4358FF: exit (in /home/kassane/Downloads/hello) ==109547== by 0x432A10: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451229: __libc_cleanup_push_defer (in /home/kassane/Downloads/hello) ==109547== by 0x44F730: _IO_flush_all (in /home/kassane/Downloads/hello) ==109547== by 0x44FDD9: _IO_cleanup (in /home/kassane/Downloads/hello) ==109547== by 0x4358A2: __run_exit_handlers (in /home/kassane/Downloads/hello) ==109547== by 0x4358FF: exit (in /home/kassane/Downloads/hello) ==109547== by 0x432A10: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451275: __libc_cleanup_pop_restore (in /home/kassane/Downloads/hello) ==109547== by 0x44F947: _IO_flush_all (in /home/kassane/Downloads/hello) ==109547== by 0x44FDD9: _IO_cleanup (in /home/kassane/Downloads/hello) ==109547== by 0x4358A2: __run_exit_handlers (in /home/kassane/Downloads/hello) ==109547== by 0x4358FF: exit (in /home/kassane/Downloads/hello) ==109547== by 0x432A10: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451229: __libc_cleanup_push_defer (in /home/kassane/Downloads/hello) ==109547== by 0x44FDF7: _IO_cleanup (in /home/kassane/Downloads/hello) ==109547== by 0x4358A2: __run_exit_handlers (in /home/kassane/Downloads/hello) ==109547== by 0x4358FF: exit (in /home/kassane/Downloads/hello) ==109547== by 0x432A10: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== Conditional jump or move depends on uninitialised value(s) ==109547== at 0x451275: __libc_cleanup_pop_restore (in /home/kassane/Downloads/hello) ==109547== by 0x44FF8B: _IO_cleanup (in /home/kassane/Downloads/hello) ==109547== by 0x4358A2: __run_exit_handlers (in /home/kassane/Downloads/hello) ==109547== by 0x4358FF: exit (in /home/kassane/Downloads/hello) ==109547== by 0x432A10: (below main) (in /home/kassane/Downloads/hello) ==109547== ==109547== ==109547== HEAP SUMMARY: ==109547== in use at exit: 0 bytes in 0 blocks ==109547== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==109547== ==109547== All heap blocks were freed -- no leaks are possible ==109547== ==109547== Use --track-origins=yes to see where uninitialised values come from ==109547== For lists of detected and suppressed errors, rerun with: -s ==109547== ERROR SUMMARY: 84 errors from 26 contexts (suppressed: 0 from 0) ```
Sanitizer=memory ```bash $> ./openldc2-0655f30f-linux-x86_64/bin/ldc2 hello.d -fsanitize=memory kassane:~/Downloads $ ./hello FATAL: Code 0x6423f3fbdbf0 is out of application range. Non-PIE build? FATAL: MemorySanitizer can not mmap the shadow memory. FATAL: Make sure to compile with -fPIE and to link with -pie. FATAL: Disabling ASLR is known to cause this error. FATAL: If running under GDB, try 'set disable-randomization off'. ==109599==Process memory map follows: 0x6423f3f9e000-0x6423f3fbd000 /home/kassane/Downloads/hello 0x6423f3fbd000-0x6423f4052000 /home/kassane/Downloads/hello 0x6423f4052000-0x6423f408e000 /home/kassane/Downloads/hello 0x6423f408e000-0x6423f4095000 /home/kassane/Downloads/hello 0x6423f4095000-0x6423f40a0000 /home/kassane/Downloads/hello 0x6423f40a0000-0x6423f59f4000 0x7e3f53e00000-0x7e3f53f00000 0x7e3f54000000-0x7e3f54100000 0x7e3f54200000-0x7e3f54300000 0x7e3f54400000-0x7e3f54500000 0x7e3f54600000-0x7e3f5498e000 0x7e3f54a00000-0x7e3f54a04000 0x7e3f54a04000-0x7e3f54a28000 /usr/lib/libc.so.6 0x7e3f54a28000-0x7e3f54b83000 /usr/lib/libc.so.6 0x7e3f54b83000-0x7e3f54bd8000 /usr/lib/libc.so.6 0x7e3f54bd8000-0x7e3f54bdc000 /usr/lib/libc.so.6 0x7e3f54bdc000-0x7e3f54bde000 /usr/lib/libc.so.6 0x7e3f54bde000-0x7e3f54be6000 0x7e3f54be6000-0x7e3f54bea000 /usr/lib/libgcc_s.so.1 0x7e3f54bea000-0x7e3f54c05000 /usr/lib/libgcc_s.so.1 0x7e3f54c05000-0x7e3f54c09000 /usr/lib/libgcc_s.so.1 0x7e3f54c09000-0x7e3f54c0a000 /usr/lib/libgcc_s.so.1 0x7e3f54c0a000-0x7e3f54c0b000 /usr/lib/libgcc_s.so.1 0x7e3f54c0b000-0x7e3f54c19000 /usr/lib/libm.so.6 0x7e3f54c19000-0x7e3f54c99000 /usr/lib/libm.so.6 0x7e3f54c99000-0x7e3f54cf5000 /usr/lib/libm.so.6 0x7e3f54cf5000-0x7e3f54cf6000 /usr/lib/libm.so.6 0x7e3f54cf6000-0x7e3f54cf7000 /usr/lib/libm.so.6 0x7e3f54cf7000-0x7e3f54cf9000 0x7e3f54d0c000-0x7e3f54d1d000 0x7e3f54d1d000-0x7e3f54d1e000 /usr/lib/ld-linux-x86-64.so.2 0x7e3f54d1e000-0x7e3f54d45000 /usr/lib/ld-linux-x86-64.so.2 0x7e3f54d45000-0x7e3f54d50000 /usr/lib/ld-linux-x86-64.so.2 0x7e3f54d50000-0x7e3f54d52000 /usr/lib/ld-linux-x86-64.so.2 0x7e3f54d52000-0x7e3f54d54000 /usr/lib/ld-linux-x86-64.so.2 0x7ffefc59d000-0x7ffefc5be000 [stack] 0x7ffefc5e5000-0x7ffefc5e9000 [vvar] 0x7ffefc5e9000-0x7ffefc5eb000 [vdso] 0xffffffffff600000-0xffffffffff601000 [vsyscall] ==109599==End of process memory map. ```

Reference

kassane commented 7 months ago

more tests

$> export ASAN_OPTIONS=abort_on_error=0:fast_unwind_on_malloc=0:detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1
$> ./openldc2-0655f30f-linux-x86_64/bin/ldc2 hello.d -fsanitize=memory -static
/usr/bin/ld: /home/kassane/Downloads/openldc2-0655f30f-linux-x86_64/bin/../lib/libldc_rt.msan.a(msan_interceptors.cpp.o): in function `InitializeCommonInterceptors()':
/home/runner/work/llvm-project/llvm-project/compiler-rt/lib/msan/../sanitizer_common/sanitizer_common_interceptors.inc:10448:(.text._ZL28InitializeCommonInterceptorsv+0x61bb): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /home/kassane/Downloads/openldc2-0655f30f-linux-x86_64/bin/../lib/libldc_rt.msan.a(msan_interceptors.cpp.o): note: the message above does not take linker garbage collection into account
$> ./hello 
MemorySanitizer: CHECK failed: sanitizer_common_interceptors_memintrinsics.inc:239 "((__interception::real_memcpy)) != (0)" (0x0, 0x0) (tid=19145)
    <empty stack>

Reference

adamdruppe commented 7 months ago

I think upstream had something similar to this a while ago, possible we introduced something new here but also possible there is a commit from them we can cherry pick to solve it.

kassane commented 7 months ago

It's also worth investigating whether this only happens on archlinux. I'll try the same test on another distro (glibc only).

kassane commented 7 months ago

that ConservativeGC object itself is malloc'd during runtime/GC initialization and most likely never freed.

https://github.com/opendlang/opend/blob/45eb187c85cf85bd5af4a6e32d0b173d81756882/druntime/src/core/internal/gc/impl/conservative/gc.d#L138-L147

adamdruppe commented 7 months ago

That makes sense, I guess it is kinda a leak because it isn't freed explicitly, but it is meant to live through the lifetime of the process. Do you know if there's an easy way to just tell valgrind "don't worry about this"?

kassane commented 7 months ago

Suppressions?

valgrind-suppression-stdout ```bash $ valgrind --leak-check=full --show-reachable=yes -v --track-origins=yes --show-leak-kinds=all --error-limit=no --gen-suppressions=all --log-fd=9 ./start 9>>memcheck.log $ ./suppression.sh memcheck.log { Memcheck:Leak match-leak-kinds: reachable fun:realloc fun:_D4core8internal9container6common8xreallocFNbNiPvmZQe fun:_D4core8internal9container5array__T5ArrayTSQBp2gc11gcinterface5RangeZQBi__T10insertBackZQnMFNbNiQCcZv fun:_DThn16_4core8internal2gc4impl5protoQo7ProtoGC8addRangeMFNbNiPvmxC8TypeInfoZv fun:_D2rt6memory16initStaticDataGCFZ14__foreachbody1MFNbNiKSQCc19sections_elf_shared3DSOZi fun:_D2rt19sections_elf_shared3DSO7opApplyFMDFKSQBqQBqQyZiZi fun:rt_init fun:_D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv fun:_d_run_main2 fun:_d_run_main fun:(below main) } { Memcheck:Leak match-leak-kinds: reachable fun:realloc fun:_D4core2gc8registry17registerGCFactoryFNbNiAyaPFZCQBwQBu11gcinterface2GCZv fun:call_init fun:__libc_start_main@@GLIBC_2.34 fun:(below main) } $ ./suppression.sh memcheck.log > druntime.supp $ valgrind --leak-check=full --show-leak-kinds=all --suppressions=druntime.supp ./start ==112438== Memcheck, a memory error detector ==112438== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==112438== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==112438== Command: ./start ==112438== ==112438== ==112438== HEAP SUMMARY: ==112438== in use at exit: 96 bytes in 2 blocks ==112438== total heap usage: 232 allocs, 230 frees, 47,595 bytes allocated ==112438== ==112438== LEAK SUMMARY: ==112438== definitely lost: 0 bytes in 0 blocks ==112438== indirectly lost: 0 bytes in 0 blocks ==112438== possibly lost: 0 bytes in 0 blocks ==112438== still reachable: 0 bytes in 0 blocks ==112438== suppressed: 96 bytes in 2 blocks ==112438== ==112438== For lists of detected and suppressed errors, rerun with: -s ==112438== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```

References