git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent van Ravesteijn <vfr@lyx.org>
To: git@vger.kernel.org
Cc: msysgit@googlegroups.com, gitster@pobox.com, kusmabite@gmail.com,
	Johannes.Schindelin@gmx.de, Vincent van Ravesteijn <vfr@lyx.org>
Subject: [PATCH 2/2] MSVC: Use _putenv instead of putenv to prevent a crash
Date: Sat, 19 Nov 2011 14:52:25 +0100	[thread overview]
Message-ID: <1321710745-2341-1-git-send-email-vfr@lyx.org> (raw)
In-Reply-To: <1321710345-2299-1-git-send-email-vfr@lyx.org>

Git crashes when trying to clear a nonexistent environment variable using
the putenv function. The crash occurs when freeing the option string. In
debug mode the assert "CrtIsValidHeapPointer" fails.

Using _putenv instead of putenv makes the crash and assert disappear.

Signed-off-by: Vincent van Ravesteijn <vfr@lyx.org>
---
The strange thing is that all over the internet people are claiming
that there is no difference between putenv and _putenv. Still, using
_putenv fixes the crash for me. 

If there is someone around who is more knowledgeable in this area,
please comment.

 compat/setenv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/compat/setenv.c b/compat/setenv.c
index 3a22ea7..b23937d 100644
--- a/compat/setenv.c
+++ b/compat/setenv.c
@@ -23,7 +23,7 @@ int gitsetenv(const char *name, const char *value, int replace)
 	memcpy(envstr + namelen + 1, value, valuelen);
 	envstr[namelen + valuelen + 1] = 0;
 
-	out = putenv(envstr);
+	out = _putenv(envstr);
 	/* putenv(3) makes the argument string part of the environment,
 	 * and changing that string modifies the environment --- which
 	 * means we do not own that storage anymore.  Do not free
-- 
1.7.4.1

  reply	other threads:[~2011-11-19 13:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-19 13:45 [PATCH 1/2] MSVC: Do not close stdout to prevent a crash Vincent van Ravesteijn
2011-11-19 13:52 ` Vincent van Ravesteijn [this message]
2011-11-19 14:41 ` Andreas Schwab
2011-11-19 19:11   ` Junio C Hamano
2011-11-19 20:16     ` Andreas Schwab
2011-11-20  3:27       ` Junio C Hamano
2011-11-20  9:05         ` Andreas Schwab
2011-11-20  9:27         ` [msysGit] " Johannes Sixt
2011-11-20 21:10           ` Junio C Hamano
2011-11-19 20:52     ` Vincent van Ravesteijn
2011-11-19 20:11 ` [msysGit] " Johannes Sixt
2011-11-22  6:45   ` Vincent van Ravesteijn
2011-11-22 20:24     ` Johannes Sixt
2011-11-22 21:27       ` Vincent van Ravesteijn

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=1321710745-2341-1-git-send-email-vfr@lyx.org \
    --to=vfr@lyx.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kusmabite@gmail.com \
    --cc=msysgit@googlegroups.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).