Skip to content

Commit f8892da

Browse files
committed
hooks: make hook logic memory-leak free
This helps t0401 pass while under SANITIZE=leak. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 095f361 commit f8892da

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
@@ -320,12 +320,15 @@ int run_hooks_l(struct repository *r, const char *hook_name, ...)
320320
{
321321
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
322322
va_list ap;
323+
int result;
323324
const char *arg;
324325

325326
va_start(ap, hook_name);
326327
while ((arg = va_arg(ap, const char *)))
327328
strvec_push(&opt.args, arg);
328329
va_end(ap);
329330

330-
return run_hooks_opt(r, hook_name, &opt);
331+
result = run_hooks_opt(r, hook_name, &opt);
332+
strvec_clear(&opt.args);
333+
return result;
331334
}

0 commit comments

Comments
 (0)