Buffer pointers randomly change

I currently have a non-threaded application, which has library calls that are called back from a single threaded caller library. Once a call is made, the caller thread is blocked from calling another library function. The caller library is a binary that is linked into the final executable. When this happens my memory buffers are randomly being overwritten with other data, causing my application to crash. I can put a write statement at the top of my callback library routine and it will randomly have a parameter value in it instead of the write string. This only occurs on PGF77 and does not happen on INTEL or on TRu64 5.1A or B. Can anyone shed any light on this issue ? I’m using PGF77 5.2-4 on a RHEL 4 update 2 platform.


Hi mantech_ajb,

Unfortunately, I can only speculate as to the cause. You should first try compiling your application and library with debugging information (-g). Next, use Valgrind (http://valgrind.org/) to find memory errors and/or PGDBG to step through your code to determine where and why the memory issue occurs.

  • Mat

I concur with Mat. These are classic symptoms of a memory use bug.

There are many possibilities, but a few that come to mind are:

  • if this is a mixed language application passing string data between C and Fortran, the conversion between zero-terminated and space padded strings is not being done correctly somewhere, causing C to run off the end of the Fortran string, etc. This often causes different results on different platforms since the app will seem to work if the executable happens to place a chunk of zeroed data after the storage for the string.
  • use of uninitialized data, especially sizes and counters
  • a function returning a pointer to space that’s allocated on the stack. This can work great or cause a wide array of pathologies
  • if your callbacks are firing frequently is that whatever reads the data is not synchronized so it can pick up data that’s in the process of being written.