| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

mem_assert_

#include "sflmem.h"
void
mem_assert_ (
    const char *filename,               /*  Name of source file making call  */
    size_t lineno                       /*  Line number in calling source    */
)

Synopsis

Checks that all allocated memory was freed. Use the mem_assert macro to call this function! If any memory is still left allocated, displays the memory list on stderr and aborts. Generally we use this function at the end of a program, after deallocating all memory. If any memory has not been allocated, we get a nice list and an abort. Our principle is that any memory allocation must be matched by a free somewhere in the code.

Source Code - (sflmem.c)

{
    FILE
        *trace_file;

    if (mem_total != 0
    ||  !list_empty (&tr_list))
      {
        fflush  (stdout);
        fprintf (stderr, "Clean-memory assertion failed - %s (%ld)\n",
                          filename? filename: "<Unknown>", (long) lineno);
        fprintf (stderr, "Details are in memtrace.lst\n");
        trace_file = fopen ("memtrace.lst", "w");
        mem display (trace_file);
        fclose (trace_file);
        abort ();
      }
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation