Git fork

shell: fix leaking strings

There are two memory leaks in "shell.c". The first one in `run_shell()`
is trivial and fixed without further explanation. The second one in
`cmd_main()` happens because we overwrite the `prog` variable, which
contains an allocated string. In fact though, the memory pointed to by
that variable is still in use because we use `split_cmdline()`, which
may create pointers into the middle of that string. But as we do not
have a direct pointer to the head of the allocated string anymore, we
get a complaint by the leak checker.

Address this by not overwriting the `prog` pointer.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
c7584168 d607bd88

+6 -3
+3 -3
shell.c
··· 143 143 } 144 144 145 145 free(argv); 146 + free(split_args); 146 147 free(rawargs); 147 148 } while (!done); 148 149 } ··· 216 217 count = split_cmdline(prog, &user_argv); 217 218 if (count >= 0) { 218 219 if (is_valid_cmd_name(user_argv[0])) { 219 - prog = make_cmd(user_argv[0]); 220 - user_argv[0] = prog; 221 - execv(user_argv[0], (char *const *) user_argv); 220 + char *cmd = make_cmd(user_argv[0]); 221 + execv(cmd, (char *const *) user_argv); 222 222 } 223 223 free(prog); 224 224 free(user_argv);
+1
t/t9400-git-cvsserver-server.sh
··· 11 11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 12 12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 13 13 14 + TEST_PASSES_SANITIZE_LEAK=true 14 15 . ./test-lib.sh 15 16 16 17 if ! test_have_prereq PERL; then
+2
t/t9850-shell.sh
··· 1 1 #!/bin/sh 2 2 3 3 test_description='git shell tests' 4 + 5 + TEST_PASSES_SANITIZE_LEAK=true 4 6 . ./test-lib.sh 5 7 6 8 test_expect_success 'shell allows upload-pack' '