0

I have following code that is working fine in my development environment but when the code is moved to production server it give oracle "Heap Consistency Error". Can you please let me know how to debug this and reason for this?

if (TagValue[TagTable[TagLoc].Ptr2ValueTable].repetitionOutValue.length==-1)
{
                TagValue[TagTable[TagLoc].Ptr2ValueTable].repetitionOutValue.value
     = (char*) malloc (*CurLen+1)   ;
}
else
{
             more_val2 = (char*) realloc (TagValue[TagTable[TagLoc].Ptr2ValueTable].repetitionOutValue.value
             , (strlen(TagValue[TagTable[TagLoc].Ptr2ValueTable].repetitionOutValue.value)+(*CurLen)) * sizeof(char));

      if (more_val2!=NULL) 
      {
      TagValue[TagTable[TagLoc].Ptr2ValueTable].repetitionOutValue.value=more_val2;
      } 
  }
QMG
  • 719
  • 2
  • 7
  • 16
  • thank you for reply.code is added. Please note every variable is initialized – QMG Apr 19 '12 at 15:40
  • 1
    I'm sorry but I have no idea what your code is trying to do... – Nick Apr 19 '12 at 16:17
  • let me just give a brief idea if first condition meet then malloc memory for first time. If memory is already allocated then it is a repeated case so realloc the memory – QMG Apr 19 '12 at 16:29

1 Answers1

1

Check program with Valgrind.

As oracle say for this implementation-defined status:

Code    Condition               Oracle Error
82111   heap consistency error  SQL-02111
  • Heap consistency error

  • This internal error typically indicates a memory-related error.

  • Check the program for memory-related errors, such as invalid pointers or array-bounds violations.

Tho; If this is a huge code never ran trough any checks - I do not envy you the task ahead.

The heap, here, is an area of memory reserved for dynamic variables.

Excessive heap validation is also a runtime option enabled by ORAHCHF. If set tells the Oracle runtime library to check the heap for consistency every time the precompiler dynamically allocates or frees memory.

Must be set before CONNECT and once set, cannot be cleared. Defaults to 0/off.

You also do a redundant cast on malloc. Perhaps you cast, etc., somewhere else where development vs production environment has an effect. I.e. 32 vs 64 bit.

  • On malloc you malloc CurLen + 1
  • On your realloc you do not add an extra 1 (for '\0' ?).

If this is an issue depends on what you do with the repetitionOut.value afterwards.

strlen() does not count the terminating \0.

Community
  • 1
  • 1
Morpfh
  • 4,033
  • 18
  • 26
  • Thank you Rune for your reply. I have added +1 but still getting the consistency error. When I run the single instance of program it works fine. But when I run 4 instances then this consistency issue raised – QMG Apr 20 '12 at 09:51
  • What environment? Linux + GCC or? – Morpfh Apr 20 '12 at 14:08