[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [Qemu-devel] [PATCH] os-win32.c : fix memory leak

From: Mark
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] os-win32.c : fix memory leak
Date: Thu, 24 Nov 2011 17:15:30 +0800

If you free the string, it will cause the environment variable unavailable.  More details please see the following text extracted from manual of "putenv":

       The  libc4  and  libc5  and  glibc 2.1.2 versions conform to SUSv2: the pointer string given to putenv() is used.  In particular, this
       string becomes part of the environment; changing it later will change the environment.  (Thus, it is an error is to call putenv() with
       an automatic variable as the argument, then return from the calling function while string is still part of the environment.)  However,
       glibc 2.0-2.1.1 differs: a copy of the string is used.  On the one hand this causes a memory leak, and on the other hand  it  violates
       SUSv2.  This has been fixed in glibc 2.1.2.

2011/11/24 Zhi Hui Li <address@hidden>
string is allocated by g_malloc, will not be used after putenv, should be free before return.

Signed-off-by: Li Zhi Hui <address@hidden>
 os-win32.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index 8ad5fa1..e6e9143 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -44,6 +44,7 @@ int setenv(const char *name, const char *value, int overwrite)
         char *string = g_malloc(length);
         snprintf(string, length, "%s=%s", name, value);
         result = putenv(string);
+        g_free(string);
     return result;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]