From: Stefan Hajnoczi <stefanha@gmail.com>
To: Mark <wudx05@gmail.com>
Cc: qemu-trivial@nongnu.org, Zhi Hui Li <zhihuili@linux.vnet.ibm.com>,
qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] os-win32.c : fix memory leak
Date: Thu, 24 Nov 2011 10:27:12 +0000 [thread overview]
Message-ID: <20111124102712.GA27170@stefanha-thinkpad.localdomain> (raw)
In-Reply-To: <CAOfR6VHZHvcp-808F5n2NPv4E_zUjeToNBjx_2FyM+Wjb+oY5A@mail.gmail.com>
On Thu, Nov 24, 2011 at 05:15:30PM +0800, Mark wrote:
> 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.
I don't think this matters since os-win32.c is only built for mingw,
which uses the Microsoft C runtime and not glibc.
However, there is no documentation for putenv(3) on MSDN because the
function has been deprecated :(. So I think the safest thing to do is
to assume this will leak memory but we are not allowed to free the
string.
Either you could investigate the new _putenv(3) and test the Windows
build to make sure it works. Or you could send a patch that adds a
comment explaining why there is a memory leak here.
Stefan
next prev parent reply other threads:[~2011-11-24 10:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-24 8:27 [Qemu-devel] [PATCH] os-win32.c : fix memory leak Zhi Hui Li
2011-11-24 9:15 ` Mark
2011-11-24 10:27 ` Stefan Hajnoczi [this message]
2011-11-24 19:28 ` [Qemu-devel] [Qemu-trivial] " Stefan Weil
2011-11-24 20:46 ` Stefan Weil
2011-11-25 8:56 ` Paolo Bonzini
2011-11-28 10:49 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111124102712.GA27170@stefanha-thinkpad.localdomain \
--to=stefanha@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=wudx05@gmail.com \
--cc=zhihuili@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).