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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 24, 2014 at 00:41 UTC def0697167d0b3fb3c9cc1a2fcbac56e540aae48
1 file changed +3 -2
transport.c
+3 -2
@@ -1369,11 +1369,11 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
1369 while (other[len-1] == '/')
1370 other[--len] = '\0';
1371 if (len < 8 || memcmp(other + len - 8, "/objects", 8))
1372 - return 0;
1372 + goto out;
1373 /* Is this a git repository with refs? */
1374 memcpy(other + len - 8, "/refs", 6);
1375 if (!is_directory(other))
1376 - return 0;
1376 + goto out;
1377 other[len - 8] = '\0';
1378 remote = remote_get(other);
1379 transport = transport_get(remote, other);
@@ -1382,6 +1382,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
1382 extra = extra->next)
1383 cb->fn(extra, cb->data);
1384 transport_disconnect(transport);
1385 +out:
1386 free(other);
1387 return 0;
1388 }