FOSSology  4.4.0
Open Source License Compliance by Open Source Software
DMalloc.c File Reference
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for DMalloc.c:

Go to the source code of this file.

Macros

#define TRIGGER(p)   if( (p) == DMtriggeraddr ) DMtrigger();
 
#define GUARD   0x73
 
#define MC68000
 
#define TABSIZE   (16*1024)
 
#define HDRSIZE   (2 * sizeof (unsigned long))
 

Functions

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)
 Check the validity of allocated memory areas and report any problems.
 
 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.
 

Variables

int DMverbose = 1
 Verbosity level.
 
char * DMtriggeraddr = NULL
 
static char * __memtab [TABSIZE]
 

Detailed Description

  • 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.

Function Documentation

◆ DMcalloc()

char* DMcalloc ( int  size,
int  nitems,
char *  fname,
int  line 
)

Allocate memory safely using calloc()

Parameters
sizeSize of single element
nitemsTotal number of elements
fnameSource file name
lineSource line number
Returns
Pointer to new memory
Note
Allocated pointer must be freed using DMfree()
See also
DMmalloc()

Definition at line 203 of file DMalloc.c.

◆ DMfree()

DMfree ( char *  ptr,
char *  fname,
int  line 
)

Free a pointer allocated by DMmalloc()

Parameters
ptrPointer to be freed
fnameSource file name
lineSource line number

Definition at line 138 of file DMalloc.c.

◆ DMmalloc()

char* DMmalloc ( int  size,
char *  fname,
int  line 
)

Allocate memory safely using malloc()

Parameters
sizeSize to be allocated
fnameSource file name
lineSource line number
Returns
Pointer to new memory
Note
Allocated pointer must be freed using DMfree()

Definition at line 169 of file DMalloc.c.

◆ DMrealloc()

char* DMrealloc ( char *  ptr,
int  size,
char *  fname,
int  line 
)

Reallocate memory safely using realloc()

Parameters
ptrThe pointer to be reallocated
sizeNew size
fnameSource file name
lineSource line number
Returns
Pointer to new memory
See also
DMmemcheck()
guardit()

Definition at line 291 of file DMalloc.c.

◆ guardit()

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
prtPointer to guard
size
Returns
pointer to user's area

Definition at line 62 of file DMalloc.c.

◆ memorycheck()

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
ptrPointer to check
fnameSource file name for logging
lineSource line number for logging

Definition at line 85 of file DMalloc.c.