]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
block: Don't forget to delete temporary file
authorDunrong Huang <riegamaths@gmail.com>
Wed, 5 Sep 2012 13:26:22 +0000 (21:26 +0800)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Fri, 12 Oct 2012 02:44:16 +0000 (21:44 -0500)
The caller would not delete temporary file after failed get_tmp_filename().

Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit fe235a06e1e008dedd2ac3cc0a3a655169ce9b33)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
block.c

diff --git a/block.c b/block.c
index c754353ac6bbb90b9d71f36133216abb88698d70..e78039bd5a089380d29b9305c99b7ad1e6a163d2 100644 (file)
--- a/block.c
+++ b/block.c
@@ -433,7 +433,11 @@ int get_tmp_filename(char *filename, int size)
         return -EOVERFLOW;
     }
     fd = mkstemp(filename);
-    if (fd < 0 || close(fd)) {
+    if (fd < 0) {
+        return -errno;
+    }
+    if (close(fd) != 0) {
+        unlink(filename);
         return -errno;
     }
     return 0;