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>
Johannes Schindelin committed
May 4, 2017 at 15:56 UTC
514e8039444565f7806e065579090167db5e489c
1 file changed
+9
-8
builtin/checkout.c
+9
-8
@@ -235,14 +235,14 @@ static int checkout_merged(int pos, const struct checkout *state)
235
/*
236
* NEEDSWORK:
237
* 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).
246
*/
247
if (write_sha1_file(result_buf.ptr, result_buf.size,
248
blob_type, oid.hash))
@@ -251,6 +251,7 @@ static int checkout_merged(int pos, const struct checkout *state)
251
if (!ce)
252
die(_("make_cache_entry failed for path '%s'"), path);
253
status = checkout_entry(ce, state, NULL);
254
+ free(ce);
255
return status;
256
}
257