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().
This commit is contained in:
Eric Blake 2011-05-11 09:51:30 -06:00
parent ba13a37cff
commit 70ea7decbe

View File

@ -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) \