From def0697167d0b3fb3c9cc1a2fcbac56e540aae48 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 Jul 2014 00:41:30 -0400 Subject: [PATCH] transport: fix leaks in refs_from_alternate_cb The function starts by creating a copy of the static buffer returned by real_path, but forgets to free it in the error code paths. We can solve this by jumping to the cleanup code that is already there. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- transport.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/transport.c b/transport.c index 325f03e1ee..e735633a61 100644 --- a/transport.c +++ b/transport.c @@ -1369,11 +1369,11 @@ static int refs_from_alternate_cb(struct alternate_object_database *e, while (other[len-1] == '/') other[--len] = '\0'; if (len < 8 || memcmp(other + len - 8, "/objects", 8)) - return 0; + goto out; /* Is this a git repository with refs? */ memcpy(other + len - 8, "/refs", 6); if (!is_directory(other)) - return 0; + goto out; other[len - 8] = '\0'; remote = remote_get(other); transport = transport_get(remote, other); @@ -1382,6 +1382,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e, extra = extra->next) cb->fn(extra, cb->data); transport_disconnect(transport); +out: free(other); return 0; }