qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Igor Kovalenko" <igor.v.kovalenko@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] osdep.c fd leak fix
Date: Mon, 14 Aug 2006 20:53:58 +0400	[thread overview]
Message-ID: <b2fa41d60608140953u6a077d6fx3995789e6b343f01@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 123 bytes --]

Hi!

mkstemp() does open fd for us, no need to leak one file descriptor.
Please apply.

--
Kind Regards,
Igor V. Kovalenko

[-- Attachment #1.2: Type: text/html, Size: 152 bytes --]

[-- Attachment #2: osdep-fd-leak.diff --]
[-- Type: text/plain, Size: 1499 bytes --]

Index: osdep.c
===================================================================
RCS file: /cvsroot/qemu/qemu/osdep.c,v
retrieving revision 1.13
diff -u -r1.13 osdep.c
--- osdep.c	3 Aug 2006 17:53:19 -0000	1.13
+++ osdep.c	14 Aug 2006 16:48:39 -0000
@@ -120,7 +120,8 @@
         }
         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 @@
                     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;

                 reply	other threads:[~2006-08-14 16:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b2fa41d60608140953u6a077d6fx3995789e6b343f01@mail.gmail.com \
    --to=igor.v.kovalenko@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).