Skip to content

Commit 514e803

Browse files
dschogitster
authored andcommitted
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>
1 parent 05c2b7b commit 514e803

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

builtin/checkout.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ static int checkout_merged(int pos, const struct checkout *state)
235235
/*
236236
* NEEDSWORK:
237237
* There is absolutely no reason to write this as a blob object
238-
* and create a phony cache entry just to leak. This hack is
239-
* primarily to get to the write_entry() machinery that massages
240-
* the contents to work-tree format and writes out which only
241-
* allows it for a cache entry. The code in write_entry() needs
242-
* to be refactored to allow us to feed a <buffer, size, mode>
243-
* instead of a cache entry. Such a refactoring would help
244-
* merge_recursive as well (it also writes the merge result to the
245-
* object database even when it may contain conflicts).
238+
* and create a phony cache entry. This hack is primarily to get
239+
* to the write_entry() machinery that massages the contents to
240+
* work-tree format and writes out which only allows it for a
241+
* cache entry. The code in write_entry() needs to be refactored
242+
* to allow us to feed a <buffer, size, mode> instead of a cache
243+
* entry. Such a refactoring would help merge_recursive as well
244+
* (it also writes the merge result to the object database even
245+
* when it may contain conflicts).
246246
*/
247247
if (write_sha1_file(result_buf.ptr, result_buf.size,
248248
blob_type, oid.hash))
@@ -251,6 +251,7 @@ static int checkout_merged(int pos, const struct checkout *state)
251251
if (!ce)
252252
die(_("make_cache_entry failed for path '%s'"), path);
253253
status = checkout_entry(ce, state, NULL);
254+
free(ce);
254255
return status;
255256
}
256257

0 commit comments

Comments
 (0)