From 1bacc536bb3ef013bc502937ee0d89ed32b253d7 Mon Sep 17 00:00:00 2001 From: relan Date: Sat, 19 Dec 2015 11:16:21 +0300 Subject: [PATCH] Fix clusters loss when file renaming replaces target. Add missing exfat_cleanup_node() call after exfat_unlink(). --- libexfat/node.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libexfat/node.c b/libexfat/node.c index d05f20d..4dd4dc6 100644 --- a/libexfat/node.c +++ b/libexfat/node.c @@ -1130,6 +1130,16 @@ int exfat_rename(struct exfat* ef, const char* old_path, const char* new_path) exfat_put_node(ef, existing); if (rc != 0) { + /* free clusters even if something went wrong; overwise they + will be just lost */ + exfat_cleanup_node(ef, existing); + exfat_put_node(ef, dir); + exfat_put_node(ef, node); + return rc; + } + rc = exfat_cleanup_node(ef, existing); + if (rc != 0) + { exfat_put_node(ef, dir); exfat_put_node(ef, node); return rc; -- 2.11.0