Memory Violation Trapping
Original Publication Date: 1996-Aug-01
Included in the Prior Art Database: 2005-Mar-31
Memory Violations are difficult to trace and fix, and may "live" in software for a long time, reducing software performance, especially in statistical programs.
Memory Violation Trapping
Violations are difficult to trace and fix, and may
"live" in software for a long time, reducing software performance,
especially in statistical programs.
method permits the provision of simple software
which taps memory violations, reducing debugging time, and increasing
software performance. The software referred to hereafter as Memory
Violation Trapping (MVT) provides the following essential elements:
1. All allocations and frees are performed using the MVT
software. The MVT uses the regular allocation system
but adds the following elements
2. MVT marks each allocation in an Allocation Table (AT),
including all information required for tracing the
violation and giving the programmer all information,
such as variable name, size, location, etc..
3. MVT adds for each allocated memory area a Safety Prefix
and Suffix Padding Areas (PSSA).
4. MVT initializes the PSSA padding to a Specific Value (SV)
(or to a specific sequence of values).
5. MVT supplies optional reports of the Allocation Table (AT).
6. When free is being executed for an allocated area, MVT
erases it from AT while checking its PSSA. If the PSSA
does not have the SV value, a violation has occurred and
an error message is printed.
7. MVT traces double free of a variable.
8. MVT, when freeing a variable, sets its pointer to
NULL to avoid further access to the freed areas.
The PSSA area
provides prefix and suffix padding for each
allocated variable which is initialized by MVT to a SV (not zero, for
trace violation when initializing zeros to a variable) "travels" with
the allocated variable through all program stages, but is never
touched by the program. When freeing this variable, MVT checks that
this padding is set to its original setting (SV) value. In addition,
the use of the AT for handling the allocated variables list enables
duplication of free allocations to be avoided and provides
information on violation when trapped.
MVT to trap violations between program variables,
and report the exact location of violations in code. The Operating
system traps violations only when memory page (memory segments) are
affected. "Small" violations (within program memory page) are
The following main.c program contains three types of
1. Suffix violation (setting of bigger area than allocated
2. Prefix violation (setting negative index on array).
3. Double free violation (which may free undesired areas).
All of the
above may cause unexpected errors in a
program. This main.c was compiled using the IBM*-C2 compiler. When
executed, no violation was detected by the system (program finished
without segmentation fault).