fd leak fix (Igor Kovalenko)
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
Thu, 17 Aug 2006 16:19:07 +0000 (16:19 +0000)
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
Thu, 17 Aug 2006 16:19:07 +0000 (16:19 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2118 c046a42c-6fe2-441c-8c8c-71466251a162

osdep.c

diff --git a/osdep.c b/osdep.c
index 348fcf2..1a4c036 100644 (file)
--- a/osdep.c
+++ b/osdep.c
@@ -120,7 +120,8 @@ void *kqemu_vmalloc(size_t size)
         }
         snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX", 
                  tmpdir);
-        if (mkstemp(phys_ram_file) < 0) {
+        phys_ram_fd = mkstemp(phys_ram_file);
+        if (phys_ram_fd < 0) {
             fprintf(stderr, 
                     "warning: could not create temporary file in '%s'.\n"
                     "Use QEMU_TMPDIR to select a directory in a tmpfs filesystem.\n"
@@ -128,18 +129,13 @@ void *kqemu_vmalloc(size_t size)
                     tmpdir);
             snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX", 
                      "/tmp");
-            if (mkstemp(phys_ram_file) < 0) {
+            phys_ram_fd = mkstemp(phys_ram_file);
+            if (phys_ram_fd < 0) {
                 fprintf(stderr, "Could not create temporary memory file '%s'\n", 
                         phys_ram_file);
                 exit(1);
             }
         }
-        phys_ram_fd = open(phys_ram_file, O_CREAT | O_TRUNC | O_RDWR, 0600);
-        if (phys_ram_fd < 0) {
-            fprintf(stderr, "Could not open temporary memory file '%s'\n", 
-                    phys_ram_file);
-            exit(1);
-        }
         unlink(phys_ram_file);
     }
     size = (size + 4095) & ~4095;