Problem with DB handles

This is a discussion on Problem with DB handles within the C Programming forums, part of the General Programming Boards category; Hi,
I'm using couple of Sybase stored procedure calls from my C program. If I comment any one of the ...

Look at the side effects of the Sybase call. Is there a contextual structure that is being changed as a result of the first call that must be reinitialized before the second call? A good place to start looking is at any structure that you pass to the Sybase calls that is shared between the two calls. Also look at any structures returned by the Sybase interface library.

- Compile the code with debug enabled.
- Run the program inside the debugger.

The debugger should catch the segfault, and provide you with a stack backtrace of the function call heirarchy at the point of the fault.

If malloc or free are in that list (which is a fairly common reason), then check all your usage of malloc and free to make sure you're not overstepping the end of allocated memory, using it after free, freeing twice, freeing what wasn't malloced etc etc.

You might also try say electric fence (if you have that)
gcc prog.c -lefence
And run that in the debugger as well. If you have a malloc overrun problem for example, that should trap the point where it happens (as opposed to the more normal case of noticing somethings wrong later on).