peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0168-block-Don-t-forget-to-delete-temporary-file.patch

5544c1
From 3306981d5631182fb1384b05d66be26918521511 Mon Sep 17 00:00:00 2001
5544c1
From: Dunrong Huang <riegamaths@gmail.com>
5544c1
Date: Wed, 5 Sep 2012 21:26:22 +0800
5544c1
Subject: [PATCH] block: Don't forget to delete temporary file
5544c1
5544c1
The caller would not delete temporary file after failed get_tmp_filename().
5544c1
5544c1
Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
5544c1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5544c1
(cherry picked from commit fe235a06e1e008dedd2ac3cc0a3a655169ce9b33)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 block.c | 6 +++++-
5544c1
 1 file changed, 5 insertions(+), 1 deletion(-)
5544c1
5544c1
diff --git a/block.c b/block.c
5544c1
index c754353..e78039b 100644
5544c1
--- a/block.c
5544c1
+++ b/block.c
5544c1
@@ -433,7 +433,11 @@ int get_tmp_filename(char *filename, int size)
5544c1
         return -EOVERFLOW;
5544c1
     }
5544c1
     fd = mkstemp(filename);
5544c1
-    if (fd < 0 || close(fd)) {
5544c1
+    if (fd < 0) {
5544c1
+        return -errno;
5544c1
+    }
5544c1
+    if (close(fd) != 0) {
5544c1
+        unlink(filename);
5544c1
         return -errno;
5544c1
     }
5544c1
     return 0;
5544c1
-- 
5544c1
1.7.12.1
5544c1