1827786 Members
3222 Online
109969 Solutions
New Discussion

Re: SIGBUS problem

 
Rohan_4
New Member

SIGBUS problem

Hi,

I am having problem running my application written in C on HP-UX 11.
The process gets SIGBUS error after call to function (f1). The back trace of core file recursively shows caller 'f1' function.
There is no memory corruption or such error before call to f1.
What could be the problem here?
Does memory allocation from cause this problem?

Thanks
Rohan
4 REPLIES 4
Deepak Extross
Honored Contributor

Re: SIGBUS problem

Well, if you're getting a SIGBUS there definitely is some kind of problem somewhere.
Some things to look for:
1. Using a pointer that hasn't been initialised - trying to read/write to an invalid or NULL memory address.
2. Improper pointer arithmetic - for example, accessing *ptr [a]+1 instead of *ptr[a+1]
3. Overflowing arrays.

Rational's purify is a good tool to locate these kind of errors. Alternatively, recompile your code with the +g and without the -O option (make sure you don't strip the exe after compiling) and then use a good debugger like gdb to figure out where the problem lies.
Rajeev  Shukla
Honored Contributor

Re: SIGBUS problem

Hi Rohan,
You'll have to go though your ptogram more closely. Likely chances are that a unintilized pointer is being used. That might be that you havent allocated any memory for a pointer.

Cheers
Rajeev
Adam J Markiewicz
Trusted Contributor

Re: SIGBUS problem

Hi

One more comment. There is one more situation extremally difficult to debug, very often not mentioned: using deallocated memory.
Consider code:

{
char *buffer = malloc( BUFFER_SIZE );

free( buffer );

/***/

/* do something with buffer (!!!) */
}

This very rarelly generates SIGSEGV! Why?
Memory management doesn't return every piece of memory back to the system immediatelly. Instead it keaps a track of free memory blocks for reuse. So the memory from the system's point of view is allocated.
However for managing free memory lists you need a memory (at least to write pointers for the blocks). But there is no problem - we have a memory that is to be deallocated - why not to use it?
Concluding - freed memory is not deallocated, but collected into free blocks list for reusage. This memory IS USED by memory manager INTERNALLY. If you destroy it you won't be rejected by the system, as from it's point of view everything is OK. But it is likelly that your next try to allocate memory, while checking free blocks, will end on block with destroyed internal data and then - everything can happen.

Check it very carefully.

Good luck

Adam
I do everything perfectly, except from my mistakes
Rohan_4
New Member

Re: SIGBUS problem

Hi,

Thanks a lot for your reply/suggestions.
Actualy, I traced down the cause of problem to a local variable in 'f1'. It is a char str[128][1024].
When I reduced 'str' to str[10][1024], the application started working.
What I am wondering is, instead of getting stack overflow why am I getting SIGBUS error?
Any clues regarding this?

Even though I increased the maxssiz to 32MB, the str[128][1K] gave problem.

Also, is there way to find current usage of stack?

Thanks
Rohan