diff mbox

[3/3] xl: create: close restore_fd_to_close on error

Message ID 1455717855-2344-3-git-send-email-ian.campbell@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Campbell Feb. 17, 2016, 2:04 p.m. UTC
Currently the fd is opened and then later closed and
restore_fd_to_close set back to -1, however there are several goto out
and goto error_out paths in the interim.

Since the code resets restore_fd_to_close to -1 it is OK to check this
and close on the out path too.

CID: 1055897

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/libxl/xl_cmdimpl.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Ian Jackson Feb. 19, 2016, 4:04 p.m. UTC | #1
Ian Campbell writes ("[PATCH 3/3] xl: create: close restore_fd_to_close on error"):
> Currently the fd is opened and then later closed and
> restore_fd_to_close set back to -1, however there are several goto out
> and goto error_out paths in the interim.
> 
> Since the code resets restore_fd_to_close to -1 it is OK to check this
> and close on the out path too.
> 
> CID: 1055897

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

And queued for push.

Ian.
diff mbox

Patch

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 7ba40c0..514f5a8 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3069,6 +3069,13 @@  error_out:
     }
 
 out:
+    if (restore_fd_to_close >= 0) {
+        if (close(restore_fd_to_close))
+            fprintf(stderr, "Failed to close restoring file, fd %d, errno %d\n",
+                    restore_fd_to_close, errno);
+        restore_fd_to_close = -1;
+    }
+
     if (logfile != 2)
         close(logfile);