Skip to content

Commit 3f692fe

Browse files
pks-tgitster
authored andcommitted
trailer: fix leaking trailer values
Fix leaking trailer values when replacing the value with a command or when the token value is empty. This leak is exposed by t7513, but plugging it does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d34b5cb commit 3f692fe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

trailer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,23 @@ static char *apply_command(struct conf_info *conf, const char *arg)
249249
static void apply_item_command(struct trailer_item *in_tok, struct arg_item *arg_tok)
250250
{
251251
if (arg_tok->conf.command || arg_tok->conf.cmd) {
252-
const char *arg;
252+
char *value_to_free = NULL;
253+
char *arg;
254+
253255
if (arg_tok->value && arg_tok->value[0]) {
254256
arg = arg_tok->value;
255257
} else {
256258
if (in_tok && in_tok->value)
257259
arg = xstrdup(in_tok->value);
258260
else
259261
arg = xstrdup("");
262+
value_to_free = arg_tok->value;
260263
}
264+
261265
arg_tok->value = apply_command(&arg_tok->conf, arg);
262-
free((char *)arg);
266+
267+
free(value_to_free);
268+
free(arg);
263269
}
264270
}
265271

0 commit comments

Comments
 (0)