From: Eric Blake Date: Wed, 11 May 2011 15:51:30 +0000 (-0600) Subject: tests: avoid crash when run under gcov X-Git-Tag: CVE-2011-2178~258 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70ea7decbed7678a3e9a4114af1c1b412ba8071d;p=thirdparty%2Flibvirt.git tests: avoid crash when run under gcov Running ./autobuild.sh failed when gcov is installed, because commandtest ended up crashing during gcov's getenv() call after exit() had already started. I traced this nasty bug back to a scoping issue present since the test introduction. * tests/commandtest.c (mymain): Move newenv... (newenv): ...to a scope that is still useful during exit(). --- diff --git a/tests/commandtest.c b/tests/commandtest.c index caad69832a..6757253526 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -748,6 +748,18 @@ cleanup: return ret; } +static const char *const newenv[] = { + "PATH=/usr/bin:/bin", + "HOSTNAME=test", + "LANG=C", + "HOME=/home/test", + "USER=test", + "LOGNAME=test" + "TMPDIR=/tmp", + "DISPLAY=:0.0", + NULL +}; + static int mymain(void) { @@ -771,17 +783,6 @@ mymain(void) virInitialize(); - const char *const newenv[] = { - "PATH=/usr/bin:/bin", - "HOSTNAME=test", - "LANG=C", - "HOME=/home/test", - "USER=test", - "LOGNAME=test" - "TMPDIR=/tmp", - "DISPLAY=:0.0", - NULL - }; environ = (char **)newenv; # define DO_TEST(NAME) \