Commit 243a273ee0168fc373f342479ae92fe3028b45c1

Authored by bellard
1 parent c3d78997

fd leak fix (Igor Kovalenko)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2118 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 4 additions and 8 deletions
... ... @@ -120,7 +120,8 @@ void *kqemu_vmalloc(size_t size)
120 120 }
121 121 snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
122 122 tmpdir);
123   - if (mkstemp(phys_ram_file) < 0) {
  123 + phys_ram_fd = mkstemp(phys_ram_file);
  124 + if (phys_ram_fd < 0) {
124 125 fprintf(stderr,
125 126 "warning: could not create temporary file in '%s'.\n"
126 127 "Use QEMU_TMPDIR to select a directory in a tmpfs filesystem.\n"
... ... @@ -128,18 +129,13 @@ void *kqemu_vmalloc(size_t size)
128 129 tmpdir);
129 130 snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
130 131 "/tmp");
131   - if (mkstemp(phys_ram_file) < 0) {
  132 + phys_ram_fd = mkstemp(phys_ram_file);
  133 + if (phys_ram_fd < 0) {
132 134 fprintf(stderr, "Could not create temporary memory file '%s'\n",
133 135 phys_ram_file);
134 136 exit(1);
135 137 }
136 138 }
137   - phys_ram_fd = open(phys_ram_file, O_CREAT | O_TRUNC | O_RDWR, 0600);
138   - if (phys_ram_fd < 0) {
139   - fprintf(stderr, "Could not open temporary memory file '%s'\n",
140   - phys_ram_file);
141   - exit(1);
142   - }
143 139 unlink(phys_ram_file);
144 140 }
145 141 size = (size + 4095) & ~4095;
... ...