Skip to content
  • Thomas Haller's avatar
    spawn: prefer allocating buffers on stack for small sizes to avoid valgrind leaks · 8a3c3b8c
    Thomas Haller authored and Philip Withnall's avatar Philip Withnall committed
    We preallocate buffers that are used after forked. That is because
    malloc()/free() are not async-signal-safe and must not be used between
    fork() and exec().
    
    However, for the child process that exits without fork, valgrind wrongly
    reports these buffers as leaked.
    That can be suppressed with "--child-silent-after-fork=yes", but it is
    cumbersome.
    
    Work around by trying to allocate the buffers on the stack. At
    least in the common cases where the pointers are small enough
    so that we can reasonably do that.
    
    If the buffers happen to be large, we still allocate them on the heap
    and the problem still happens. Maybe we could have also allocated them
    as thread_local, but currently glib doesn't use that.
    
    [smcv: Cosmetic adjustments to address review comments from pwithnall]
    8a3c3b8c