* [Qemu-devel] [PATCH] osdep.c fd leak fix
@ 2006-08-14 16:53 Igor Kovalenko
0 siblings, 0 replies; only message in thread
From: Igor Kovalenko @ 2006-08-14 16:53 UTC (permalink / raw)
To: qemu-devel
[-- 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-08-14 16:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-14 16:53 [Qemu-devel] [PATCH] osdep.c fd leak fix Igor Kovalenko
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).