#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
|  | 
| #define | TRIGGER(p)   if( (p) == DMtriggeraddr ) DMtrigger(); | 
|  | 
| #define | GUARD   0x73 | 
|  | 
| #define | MC68000 | 
|  | 
| #define | TABSIZE   (16*1024) | 
|  | 
| #define | HDRSIZE   (2 * sizeof (unsigned long)) | 
|  | 
|  | 
| static | malloced (char *ptr) | 
|  | record 'ptr's value in a list of malloc-ed memory 
 | 
|  | 
| static | freed (char *ptr, char *fname, int line) | 
|  | remove 'ptr's value from a list of malloc-ed memory - print error and die if it's not in the list at all. 
 | 
|  | 
| static char * | guardit (char *ptr, int size) | 
|  | Add guard word encoding size on start of memory area and a guard byte just past the end of the area.  More... 
 | 
|  | 
| static char * | memorycheck (char *ptr, char *fname, int line) | 
|  | Check the validity of allocated memory areas and report any problems.  More... 
 | 
|  | 
| char * | DMmemcheck (char *ptr, char *fname, int line) | 
|  | 
|  | DMfree (char *ptr, char *fname, int line) | 
|  | Free a pointer allocated by DMmalloc()  More... 
 | 
|  | 
| char * | DMmalloc (int size, char *fname, int line) | 
|  | Allocate memory safely using malloc()  More... 
 | 
|  | 
| char * | DMcalloc (int size, int nitems, char *fname, int line) | 
|  | Allocate memory safely using calloc()  More... 
 | 
|  | 
| char * | DMrealloc (char *ptr, int size, char *fname, int line) | 
|  | Reallocate memory safely using realloc()  More... 
 | 
|  | 
|  | DMnotfreed () | 
|  | Print a list of memory pointers not freed - one per line. 
 | 
|  | 
|  | DMtrigger () | 
|  | Dummy routine with the sole purpose of being available for setting breakpoints from a debugger. 
 | 
|  | 
|  | 
| int | DMverbose = 1 | 
|  | Verbosity level. 
 | 
|  | 
| char * | DMtriggeraddr = NULL | 
|  | 
| static char * | __memtab [TABSIZE] | 
|  | 
- Several global variables control actions taken by the memory check routines. These are provided also as a convenient interface to run-time debuggers.
- DMverbose (default = 1) 
 If != 0, each memory allocation/free is printed
- DMtriggeraddr (default = 0) 
 If != 0, then any allocation/free operation with
 a pointer argument or return == DMtrigger causes
 a message to be printed.
- DMtrigger() 
 Function is called whenever a trigger occurs for
 setting breakpoints in a debugger.
 
- Possible combinations:
- DMverbose = 0; DMtriggeraddr = 0x12345 
 Print messages only when 0x12345 is involved
- DMverbose = 0; DMtriggeraddr = 0 
 Print messages only when an error occurs
 
Definition in file DMalloc.c.
      
        
          | char* DMcalloc | ( | int | size, | 
        
          |  |  | int | nitems, | 
        
          |  |  | char * | fname, | 
        
          |  |  | int | line | 
        
          |  | ) |  |  | 
      
 
Allocate memory safely using calloc() 
- Parameters
- 
  
    | size | Size of single element |  | nitems | Total number of elements |  | fname | Source file name |  | line | Source line number |  
 
- Returns
- Pointer to new memory 
- Note
- Allocated pointer must be freed using DMfree() 
- See also
- DMmalloc() 
Definition at line 215 of file DMalloc.c.
 
 
      
        
          | DMfree | ( | char * | ptr, | 
        
          |  |  | char * | fname, | 
        
          |  |  | int | line | 
        
          |  | ) |  |  | 
      
 
Free a pointer allocated by DMmalloc() 
- Parameters
- 
  
    | ptr | Pointer to be freed |  | fname | Source file name |  | line | Source line number |  
 
Definition at line 150 of file DMalloc.c.
 
 
      
        
          | char* DMmalloc | ( | int | size, | 
        
          |  |  | char * | fname, | 
        
          |  |  | int | line | 
        
          |  | ) |  |  | 
      
 
Allocate memory safely using malloc() 
- Parameters
- 
  
    | size | Size to be allocated |  | fname | Source file name |  | line | Source line number |  
 
- Returns
- Pointer to new memory 
- Note
- Allocated pointer must be freed using DMfree() 
Definition at line 181 of file DMalloc.c.
 
 
      
        
          | char* DMmemcheck | ( | char * | ptr, | 
        
          |  |  | char * | fname, | 
        
          |  |  | int | line | 
        
          |  | ) |  |  | 
      
 
Check the validity of allocated memory areas and report any problems. 
Definition at line 128 of file DMalloc.c.
 
 
      
        
          | char* DMrealloc | ( | char * | ptr, | 
        
          |  |  | int | size, | 
        
          |  |  | char * | fname, | 
        
          |  |  | int | line | 
        
          |  | ) |  |  | 
      
 
Reallocate memory safely using realloc() 
- Parameters
- 
  
    | ptr | The pointer to be reallocated |  | size | New size |  | fname | Source file name |  | line | Source line number |  
 
- Returns
- Pointer to new memory 
- See also
- DMmemcheck() 
- 
guardit() 
Definition at line 303 of file DMalloc.c.
 
 
  
  | 
        
          | static char* guardit | ( | char * | ptr, |  
          |  |  | int | size |  
          |  | ) |  |  |  | static | 
 
Add guard word encoding size on start of memory area and a guard byte just past the end of the area. 
- Parameters
- 
  
  
- Returns
- pointer to user's area 
Definition at line 74 of file DMalloc.c.
 
 
  
  | 
        
          | static char* memorycheck | ( | char * | ptr, |  
          |  |  | char * | fname, |  
          |  |  | int | line |  
          |  | ) |  |  |  | static | 
 
Check the validity of allocated memory areas and report any problems. 
Called by DMmemcheck(). 
- Parameters
- 
  
    | ptr | Pointer to check |  | fname | Source file name for logging |  | line | Source line number for logging |  
 
Definition at line 97 of file DMalloc.c.