Skip to content

Commit 9f1429d

Browse files
peffgitster
authored andcommitted
format_config: don't init strbuf
It's unusual for a function which writes to a passed-in strbuf to call strbuf_init; that will throw away anything already there, leaking memory. In this case, there are exactly two callers; one relies on this initialization and the other passes in an already-initialized buffer. There's no leak, as the initialized buffer doesn't have anything in it. But let's bump the strbuf_init out to the one caller who needs it, making format_config more idiomatic. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ebca2d4 commit 9f1429d

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

builtin/config.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ struct strbuf_list {
108108

109109
static int format_config(struct strbuf *buf, const char *key_, const char *value_)
110110
{
111-
strbuf_init(buf, 0);
112-
113111
if (show_keys)
114112
strbuf_addstr(buf, key_);
115113
if (!omit_values) {
@@ -166,6 +164,7 @@ static int collect_config(const char *key_, const char *value_, void *cb)
166164
return 0;
167165

168166
ALLOC_GROW(values->items, values->nr + 1, values->alloc);
167+
strbuf_init(&values->items[values->nr], 0);
169168

170169
return format_config(&values->items[values->nr++], key_, value_);
171170
}

0 commit comments

Comments
 (0)