Link to home
Start Free TrialLog in
Avatar of jewee
jewee

asked on

getenv Crashes!

I noticed that when i use getenv to get a particular environment variable, the program crashes...

However, i wanted the environemnt variables to be optional.  So, if the env variables are not set, then use the default ones.

But when it's not defined, ...it shuts down.
Avatar of pankajtiwary
pankajtiwary

Hi jewee,
Please post the relevant part of the code so that we can go further.

Cheers!
Avatar of Axter
What OS and what compiler are you using?

I had a similar problem like this using GNU compiler on SunOS.
The problem was some where else in the code, but it would currupt the memory so that it would crash when calling getenv.
Avatar of jewee

ASKER

I call the getEnvVar method in the constructor...

bool ViewForm::getEnvVar()
{
   serverHostName = getenv("SERVER_HOSTNAME");
   if (serverHostName == NULL)
   {
        printf("Error\n");
        return false;
    }
}

I am running on a SunOS
ASKER CERTIFIED SOLUTION
Avatar of stefan73
stefan73
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is your constructor being called before entry into the main() function?
serverHostName is going to point to read-only memory. You don't do anything like accidentally free/deleting it or writing to it do you?