Re: [PATCH 03/15] read-cache: free cache entry in add_to_index in case of early return
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 21, 2015, 03:31 UTC
- Message-ID
- <xmqq1tkjc9g6.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1426897692-18322-4-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
> This frees `ce` would be leaking in the error path.
At this point ce is not yet added to the index, so it is clear it is safe to free it---otherwise we will leak it. Good.
> Additionally a free is moved towards the return.
I am on the fence on this one between two schools and do not have a strong preference. One school is to free as soon as you know you do not need it, which is a valid stance to take. Another is, as you did, not to care about the minimum necessary lifetime of the storage and free them all at the end, which is also valid. Technically, the former could be more performant while the latter is easier on the eyes.