segmantation Fault error SEGV_MAPERR - Address not mapped to object


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 06-03-2009
segmantation Fault error SEGV_MAPERR - Address not mapped to object

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 .
# 2  
Old 06-04-2009
Code tags for code please. They make it readable. [ code ] stuff [ /code ] without the extra spaces in the tags.

Posting a member function out of context is pretty pointless since a class is bound to contain member variables of which we have no knowledge, could you please post the complete code for this class, including header, in code tags?

Compiling your executable with debugging support, and running it in a debugger, may tell you what line this segfault is happening on. The gcc flag for this is -ggdb, and the GNU tool for debugging is gdb, I am not certain what HP-UX specific tools there are for this.
# 3  
Old 06-04-2009
Thanks for reply .
I have changed parametrs to this function from string * to char *
getConfigValue is function in class CConfigReader
Code:
CConfigReader .c
 
#include "CConfigReader.h"
using namespace std;
CConfigReader::CConfigReader()
{}
CConfigReader::CConfigReader(char *paramConfigpath)
{
memset(szConfigPath, ' ', sizeof( szConfigPath) );
memcpy(szConfigPath,paramConfigpath,sizeof( szConfigPath));
}
int CConfigReader::GetConfigValue(char *paramApp,int paramKey,char *ResultValue)
{
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
string *pstrSplit=NULL;
int iNumWords =split(buffer, pstrSplit);
if(iNumWords != -1)
{
if (pstrSplit[0].compare(paramApp)!=0)
{

continue;
}
else
{

strcpy(ResultValue,pstrSplit[paramKey].c_str()); 
break;
}
}
else
{
cout << "Error in reading the line "<<endl;
return 1;
}

}
else
{
cout << "header line ignore it "<<endl;

}
}
else
{
cout << "empty line ignore it "<<endl;
}
}//end of while 
}
else
{
cout << "unable to open the stream ";
return 1;
}
Stream.close();
return 0; 
}
int CConfigReader::split(string strInput, string *&pstrResult)
{
// Reserve some memory, WATCH OUT! USER NEEDS TO FREE THE MEMORY!
if(pstrResult != NULL)
return -1; // We need a clean buffer, we could shoose to delete the inside,
else
pstrResult = new string[1];
string strTemp;
int iInputLen = strInput.length(), iNumWords = 0;
if(iInputLen)
{
for(int i = 0; i < iInputLen; i++)
{
if((strInput[i] == ' ') && (!strTemp.empty())) // Split it if there is a word.
{
if(iNumWords > 0)
{
string *pstrTempRes = new string[iNumWords];
CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
delete[] pstrResult;
pstrResult = new string[iNumWords+1];
CopyBuffer(pstrResult, pstrTempRes, iNumWords);
pstrResult[iNumWords] = strTemp;
delete[] pstrTempRes;
iNumWords++;
}
else
{
pstrResult[iNumWords] = strTemp;
iNumWords++;
}
strTemp.erase(); //- Erase the temp-string, and start over.
i++; // SKIP THE SPACE!
}
strTemp += strInput[i];
}
if(strTemp.length() > 0)
{
if(iNumWords > 0)
{
string *pstrTempRes = new string[iNumWords];
CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
delete[] pstrResult;
pstrResult = new string[iNumWords+1];
CopyBuffer(pstrResult, pstrTempRes, iNumWords);
pstrResult[iNumWords] = strTemp;
delete[] pstrTempRes;
iNumWords++;
}
else
{
pstrResult[iNumWords] = strTemp;
iNumWords++;
}
}
}
return iNumWords;
}
void CConfigReader::CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen)
{
for(int i = 0; i < iDynamicLen; i++)
 
{
pstrDest[i] = pstrSource[i];
}
}

Code:
CConfigReader.h
 
#include <iostream>
#include <istream>
#include <fstream>
#include <istream>
#include <string>
#include <stdio.h>
using namespace std;
class CConfigReader
{
public:
char szConfigPath[100];
CConfigReader();
CConfigReader(char *paramConfigpath );
int GetConfigValue(char *paramApp,int paramKey,char *ResultValue);
private:
int split(string strInput, string *&pstrResult);
void CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen);
};

function call is as folllows
Code:
char szLogDir[ MAX_PATH ];
enum AppConfig {AppName=0,Server,Port,LogDir};
 
AppConfig enLogDir=LogDir;
CConfigReader config =CConfigReader(szConfigFile);
if (! config.GetConfigValue("MMSYNCH",enLogDir,szLogDir))
{
printf("sucessfully executed function \n");

}
else
{ 
printf("Error in reading the file \n" );
exit ;
}

Thanks
# 4  
Old 06-04-2009
Code:
CConfigReader .c
 
#include "CConfigReader.h"
using namespace std;
CConfigReader::CConfigReader()
{}

CConfigReader::CConfigReader(char *paramConfigpath)
{
  memset(szConfigPath, ' ', sizeof( szConfigPath) );
  memcpy(szConfigPath,paramConfigpath,sizeof( szConfigPath));
}
int CConfigReader::GetConfigValue(char *paramApp,int paramKey,char *ResultValue)
{
  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
          string *pstrSplit=NULL;
          int iNumWords =split(buffer, pstrSplit);
          if(iNumWords != -1)
          {
            if (pstrSplit[0].compare(paramApp)!=0)
            {
              continue;
            }
            else
            {
              strcpy(ResultValue,pstrSplit[paramKey].c_str()); 
              break;
            }
          }
          else
          {
            cout << "Error in reading the line "<<endl;
            return 1;
          }
        }
        else
        {
          cout << "header line ignore it "<<endl;
        }
      }
      else
      {
        cout << "empty line ignore it "<<endl;
      }
    }//end of while 
  }
  else
  {
    cout << "unable to open the stream ";
    return 1;
  }

  Stream.close();
  return 0; 
}

