Detecting and reporting errors

QNX SDP8.0Programmer's GuideDeveloper

The primary goal for detecting heap corruption problems is to correctly identify the source of errors and fix them to avoid getting faults in the allocator at some later time.

The first step to achieving this goal is to create an allocator that can determine whether the heap is corrupted on every entry into the allocator, whether it's for an allocation request or for a release request. For example, on a release request, the allocator should be capable of determining whether:
  • the pointer given to it is valid
  • the associated block's header is corrupt
  • either of the neighboring blocks is corrupt

To detect heap corruption, we provide a replacement library for the standard allocator that can keep additional block information in the header of every heap buffer. You can use this replacement library, which is implemented by the librcheck.so shared object and referred to simply as librcheck, while testing an application to help isolate any heap corruption problems.

When this allocator detects a source of heap corruption, it can print an error message indicating:
  • the point at which the error was detected
  • the program location that made the request
  • information about the heap buffer that contained the problem

The library technique can be refined to also detect some sources of errors that may still elude detection, such as memory overruns or underruns, that occur before the corruption is detected by the allocator. This may be done when the standard libraries are the vehicle for the heap corruption, such as an errant call to memcpy(). In librcheck, the standard memory manipulation functions and string functions are replaced with versions that use the information in this library to determine if their arguments reside in the heap and if they would cause the bounds of the heap buffer to be exceeded. Under these conditions, the functions can then call the error-reporting functions to provide information about the source of the error.

Page updated: