From: Fabien Chouteau Date: Mon, 7 Nov 2011 14:36:14 +0000 (+0100) Subject: Replace WriteFileEx with WriteFile in qemu_create_pidfile X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=bfc763fcfa80d89d31c4f801c2a82130dd92c708;p=qemu.git Replace WriteFileEx with WriteFile in qemu_create_pidfile The function that writes pidfile for win32 uses WriteFileEx which is an asynchronous IO function. The arguments given to WriteFileEx are allocated on the stack and one of them is "in out". When the IO operation is actually executed the calling function has already returned, so the arguments are no longer allocated or allocated to another frame. Reviewed-by: Paolo Bonzini Signed-off-by: Fabien Chouteau Signed-off-by: Anthony Liguori --- diff --git a/os-win32.c b/os-win32.c index 79094016f1..8ad5fa1fc3 100644 --- a/os-win32.c +++ b/os-win32.c @@ -130,14 +130,15 @@ int qemu_create_pidfile(const char *filename) memset(&overlap, 0, sizeof(overlap)); file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (file == INVALID_HANDLE_VALUE) { return -1; } len = snprintf(buffer, sizeof(buffer), "%d\n", getpid()); - ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len, - &overlap, NULL); + ret = WriteFile(file, (LPCVOID)buffer, (DWORD)len, + NULL, &overlap); + CloseHandle(file); if (ret == 0) { return -1; }