int CConfigReader::split(string strInput, string *&pstrResult)
{
  // Reserve some memory, WATCH OUT! USER NEEDS TO FREE THE MEMORY!
  if(pstrResult != NULL)
    return -1; // We need a clean buffer, we could shoose to delete the inside,
  else
    pstrResult = new string[1];

  string strTemp;
  int iInputLen = strInput.length(), iNumWords = 0;

  if(iInputLen)
  {
    for(int i = 0; i < iInputLen; i++)
    {
      if((strInput[i] == ' ') && (!strTemp.empty())) // Split it if there is a word.
      {
        if(iNumWords > 0)
        {
          string *pstrTempRes = new string[iNumWords];
          CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
          delete[] pstrResult;
          pstrResult = new string[iNumWords+1];
          CopyBuffer(pstrResult, pstrTempRes, iNumWords);
          pstrResult[iNumWords] = strTemp;
          delete[] pstrTempRes;
          iNumWords++;
        }
        else
        {
          pstrResult[iNumWords] = strTemp;
          iNumWords++;
        }

        strTemp.erase(); //- Erase the temp-string, and start over.
        i++; // SKIP THE SPACE!
      }

      strTemp += strInput[i];
    }

    if(strTemp.length() > 0)
    {
      if(iNumWords > 0)
      {
        string *pstrTempRes = new string[iNumWords];
        CopyBuffer(pstrTempRes, pstrResult, iNumWords); // Make a deep copy of the buffer.
        delete[] pstrResult;
        pstrResult = new string[iNumWords+1];
        CopyBuffer(pstrResult, pstrTempRes, iNumWords);
        pstrResult[iNumWords] = strTemp;
        delete[] pstrTempRes;
        iNumWords++;
      }
      else
      {
        pstrResult[iNumWords] = strTemp;
        iNumWords++;
      }
    }
  }
  return iNumWords;
}

void CConfigReader::CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen)
{
  for(int i = 0; i < iDynamicLen; i++)
  {
    pstrDest[i] = pstrSource[i];
  }
}

Code:
CConfigReader.h
 
#include <iostream>
#include <istream>
#include <fstream>
#include <istream>
#include <string>
#include <stdio.h>

using namespace std;

class CConfigReader
{
public:
  char szConfigPath[100];
  CConfigReader();
  CConfigReader(char *paramConfigpath );
  int GetConfigValue(char *paramApp,int paramKey,char *ResultValue);
private:
  int split(string strInput, string *&pstrResult);
  void CopyBuffer(string *pstrDest, string *pstrSource, int iDynamicLen);
};

function call is as folllows
Code:
char szLogDir[ MAX_PATH ];
enum AppConfig {AppName=0,Server,Port,LogDir};
 
AppConfig enLogDir=LogDir;
CConfigReader config =CConfigReader(szConfigFile);
if (! config.GetConfigValue("MMSYNCH",enLogDir,szLogDir))
{
  printf("sucessfully executed function \n");
}
else
{ 
  printf("Error in reading the file \n" );
  exit ;
}

I'll take a closer look at this in a bit, had to fix the indentation first.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Python-rrdtool try except rrdtool.error module object has no attribute error kaf3773 Shell Programming and Scripting 1 10-21-2015 05:21 AM
Segmentation Fault ERROR in C DinisR Programming 3 10-20-2015 06:39 AM
How to initialize an object with another object of different class? techmonk Programming 1 01-29-2014 01:55 PM
Object not found error for mediawiki Puvi Red Hat 0 05-08-2013 09:54 PM
Signal SEGV (no mapping at the fault address) in _memcpy at 0xff0b07c0 gthangav Programming 9 01-16-2013 12:42 AM
Error: Memory fault(coredump) EngnrRG AIX 2 05-19-2011 07:48 AM
Error while running shared object yatrik007 Programming 3 01-26-2011 08:16 AM
signal SEGV (no mapping at the fault address) mumuri UNIX for Dummies Questions & Answers 4 04-20-2010 04:10 AM
help with C++ code that relate the object with physical address silviafisica Programming 1 08-20-2009 06:18 AM
Object reference not set to an instance of an object EddiRae UNIX for Dummies Questions & Answers 0 07-06-2009 01:57 PM
Panic kernal-mode address fault on user address 0x14 Twix UNIX for Dummies Questions & Answers 10 06-15-2009 10:42 AM
Error Mismatched object file mysmileforu Linux 2 02-03-2009 11:58 PM
signal SEGV (no mapping at the fault address) in _malloc_unlocked at 0xfe1d44ac noufal UNIX for Dummies Questions & Answers 1 03-13-2008 09:13 AM
Object File Error Stevhp Programming 3 03-08-2007 04:20 AM
Printer Error(the Object Instance Test Does Not Exist) jav_v UNIX for Advanced & Expert Users 2 09-23-2002 11:42 PM