Introduction
The usual implementation of malloc and free are unforgiving to errors in their callers' code, including cases where the programmer overflows an array, forgets to free memory, or frees a memory block twice. This often does not affect the program immediately, waiting until the corrupted memory is used later (in the case of overwrites) or gradually accumulating allocated but unused blocks. Thus, debugging can be extremely difficult.
In this assignment, you will write a wrapper for the malloc package that will catch errors in the code that calls malloc and free. The skills you will have learned upon the completion of this exercise are pointer arithmetic and a greater understanding of the consequences of subtle memory mistakes.
Logistics
Unzip debugging_malloc.zip into an empty directory. The files contained are as follows:
File(s): Function:
debugmalloc.c Contains the implementation of the three functions you will be writing. This is the one file you will be editing and handing in.
debugmalloc.h Contains the declaration of the functions, as well as the macros that will call them.
driver.c Contains main procedure and the code that will be calling the functions in the malloc package
dmhelper.c, dmhelper.h Contain the helper functions and macros that you will be calling from your code
grader.pl Perl script that runs your code for the various test cases and gives you feedback based on your current code
debugmalloc.dsp Exercise 3 project file
debugmalloc.dsw Exercise 3 workspace file
tailor.h, getopt.c, getopt.h Tools that are used only by the driver program for I/O purposes. You will not need to know what the code in these files do.
Others
Required by Visual C++. You do not need to understand their purpose
Specification
Programs that use this package will call the macros MALLOC and FREE. MALLOC and FREE are used exactly the same way as the malloc() and free() functions in the standard C malloc package. That is, the li