checkout: fix memory leak

This change addresses part of the NEEDSWORK comment above the code,
therefore the comment needs to be adjusted, too.

Discovered via Coverity.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2017-05-04 15:56:40 +02:00
committed by Junio C Hamano
parent 05c2b7ba49
commit 514e803944

View File

@ -235,14 +235,14 @@ static int checkout_merged(int pos, const struct checkout *state)
/* /*
* NEEDSWORK: * NEEDSWORK:
* There is absolutely no reason to write this as a blob object * There is absolutely no reason to write this as a blob object
* and create a phony cache entry just to leak. This hack is * and create a phony cache entry. This hack is primarily to get
* primarily to get to the write_entry() machinery that massages * to the write_entry() machinery that massages the contents to
* the contents to work-tree format and writes out which only * work-tree format and writes out which only allows it for a
* allows it for a cache entry. The code in write_entry() needs * cache entry. The code in write_entry() needs to be refactored
* to be refactored to allow us to feed a <buffer, size, mode> * to allow us to feed a <buffer, size, mode> instead of a cache
* instead of a cache entry. Such a refactoring would help * entry. Such a refactoring would help merge_recursive as well
* merge_recursive as well (it also writes the merge result to the * (it also writes the merge result to the object database even
* object database even when it may contain conflicts). * when it may contain conflicts).
*/ */
if (write_sha1_file(result_buf.ptr, result_buf.size, if (write_sha1_file(result_buf.ptr, result_buf.size,
blob_type, oid.hash)) blob_type, oid.hash))
@ -251,6 +251,7 @@ static int checkout_merged(int pos, const struct checkout *state)
if (!ce) if (!ce)
die(_("make_cache_entry failed for path '%s'"), path); die(_("make_cache_entry failed for path '%s'"), path);
status = checkout_entry(ce, state, NULL); status = checkout_entry(ce, state, NULL);
free(ce);
return status; return status;
} }