Skip to content

Commit aedebdb

Browse files
brandb97gitster
authored andcommitted
builtin/fetch-pack: cleanup before return error
In builtin/fetch-pack.c:cmd_fetch_pack(), if finish_connect() failed, it returns error code without cleanup which cause memory leak. Add cleanup label before frees in the end of cmd_fetch_pack(), and add `goto cleanup` if finish_connect() failed. Signed-off-by: Lidong Yan <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d50a5e8 commit aedebdb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

builtin/fetch-pack.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,10 @@ int cmd_fetch_pack(int argc,
274274
}
275275
close(fd[0]);
276276
close(fd[1]);
277-
if (finish_connect(conn))
278-
return 1;
277+
if (finish_connect(conn)) {
278+
ret = 1;
279+
goto cleanup;
280+
}
279281

280282
ret = !fetched_refs;
281283

@@ -291,6 +293,7 @@ int cmd_fetch_pack(int argc,
291293
printf("%s %s\n",
292294
oid_to_hex(&ref->old_oid), ref->name);
293295

296+
cleanup:
294297
for (size_t i = 0; i < nr_sought; i++)
295298
free_one_ref(sought_to_free[i]);
296299
free(sought_to_free);

0 commit comments

Comments
 (0)