OSDN Git Service

Fix clusters loss when file renaming replaces target.
authorrelan <relan@users.noreply.github.com>
Sat, 19 Dec 2015 08:16:21 +0000 (11:16 +0300)
committerrelan <relan@users.noreply.github.com>
Sat, 19 Dec 2015 08:16:21 +0000 (11:16 +0300)
Add missing exfat_cleanup_node() call after exfat_unlink().

libexfat/node.c

index d05f20d..4dd4dc6 100644 (file)
@@ -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;