Skip to content
  • Jeff King's avatar
    walker_fetch: fix minor memory leak · f3320699
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    f3320699