Skip to content

Commit 7eb6f02

Browse files
pks-tgitster
authored andcommitted
builtin/push: fix leaking refspec query result
When appending a refspec via `refspec_append_mapped()` we leak the result of `query_refspecs()`. The overall logic around refspec queries is quite weird, as callers are expected to either set the `src` or `dst` pointers, and then the (allocated) result will be in the respective other struct member. As we have the `src` member set, plugging the memory leak is thus as easy as just freeing the `dst` member. While at it, use designated initializers to initialize the structure. This leak was exposed by t5516, but fixing it is not sufficient to make the whole test suite leak free. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e03004f commit 7eb6f02

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

builtin/push.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ static void refspec_append_mapped(struct refspec *refspec, const char *ref,
7272
const char *branch_name;
7373

7474
if (remote->push.nr) {
75-
struct refspec_item query;
76-
memset(&query, 0, sizeof(struct refspec_item));
77-
query.src = matched->name;
75+
struct refspec_item query = {
76+
.src = matched->name,
77+
};
78+
7879
if (!query_refspecs(&remote->push, &query) && query.dst) {
7980
refspec_appendf(refspec, "%s%s:%s",
8081
query.force ? "+" : "",
8182
query.src, query.dst);
83+
free(query.dst);
8284
return;
8385
}
8486
}

0 commit comments

Comments
 (0)