sim-card
/
qemu
Archived
10
0
Fork 0

os-posix: Plug fd leak in qemu_create_pidfile()

Spotted by Coverity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Markus Armbruster 2011-11-11 10:40:09 +01:00 committed by Anthony Liguori
parent 095ed5be7b
commit 1bbd1592c8
1 changed files with 3 additions and 0 deletions

View File

@ -372,13 +372,16 @@ int qemu_create_pidfile(const char *filename)
return -1;
}
if (lockf(fd, F_TLOCK, 0) == -1) {
close(fd);
return -1;
}
len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
if (write(fd, buffer, len) != len) {
close(fd);
return -1;
}
close(fd);
return 0;
}