Program received signal SIGSEGV, Segmentation fault
si_code: 1 - SEGV_MAPERR - Address not mapped to object.
0x9fffffffbe7080d0:0 in free+0xb0 () from /usr/lib/hpux64/libc.so.1
Hi ,
I have developed a class to read config file (flat file with space as a field seperator ) on plattform HP-UX B.11.23 IA 64 .
I am passing pointers to strings to a function which reads the config file and traverse line by line and retrieves value on the basis of key passed as parameter . I am getting above error .when i call this function more than once. First time call works fine but second time it fails with above error.
Please see code of the function
:
int CConfigReader::GetConfigValue(char *paramApp,string *ResultServer,string * ResultPort,string *ResultLogDir)
{
ifstream Stream (szConfigPath);
if (Stream.is_open())
{
while(!Stream.eof())
{
string buffer=NULL;
getline(Stream, buffer);
if(buffer.length() !=0)
{
if (buffer.find('#') == string::npos)
{
//ingnore the line header
printf("\n the red is %s \n",buffer);
string *pstrSplit=NULL;
int iNumWords =split(buffer, pstrSplit);
if(iNumWords != -1)
{
if (pstrSplit[0].compare(paramApp)!=0)
{
continue;
}
else
{
*ResultServer=pstrSplit[1];
*ResultPort=pstrSplit[2];
*ResultLogDir=pstrSplit[3];
printf("\n Serve-- %s Port --%s Log Directory --%s \ n",*ResultServer,*ResultPort,*ResultLogDir);
delete[] pstrSplit;
break;
}
}
else
{
cout << "Error in reading the line ";
return 1;
}
}
else
{
cout << "header line ignore it ";
}
}
else
{
cout << "empty line ignore it ";
}
}//end of while
}
else
{
cout << "unable to open the stream ";
return 1;
}
Stream.close();
return 0;
}
function call :
string tempServer;
string tempPort;
string tempLogDir;
// Install the SAP RFC functions that can be called.
CConfigReader config =CConfigReader(szConfigFile);
if (! config.GetConfigValue("MMSYNCH",&tempServer,&tempPort,&tempLogDir))
{
printf("sucessfully executed function \n");
printf("result MMSYNCH server is--> %s Port is --> %s log dir is -->%s \n",tempServer,tempPort,tempLogDir);
nPort=atoi(tempPort.c_str());
strcpy(szServer, tempServer.c_str());
strcpy(szLogDir, tempLogDir.c_str());
}
else
{
ErrorExit( table[0].ithandle, "Error in reading config file", errno);
}
Please help me in resolviong this error .