Skip to content

Commit 62f79d1

Browse files
derrickstoleedscho
authored andcommitted
hooks: make hook logic memory-leak free
This helps t0401 pass while under SANITIZE=leak. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent e4b9ec2 commit 62f79d1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ static int run_post_command_hook(struct repository *r)
494494

495495
run_post_hook = 0;
496496
strvec_clear(&sargv);
497+
strvec_clear(&opt.args);
497498
setenv("COMMAND_HOOK_LOCK", "false", 1);
498499
return ret;
499500
}

hook.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,15 @@ int run_hooks_l(struct repository *r, const char *hook_name, ...)
347347
{
348348
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
349349
va_list ap;
350+
int result;
350351
const char *arg;
351352

352353
va_start(ap, hook_name);
353354
while ((arg = va_arg(ap, const char *)))
354355
strvec_push(&opt.args, arg);
355356
va_end(ap);
356357

357-
return run_hooks_opt(r, hook_name, &opt);
358+
result = run_hooks_opt(r, hook_name, &opt);
359+
strvec_clear(&opt.args);
360+
return result;
358361
}

0 commit comments

Comments
 (0)