fd leak fix (Igor Kovalenko)

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2118 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
bellard 2006-08-17 16:19:07 +00:00
parent c3d78997a3
commit 243a273ee0

12
osdep.c
View File

@ -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;