|
From: | Paolo Bonzini |
Subject: | Re: [Qemu-trivial] [PATCH] os-win32.c : fix memory leak |
Date: | Fri, 25 Nov 2011 09:56:14 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 |
On 11/24/2011 08:28 PM, Stefan Weil wrote:
MS claims that putenv is a POSIX function, so I also expected that free / f_free is not allowed. I now wrote a short test which indicates that g_free would work: getenv returns a pointer which is completely different from the one passed to putenv.
Confirmed by http://source.winehq.org/source/dlls/msvcrt/environ.c. It makes a copy of the string, passes it to SetEnvironmentVariable, and frees the copy. So Windows never even sees the string passed to putenv.
The reason for the dance is that: 1) the underlying Win32 APIs require separate arguments for the variable and value; 2) even though in the end Wine stores the environment as name=value (http://source.winehq.org/source/dlls/ntdll/env.c), it does so in a single consecutive block of memory, not as a char* array like POSIX does. While (2) might apply only to Wine, (1) surely applies to Windows as well.
Stefan, can you add some of the info to the commit message? Reviewed-by: Paolo Bonzini <address@hidden>
[Prev in Thread] | Current Thread | [Next in Thread] |