Skip to content

fork on macOS 10.14.6 shows leaks #1487

Open
@GroteGnoom

Description

@GroteGnoom

For this file

#include<unistd.h>
int     main()
{
        fork();
}

if I run

clang test_fork.c -fsanitize=leak && ./a.out

I get leaks:

=================================================================
==12452==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x104f56988 in wrap_malloc+0x58 (libclang_rt.lsan_osx_dynamic.dylib:x86_64+0x8988)
    #1 0x7fff7885fb17  (libsystem_notify.dylib:x86_64+0x3b17)
    #2 0x7fff7885faf6  (libsystem_notify.dylib:x86_64+0x3af6)
    #3 0x7fff78865aaa in _os_once_callout+0x11 (libsystem_platform.dylib:x86_64+0x1aaa)
    #4 0x7fff78865a6e in _os_alloc_once+0x29 (libsystem_platform.dylib:x86_64+0x1a6e)
    #5 0x7fff78860d29 in _notify_fork_child+0xd2 (libsystem_notify.dylib:x86_64+0x4d29)
    #6 0x7fff75662b12 in libSystem_atfork_child+0x30 (libSystem.B.dylib:x86_64+0x1b12)
    #7 0x7fff786d6d96 in fork+0x27 (libsystem_c.dylib:x86_64+0xfd96)
    #8 0x104f45f88 in main+0x8 (a.out:x86_64+0x100000f88)
    #9 0x7fff7867d3d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x104f56988 in wrap_malloc+0x58 (libclang_rt.lsan_osx_dynamic.dylib:x86_64+0x8988)
    #1 0x7fff7885fb17  (libsystem_notify.dylib:x86_64+0x3b17)
    #2 0x7fff7885fae8  (libsystem_notify.dylib:x86_64+0x3ae8)
    #3 0x7fff78865aaa in _os_once_callout+0x11 (libsystem_platform.dylib:x86_64+0x1aaa)
    #4 0x7fff78865a6e in _os_alloc_once+0x29 (libsystem_platform.dylib:x86_64+0x1a6e)
    #5 0x7fff78860d29 in _notify_fork_child+0xd2 (libsystem_notify.dylib:x86_64+0x4d29)
    #6 0x7fff75662b12 in libSystem_atfork_child+0x30 (libSystem.B.dylib:x86_64+0x1b12)
    #7 0x7fff786d6d96 in fork+0x27 (libsystem_c.dylib:x86_64+0xfd96)
    #8 0x104f45f88 in main+0x8 (a.out:x86_64+0x100000f88)
    #9 0x7fff7867d3d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

Indirect leak of 2048 byte(s) in 1 object(s) allocated from:
    #0 0x104f56bcd in wrap_calloc+0x5d (libclang_rt.lsan_osx_dynamic.dylib:x86_64+0x8bcd)
    #1 0x7fff7885fb3e  (libsystem_notify.dylib:x86_64+0x3b3e)
    #2 0x7fff7885faf6  (libsystem_notify.dylib:x86_64+0x3af6)
    #3 0x7fff78865aaa in _os_once_callout+0x11 (libsystem_platform.dylib:x86_64+0x1aaa)
    #4 0x7fff78865a6e in _os_alloc_once+0x29 (libsystem_platform.dylib:x86_64+0x1a6e)
    #5 0x7fff78860d29 in _notify_fork_child+0xd2 (libsystem_notify.dylib:x86_64+0x4d29)
    #6 0x7fff75662b12 in libSystem_atfork_child+0x30 (libSystem.B.dylib:x86_64+0x1b12)
    #7 0x7fff786d6d96 in fork+0x27 (libsystem_c.dylib:x86_64+0xfd96)
    #8 0x104f45f88 in main+0x8 (a.out:x86_64+0x100000f88)
    #9 0x7fff7867d3d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

Indirect leak of 2048 byte(s) in 1 object(s) allocated from:
    #0 0x104f56bcd in wrap_calloc+0x5d (libclang_rt.lsan_osx_dynamic.dylib:x86_64+0x8bcd)
    #1 0x7fff7885fb3e  (libsystem_notify.dylib:x86_64+0x3b3e)
    #2 0x7fff7885fae8  (libsystem_notify.dylib:x86_64+0x3ae8)
    #3 0x7fff78865aaa in _os_once_callout+0x11 (libsystem_platform.dylib:x86_64+0x1aaa)
    #4 0x7fff78865a6e in _os_alloc_once+0x29 (libsystem_platform.dylib:x86_64+0x1a6e)
    #5 0x7fff78860d29 in _notify_fork_child+0xd2 (libsystem_notify.dylib:x86_64+0x4d29)
    #6 0x7fff75662b12 in libSystem_atfork_child+0x30 (libSystem.B.dylib:x86_64+0x1b12)
    #7 0x7fff786d6d96 in fork+0x27 (libsystem_c.dylib:x86_64+0xfd96)
    #8 0x104f45f88 in main+0x8 (a.out:x86_64+0x100000f88)
    #9 0x7fff7867d3d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

SUMMARY: LeakSanitizer: 4128 byte(s) leaked in 4 allocation(s).

And I'd expect there to be no leaks at all.

This is on macOS 10.14.6, with Homebrew clang version 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions