Skip to content

Commit c758416

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d607bd8 commit c758416

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

shell.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static void run_shell(void)
143143
}
144144

145145
free(argv);
146+
free(split_args);
146147
free(rawargs);
147148
} while (!done);
148149
}
@@ -216,9 +217,8 @@ int cmd_main(int argc, const char **argv)
216217
count = split_cmdline(prog, &user_argv);
217218
if (count >= 0) {
218219
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);
222222
}
223223
free(prog);
224224
free(user_argv);

t/t9400-git-cvsserver-server.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cvs CLI client via git-cvsserver server'
1111
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1212
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1313

14+
TEST_PASSES_SANITIZE_LEAK=true
1415
. ./test-lib.sh
1516

1617
if ! test_have_prereq PERL; then

t/t9850-shell.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='git shell tests'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'shell allows upload-pack' '

0 commit comments

Comments
 (0)