Skip to content
  • Jeff King's avatar
    prepare_{git,shell}_cmd: use argv_array · 20574f55
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    These functions transform an existing argv into one suitable
    for exec-ing or spawning via git or a shell. We can use an
    argv_array in each to avoid dealing with manual counting and
    allocation.
    
    This also makes the memory allocation more clear and fixes
    some leaks. In prepare_shell_cmd, we would sometimes
    allocate a new string with "$@" in it and sometimes not,
    meaning the caller could not correctly free it. On the
    non-Windows side, we are in a child process which will
    exec() or exit() immediately, so the leak isn't a big deal.
    On Windows, though, we use spawn() from the parent process,
    and leak a string for each shell command we run. On top of
    that, the Windows code did not free the allocated argv array
    at all (but does for the prepare_git_cmd case!).
    
    By switching both of these functions to write into an
    argv_array, we can consistently free the result as
    appropriate.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    20574f55