walker_fetch: fix minor memory leak
commitf33206992de994424036a7d9912a968ab9829e6e
authorJeff King <peff@peff.net>
Thu, 19 Jun 2014 21:29:48 +0000 (19 17:29 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 19 Jun 2014 22:20:56 +0000 (19 15:20 -0700)
tree1d3c9a7bfafe5498ba00c7945942d9ed824f2dd6
parent5c1753b198a96ed6abaf6c09db4623df703005a6
walker_fetch: fix minor memory leak

We sometimes allocate "msg" on the heap, but will fail to
free it if we hit the failure code path. We can instead keep
a separate variable that is safe to be freed no matter how
we get to the failure code path.

While we're here, we can also do two readability
improvements:

  1. Use xstrfmt instead of a manual malloc/sprintf

  2. Due to the "maybe we allocate msg, maybe we don't"
     strategy, the logic for deciding which message to show
     was split into two parts. Since the deallocation is now
     pushed onto a separate variable, this is no longer a
     concern, and we can keep all of the logic in the same
     place.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
walker.c