Reputation:

How to fix memory access error

I am working on a migration project, here we are migrating large set of C++ libraries from Mainframe to Solaris. We have complted migration sucessfully, but while running the application, some places it crashes with 'signal SEGV (no mapping at the fault address)'.

Since the application supports on windows also, we checked with purify on windows. There are no memory leaks in the application and it works fine on windows.

Can any one suggests, what could be the other reasons which may create this type of errors. Any tools for tracing this type of errors?

Upvotes: 0

Views: 1454

Answers (4)

hamishmcn
hamishmcn

Reputation: 7981

The line below looks wrong to me

m_BindMap[sLabel] = b;   // crashes at this line at when map size

I assume you are trying to add a number to the end of the string. Try this instead

stringstream ss;
ss << ":BIND" << ns;
string sLabel = ss.str();

Upvotes: 1

Reputation:

I am using CC compiler on solaris and dbx debugger. I know the call stack where it is crashing. But it is abromal crash.

map<string,CDBBindParam,less<string> >m_BindMap;



CNumString ns(CNumStringTraits(0,2,'0'));
ns = m_BindMap.size();
string sLabel = ":BIND"+ns;
CDBBindParam b(sLabel,val);
**m_BindMap[sLabel] = b;**   // crashes at this line at when map size is more than 2
return sLabel;

Upvotes: 0

PolyThinker
PolyThinker

Reputation: 5218

It's not necessarily a memory leak. It could be that a piece of memory is referenced after it is free'ed.

My friend once came to me with a piece of code that runs fine on Windows but gives segv on Linux. It turned out that sometimes the memory is still valid after you free'ed it on Windows (probably for a short period of time) but immediately triggered segv on Linux.

Upvotes: 1

eduffy
eduffy

Reputation: 40232

Are you using g++? If so, recompile with the "-g" flag. Run the program in gdb. When it crashes type "bt" (for backtrace) and that should tell you where your problem is.

Upvotes: 0

Related Questions