From bac52ab0f2e8d09de1f98590f177e9e847cdb11b Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 22 Feb 2016 13:48:45 +0100 Subject: [PATCH] pack-objects: return early when computing write order fails The function `compute_write_order` may return a `NULL`-pointer when an error occurs. In such cases we jump to the `done`-label where we try to clean up allocated memory. Unfortunately we try to deallocate the `write_order` array, though, which may be NULL here. Fix this error by returning early instead of jumping to the `done` label. There is no data to be cleaned up anyway. --- src/pack-objects.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pack-objects.c b/src/pack-objects.c index 5d9c09dd7..46fe8f3db 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -629,10 +629,8 @@ static int write_pack(git_packbuilder *pb, int error = 0; write_order = compute_write_order(pb); - if (write_order == NULL) { - error = -1; - goto done; - } + if (write_order == NULL) + return -1; /* Write pack header */ ph.hdr_signature = htonl(PACK_SIGNATURE);