1
0
mirror of https://github.com/git/git synced 2024-06-30 22:54:27 +00:00
git/t/t5811-proto-disable-git.sh
Jeff King badf2fe1c3 daemon: free listen_addr before returning
We build up a string list of listen addresses from the command-line
arguments, but never free it. This causes t5811 to complain of a leak
(though curiously it seems to do so only when compiled with gcc, not
with clang).

To handle this correctly, we have to do a little refactoring:

  - there are two exit points from the main function, depending on
    whether we are entering the main loop or serving a single client
    (since rather than a traditional fork model, we re-exec ourselves
    with the extra "--serve" argument to accommodate Windows).

    We don't need --listen at all in the --serve case, of course, but it
    is passed along by the parent daemon, which simply copies all of the
    command-line options it got.

  - we just "return serve()" to run the main loop, giving us no chance
    to do any cleanup

So let's use a "ret" variable to store the return code, and give
ourselves a single exit point at the end. That gives us one place to do
cleanup.

Note that this code also uses the "use a no-dup string-list, but
allocate strings we add to it" trick, meaning string_list_clear() will
not realize it should free them. We can fix this by switching to a "dup"
string-list, but using the "append_nodup" function to add to it (this is
preferable to tweaking the strdup_strings flag before clearing, as it
puts all the subtle memory-ownership code together).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-10-05 14:54:58 -07:00

23 lines
543 B
Bash
Executable File

#!/bin/sh
test_description='test disabling of git-over-tcp in clone/fetch'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY/lib-proto-disable.sh"
. "$TEST_DIRECTORY/lib-git-daemon.sh"
start_git_daemon
test_expect_success 'create git-accessible repo' '
bare="$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" &&
test_commit one &&
git --bare init "$bare" &&
git push "$bare" HEAD &&
>"$bare/git-daemon-export-ok" &&
git -C "$bare" config daemon.receivepack true
'
test_proto "git://" git "$GIT_DAEMON_URL/repo.git"
test_done