From 075d64ebb85a4c4ac6c47622a2f0bb6a36f16824 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 13 May 2013 21:09:18 -0500 Subject: [PATCH] do_overlay(): Correctly revert changes --- src/update_image.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/update_image.c b/src/update_image.c index 7247b1c0..a6bad2aa 100644 --- a/src/update_image.c +++ b/src/update_image.c @@ -48,6 +48,7 @@ do_overlay(struct wim_dentry *target, struct wim_dentry *branch) } rb_root = &branch->d_inode->i_children; + LIST_HEAD(moved_children); while (rb_root->rb_node) { /* While @branch has children... */ struct wim_dentry *child = rbnode_dentry(rb_root->rb_node); struct wim_dentry *existing; @@ -61,12 +62,17 @@ do_overlay(struct wim_dentry *target, struct wim_dentry *branch) int ret; ret = do_overlay(existing, child); if (ret) { - /* Overlay failed. Revert the change to avoid - * leaking the directory tree rooted at @child. - * */ + /* Overlay failed. Revert the changes. */ dentry_add_child(branch, child); + list_for_each_entry(child, &moved_children, tmp_list) + { + unlink_dentry(child); + dentry_add_child(branch, child); + } return ret; } + } else { + list_add(&child->tmp_list, &moved_children); } } free_dentry(branch); -- 2.43.0