<!-- This HTML file has been created by texi2html 1.4 on 16 November 1998 -->

<TITLE>Debug Malloc Library</TITLE>
<H1>Debug Malloc Library</H1>
<P>
Version 4.1.1 -- November 1998
<P>
<A NAME="IDX1"></A>
<A NAME="IDX2"></A>
<P>
The debug memory allocation or <DFN>dmalloc</DFN> library has been designed
as a drop in replacement for the system's <CODE>malloc</CODE>, <CODE>realloc</CODE>,
<CODE>calloc</CODE>, <CODE>free</CODE> and other memory management routines while
providing powerful debugging facilities configurable at runtime.  These
facilities include such things as memory-leak tracking, fence-post write
detection, file/line number reporting, and general logging of
statistics.
<P>
The library is reasonably portable having been run successfully on at
least the following operating systems: AIX, BSDI, DG/UX, FreeBSD, HPUX,
Irix, Linux, MS-DOG, NeXT, OSF, SCO, Solaris, SunOS, Ultrix, Unixware,
Windoze and even Unicos on a Cray Y-MP.  It also provides support for
the debugging of threaded programs.  See section <A HREF="dmalloc.html#SEC30">Using the Library with a Thread Package</A>.
<P>
The package includes the library, configuration scripts, debug utility
application, test program, and extensive documentation (formats: text,
texi, info, and ps).  Documentation is available online at URL
<CODE>http://www.letters.com/dmalloc/</CODE>.
<P>
The library is available via ftp from <SAMP>ftp.letters.com</SAMP> in the
<TT>/src/dmalloc</TT> directory.  See section <A HREF="dmalloc.html#SEC11">How to get the library.</A>.  I can be reached via
my web page <SAMP>http://www.letters.com/~gray/</SAMP> with any questions or
feedback.  Please include the version number of the library that you are
using as well as your machine and operating system types.
<P>
Gray Watson.
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC1">Copying</A>: Library copying and licensing conditions.
<LI><A HREF="dmalloc.html#SEC6">Overview</A>: Description of features and how to get started.
<LI><A HREF="dmalloc.html#SEC14">Details</A>: Details about how to use the library.
<LI><A HREF="dmalloc.html#SEC31">Source Code</A>: Information on the source and general concerns.
<LI><A HREF="dmalloc.html#SEC35">Plugs</A>: A couple soapbox comments.
<LI><A HREF="dmalloc.html#SEC36">Index of Concepts</A>: Index of concepts in the manual.
<LI><A HREF="dmalloc.html#SEC37">Full Node Listing</A>: Listing of all the nodes in the manual.
</UL>
<P>
<H1><A NAME="SEC1" HREF="dmalloc_toc.html#SEC1">Library Copying and Licensing Conditions</A></H1>
<P>
<A NAME="IDX3"></A>
<A NAME="IDX4"></A>
<A NAME="IDX5"></A>
<A NAME="IDX6"></A>
<P>
Copyright 1992 to 1998 by Gray Watson.
<P>
Gray Watson makes no representations about the suitability of the
software described herein for any purpose.  It is provided ``as is''
without express or implied warranty.  The name of Gray Watson cannot be
used in advertising or publicity pertaining to distribution of the
document or software without specific, written prior permission.
<P>
Permission to distribute this software for any purpose without fee is
hereby granted, provided that the above copyright notice, all
documentation files associated with the software, and this permission
chapter appear in all copies.
<P>
Please see the following sections for usage permissions.
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC2">Non-Commercial License</A>: Permissions for non-commercial entities.
<LI><A HREF="dmalloc.html#SEC3">Commercial License</A>: Permissions for commercial entities.
<LI><A HREF="dmalloc.html#SEC4">Printed Manuals</A>: Printed/bound manuals and source floppies.
<LI><A HREF="dmalloc.html#SEC5">Registration Information</A>: Permissions for commercial entities.
</UL>
<P>
<H2><A NAME="SEC2" HREF="dmalloc_toc.html#SEC2">Non-Commercial License</A></H2>
<P>
<A NAME="IDX7"></A>
<P>
Permission to use, copy, and modify this software for any
<EM>academic</EM> or <EM>non-commercial</EM> purpose without fee is hereby
granted.
<P>
Although only commercial users are required to license the software,
<EM>all</EM> registrations are greatly appreciated.  Licensees get a
registration file for the software (which cannot be distributed), a
letter documenting their registered status, as well as product support
and notification of free-upgrades.  For more information about
registration see the following section.  See section <A HREF="dmalloc.html#SEC3">Commercial License</A>.
<P>
<H2><A NAME="SEC3" HREF="dmalloc_toc.html#SEC3">Commercial License</A></H2>
<P>
<A NAME="IDX8"></A>
<A NAME="IDX9"></A>
<P>
In order to fund maintenance and continued development of this product,
the requirement has been added that commercial entities license the
software for a nominal fee.  There is a thirty (30) day free evaluation
period but if your organization uses the software after this time period
expires, please consider purchasing a registered copy.  This allows me
to provide better support as well as bug fixes and feature updates on a
more frequent basis.  Although not required, academic or non-commercial
user registration is greatly appreciated.
<P>
A licensed copy of the software is available for US$35.  Commercial
entities should purchase one license per workstation, or one per dmalloc
user, whichever is the smaller number.  Licensees get a registration
file for the software (which cannot be distributed), a letter
documenting their registered status, as well as product support and
notification of free-upgrades.
<P>
For ``site'' licenses (at significant discount) or any other reasonable
agreements, please contact me directly.  It should be noted that a
``site'' can be defined as anything you'd like.  It can be a physical
location (a room, building, etc.), an organizational grouping (a
workgroups, department, etc.) or any other logical grouping (``the folks
working on the widget project'', etc.).
<P>
<H2><A NAME="SEC4" HREF="dmalloc_toc.html#SEC4">Printed Manuals</A></H2>
<P>
<A NAME="IDX10"></A>
<A NAME="IDX11"></A>
<P>
A printed and bound copy of the manual is available for US$15.  A copy
of the software on a Unix tar floppy is available for US$15.
International shipping costs outside of the US or Canada, please add
US$5 for the extra postal charges.
<P>
<H2><A NAME="SEC5" HREF="dmalloc_toc.html#SEC5">Registration Information</A></H2>
<P>
<A NAME="IDX12"></A>
<P>
Please include the following registration information with your check
made out to ``Gray Watson''.  Money orders are also accepted.  Purchase
orders are as well, although amounts less than US$50 are discouraged.
<P>
<UL>
<LI>Name
<LI>Position
<LI>Company/Organization
<LI>Street Address
<LI>City
<LI>State/Prov/Pref
<LI>Zip/Postal Code
<LI>Country
<LI>Email-Address
<LI>Telephone and Fax Number
</UL>
<P>
Send it along with any other correspondence that cannot be sent via
email to:
<P>
<PRE>
Gray Watson
826 Savannah Ave.
Pittsburgh, PA  15221-3446
USA
</PRE>
<P>
<H1><A NAME="SEC6" HREF="dmalloc_toc.html#SEC6">How to Debug with the Library</A></H1>
<P>
<A NAME="IDX13"></A>
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC7">Allocation Basics</A>: Basic description of terms and functions.
<LI><A HREF="dmalloc.html#SEC10">Features</A>: The general features of the library.
<LI><A HREF="dmalloc.html#SEC11">How To Get</A>: How to get the library.
<LI><A HREF="dmalloc.html#SEC12">Installation</A>: How to install the library.
<LI><A HREF="dmalloc.html#SEC13">Getting Started</A>: Getting started with the library.
</UL>
<P>
<H2><A NAME="SEC7" HREF="dmalloc_toc.html#SEC7">Allocation Basics: Terms and Functions</A></H2>
<P>
<A NAME="IDX14"></A>
<A NAME="IDX15"></A>
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC8">Basic Definitions</A>: General memory terms and concepts.
<LI><A HREF="dmalloc.html#SEC9">Malloc Functions</A>: Functionality supported by all malloc libs.
</UL>
<P>
<H3><A NAME="SEC8" HREF="dmalloc_toc.html#SEC8">Basic Concept Definitions</A></H3>
<P>
<A NAME="IDX16"></A>
<A NAME="IDX17"></A>
<P>
Any program can be divided into 2 logical parts: text and data.  Text is
the actual program code in machine-readable format and data is the
information that the text operates on when it is executing.  The data,
in turn, can be divided into 3 logical parts according to where it is
stored: <DFN>static</DFN>, <DFN>stack</DFN>, and <DFN>heap</DFN>.
<P>
<A NAME="IDX18"></A>
<P>
Static data is the information whose storage space is compiled into the
program.
<P>
<PRE>
/* global variables are allocated as static data */
int numbers[10];
<P>
main()
{
        ...
}
</PRE>
<P>
<A NAME="IDX19"></A>
<P>
Stack data is data allocated at run-time to hold information used inside
of functions.  This data is managed by the system in the space called
stack space.
<P>
<PRE>
void foo()
{
        /* this local variable is stored on the stack */
        float total;
        ...
}
<P>
main()
{
        foo();
}
</PRE>
<P>
<A NAME="IDX20"></A>
<P>
Heap data is also allocated at run-time and provides a programmer with
dynamic memory capabilities.
<P>
<PRE>
main()
{
        /* the address is stored on the stack */
        char * string;
        ...
<P>
        /*
         * Allocate a string of 10 bytes on the heap.  Store the
         * address in string which is on the stack.
         */
        string = (char *)malloc(10);
        ...
<P>
        /* de-allocate the heap memory now that we're done with it */
        (void)free(string);
        ...
}
</PRE>
<P>
It is the heap data that is managed by this library.
<P>
Although the above is an example of how to use the malloc and free
commands, it is not a good example of why using the heap for run-time
storage is useful.
<P>
Consider this: You write a program that reads a file into memory,
processes it, and displays results.  You would like to handle files with
arbitrary size (from 10 bytes to 1.2 megabytes and more).  One problem,
however, is that the entire file must be in memory at one time to do the
calculations.  You don't want to have to allocate 1.2 megabytes when you
might only be reading in a 10 byte file because it is wasteful of system
resources.  Also, you are worried that your program might have to handle
files of more than 1.2 megabytes.
<P>
A solution: first checkout the file's size and then, using the
heap-allocation routines, get enough storage to read the entire file
into memory.  The program will only be using the system resources
necessary for the job and you will be guaranteed that your program can
handle any sized file.
<P>
<H3><A NAME="SEC9" HREF="dmalloc_toc.html#SEC9">Malloc Library Functions</A></H3>
<P>
<A NAME="IDX21"></A>
<P>
All malloc libraries support 4 basic memory allocation commands.  These
include <DFN>malloc</DFN>, <DFN>calloc</DFN>, <DFN>realloc</DFN>, and <DFN>free</DFN>.  For
more information about their capabilities, check your system's manual
pages -- in unix, do a <CODE>man 3 malloc</CODE>.
<P>
void *malloc ( unsigned int <VAR>size</VAR> )
<A NAME="IDX22"></A>
<P>
Usage: <CODE>pnt = (type *)malloc(size)</CODE>
<P>
The malloc routine is the basic memory allocation routine.  It allocates
an area of <CODE>size</CODE> bytes.  It will return a pointer to the space
requested.
<P>
void *calloc ( unsigned int <VAR>number</VAR>, unsigned int
<VAR>size</VAR> )
<A NAME="IDX23"></A>
<A NAME="IDX24"></A>
<A NAME="IDX25"></A>
<P>
Usage: <CODE>pnt = (type *)calloc(number, size)</CODE>
<P>
The calloc routine allocates a certain <CODE>number</CODE> of items, each of
<CODE>size</CODE> bytes, and returns a pointer to the space.  It is
appropriate to pass in a <CODE>sizeof(type)</CODE> value as the size argument.
<P>
Also, calloc nulls the space that it returns, assuring that the memory
is all zeros.
<P>
void *realloc ( void *<VAR>old_pnt</VAR>, unsigned int
<VAR>new_size</VAR> )
<A NAME="IDX26"></A>
<P>
Usage: <CODE>new_pnt = (type *)realloc(old_pnt, new_size)</CODE>
<P>
The realloc function expands or shrinks the memory allocation in
<CODE>old_pnt</CODE> to <CODE>new_size</CODE> number of bytes.  Realloc copies as
much of the information from <CODE>old_pnt</CODE> as it can into the
<CODE>new_pnt</CODE> space it returns, up to <CODE>new_size</CODE> bytes.  If there
is a problem allocating this memory, 0L will be returned.
<P>
If the <CODE>old_pnt</CODE> is 0L then realloc will do the equivalent of a
<CODE>malloc(new_size)</CODE>.  If <CODE>new_size</CODE> is 0 and <CODE>old_pnt</CODE> is
not 0L, then it will do the equivalent of <CODE>free(old_pnt)</CODE> and will
return 0L.
<P>
void free ( void *<VAR>pnt</VAR> )
<A NAME="IDX27"></A>
<P>
Usage: <CODE>free(pnt)</CODE>
<P>
The free routine releases allocation in <CODE>pnt</CODE> which was returned by
malloc, calloc, or realloc back to the heap.  This allows other parts of
the program to re-use memory that is not needed anymore.  It guarantees
that the process does not grow too big and swallow a large portion of
the system resources.
<P>
<EM>NOTE</EM>: the returned address from the memory
allocation/reallocation functions should <EM>always</EM> be cast to the
appropriate pointer type for the variable being assigned.
<P>
<EM>WARNING</EM>: there is a quite common myth that all of the space that
is returned by malloc libraries has already been cleared.  <EM>Only</EM>
the <CODE>calloc</CODE> routine will zero the memory space it returns.
<P>
<H2><A NAME="SEC10" HREF="dmalloc_toc.html#SEC10">Features of the Library</A></H2>
<P>
<A NAME="IDX28"></A>
<P>
The debugging features that are available in this debug malloc library
can be divided into a couple basic classifications:
<P>
<DL COMPACT>
<DT> file and line number information
<DD><A NAME="IDX29"></A>
<A NAME="IDX30"></A>
One of the nice things about a good debugger is its ability to provide
the file and line number of an offending piece of code.  This library
attempts to give this functionality with the help of <DFN>cpp</DFN>, the C
preprocessor.  See section <A HREF="dmalloc.html#SEC16">Allocation Macros</A>.
<P>
<DT> return-address information
<DD><A NAME="IDX31"></A>
To debug calls to the library from external sources (i.e. those files
that could not use the allocation macros), some facilities have been
provided to supply the caller's address.  This address, with the help of
a debugger, can help you locate the source of a problem.  See section <A HREF="dmalloc.html#SEC17">Return Address Information</A>.
<P>
<DT> fence-post (i.e. bounds) checking
<DD><A NAME="IDX32"></A>
<A NAME="IDX33"></A>
<A NAME="IDX34"></A>
<DFN>Fence-post</DFN> memory is the area immediately above or below memory
allocations.  It is all too easy to write code that accesses above or
below an allocation -- especially when dealing with arrays or strings.
The library can write special values in the areas around every
allocation so it will notice when these areas have been overwritten.
See section <A HREF="dmalloc.html#SEC29">Diagnosing Fence-Post Overwritten Memory</A>.
<P>
<EM>NOTE</EM>: The library cannot notice when the program <EM>reads</EM>
from these areas, only when it writes values.  Also, fence-post checking
will increase the amount of memory the program allocates.
<P>
<DT> heap-constancy verification
<DD><A NAME="IDX35"></A>
The administration of the library is reasonably complex.  If any of the
heap-maintenance information is corrupted, the program will either crash
or give unpredictable results.
<P>
By enabling heap-consistency checking, the library will run through its
administrative structures to make sure all is in order.  This will mean
that problems will be caught faster and diagnosed better.
<P>
The drawback of this is, of course, that the library often takes quite a
long time to do this.  It is suitable to enable this only during
development and debugging sessions.
<P>
<EM>NOTE</EM>: the heap checking routines cannot guarantee that the tests
will not cause a segmentation-fault if the heap administration
structures are properly (or improperly if you will) overwritten.  In
other words, the tests will verify that everything is okay but may not
inform the user of problems in a graceful manner.
<P>
<DT> logging statistics
<DD><A NAME="IDX36"></A>
<A NAME="IDX37"></A>
<A NAME="IDX38"></A>
<A NAME="IDX39"></A>
One of the reasons why the debug malloc library was initially developed
was to track programs' memory usage -- specifically to locate
<DFN>memory leaks</DFN> which are places where allocated memory is never
getting freed.  See section <A HREF="dmalloc.html#SEC28">Tracking down Non-Freed Memory</A>.
<P>
The library has a number of logging capabilities that can track un-freed
memory pointers as well as run-time memory usage, memory transactions,
administrative actions, and final statistics.
<P>
<DT> examining unfreed memory
<DD><A NAME="IDX40"></A>
<A NAME="IDX41"></A>
Another common problem happens when a program frees a memory pointer but
goes on to use it again by mistake.  This can lead to mysterious crashes
and unexplained problems.
<P>
To combat this, the library can write special values into a block of
memory after it has been freed.  This serves two purposes: it will make
sure that the program will get garbage data if it trying to access the
area again, and it will allow the library to verify the area later for
signs of overwriting.
</DL>
<P>
If any of the above debugging features detect an error, the library will
try to recover.  If logging is enabled then an error will be logged with
as much information as possible.
<P>
The error messages that the library displays are designed to give the
most information for developers.  If the error message is not
understood, then it is most likely just trying to indicate that a part
of the heap has been corrupted.
<P>
<A NAME="IDX42"></A>
<A NAME="IDX43"></A>
The library can be configured to quit immediately when an error is
detected and to dump a core file or memory-image.  This can be examined
with a debugger to determine the source of the problem.  The library can
either stop after dumping core or continue running.
<P>
<A NAME="IDX44"></A>
<A NAME="IDX45"></A>
<EM>NOTE</EM>: do not be surprised if the library catches problems with
your system's routines.  It took me hours to finally come to the
conclusion that the localtime call, included in SunOS release 4.1,
overwrites one of its fence-post markers.
<P>
<H2><A NAME="SEC11" HREF="dmalloc_toc.html#SEC11">How to get the library.</A></H2>
<P>
<A NAME="IDX46"></A>
<A NAME="IDX47"></A>
<P>
<DL COMPACT>
<DT> Standard Repository:
<DD><P>
The newest versions of the dmalloc library are available via anonymous
ftp from <SAMP>ftp.letters.com</SAMP> in the <TT>/src/dmalloc</TT> directory.
<P>
<A NAME="IDX48"></A>
<A NAME="IDX49"></A>
<P>
To use anonymous ftp, you ftp to the site and when the system prompts
you for a login-id or username you enter <KBD>anonymous</KBD>.  When it
prompts you for a password you enter your email address.  You then can
change-directory (cd) into <TT>/src/dmalloc</TT> and get the <TT>README</TT>
and <TT>dmalloc.tar.gz</TT> files.
<P>
The versions in this repository include such stuff as a postscript
version of the manual and other large files which may not have been
included in the distribution you received.
<P>
</DL>
<P>
<H2><A NAME="SEC12" HREF="dmalloc_toc.html#SEC12">Installation of the Library</A></H2>
<P>
<A NAME="IDX50"></A>
<A NAME="IDX51"></A>
<A NAME="IDX52"></A>
<A NAME="IDX53"></A>
<A NAME="IDX54"></A>
<P>
To configure, compile, and install the library, follow these steps
carefully.
<P>
<OL>
<P>
<A NAME="IDX55"></A>
<P>
<LI>First, please examine the <TT>PERMISSIONS</TT> file.  If you are using
the library in a commercial setting, please consider paying for a
licensed copy of the software.
<P>
<A NAME="IDX56"></A>
<P>
<LI>You probably will want to edit the settings in
<TT>settings.dist</TT> to tune specific features of the library.  The
below <TT>configure</TT> script will copy this file to <TT>settings.h</TT>
which is where you should be adding per-architecture settings.
<P>
<A NAME="IDX57"></A>
<A NAME="IDX58"></A>
<P>
<LI>Type <KBD>sh ./configure</KBD> to configure the library.  You may want
to first examine the <TT>config.help</TT> file for some information about
configure.  Configure should generate the <TT>Makefile</TT> and some
configuration files automatically.
<P>
<EM>NOTE</EM>: It seems that some versions of tr (especially from HP-UX)
don't understand <CODE>tr '[a-z]' '[A-Z]'</CODE>.  Since configure uses tr
often, you may need to either get GNU's tr (in their textutils package)
or generate the <TT>Makefile</TT> and <TT>conf.h</TT> files by hand.
<P>
<LI>You may want to examine the <TT>Makefile</TT> and <TT>conf.h</TT> files
created by configure to make sure it did its job correctly.
<P>
<A NAME="IDX59"></A>
<P>
<LI>You might want to tune the settings in <TT>settings.h</TT> file to
tune the library to the local architecture.  This file contains relevant
settings if you are using pthreads or another thread library.  The
<TT>configure</TT> script created this file from the <TT>settings.dist</TT>
file.  Any permanent changes to these settings should made to the dist
file.  You then can run <TT>config.status</TT> to re-create the
<TT>settings.h</TT> file.
<P>
<A NAME="IDX60"></A>
<P>
<LI>The <CODE>DMALLOC_SIZE</CODE> variable gets auto-configured in
<TT>dmalloc.h.2</TT> but it may not generate correct settings for all
systems.  You may have to alter the definitions in this file to get
things to stop complaining when you go to compile about the size
arguments to malloc routines.  Comments on this please.
<P>
<LI>Typing <KBD>make</KBD> should be enough to build <TT>libdmalloc.a</TT>,
<TT>libdmalloclp.a</TT>, and <TT>dmalloc</TT> program.  If it does not work,
please see if there are any notes in the contrib directory about your
system-type.  If not and you figure your problem out, please send me
some notes so future users can profit from your experiences.
<P>
<EM>NOTE</EM>: You may experience some errors compiling some of the
return.h assembly macros which attempt to determine the callers address
for logging purposes.  You may want to first try disabling any compiler
optimization flags.  If this doesn't work then you may need to disable
the <SAMP>USE_RET_ADDRESS</SAMP> variable in the <TT>settings.h</TT> file.
<P>
<A NAME="IDX61"></A>
<A NAME="IDX62"></A>
<P>
<EM>NOTE</EM>: The code is pretty dependent on a good ANSI-C compiler.  If
the configure script gives the <SAMP>WARNING</SAMP> that you do not have an
ANSI-C compiler, you may still be able to add some sort of option to
your compiler to make it ANSI.  If there such is an option, please send
it to the author so it can be added to the configure script.  Otherwise,
you will have to try <KBD>make noansi</KBD>.  This will run the
<TT>Deansify.pl</TT> perl script on the code which:
<P>
<UL>
<LI><EM>WARNING</EM>: modifies the source code in place
<LI>changes <TT>stdarg.h</TT> and <CODE>...</CODE> to <TT>varargs.h</TT> and
<CODE>va_alist</CODE>
<LI>changes all <CODE>void *</CODE> references to <CODE>char *</CODE>.
<LI>fixes all functions to remove <CODE>foo(char * var)</CODE> declarations.
</UL>
<P>
If it doesn't work you may have to do Deansify.pl's job by hand.
<P>
<LI>If you use threads, typing <KBD>make threads</KBD> should be enough
to build <TT>libdmallocth.a</TT> which is the threaded version of the
library.  This may or may not work depending on the configuration
scripts ability to detect your local thread functionality.  Feel free to
send me mail with improvements.
<P>
See the ``Using With Threads'' section for more information about the
operation of the library with your threaded program.  See section <A HREF="dmalloc.html#SEC30">Using the Library with a Thread Package</A>.
<P>
<LI>See the <TT>dmalloc.cc</TT> C++ file which contains basic code to
overload the <CODE>new</CODE>, <CODE>new[]</CODE>, and <CODE>delete</CODE> C++ operators.
You may want to compile and include this object file in the dmalloc
libraries.  My apologies on the minimal C++ support.  I am still living
in a mostly C world.
<P>
<A NAME="IDX63"></A>
<A NAME="IDX64"></A>
<P>
<LI>Typing <KBD>make tests</KBD> should build the <TT>dmalloc_t</TT> test
program.
<P>
<LI>Typing <KBD>make light</KBD> should run the <TT>dmalloc_t</TT> test
program through a set of light trials.  By default this will execute
<TT>dmalloc_t</TT> 5 times -- each time will execute 10,000 malloc
operations in a very random manner.  Anal folks can type <KBD>make
heavy</KBD> to up the ante.  Use <KBD>dmalloc_t --usage</KBD> for the list of all
<TT>dmalloc_t</TT> options.
<P>
<LI>Typing <KBD>make install</KBD> should install the <TT>libdmalloc.a</TT>
and <TT>libdmalloc_lp.a</TT> library files in <TT>/usr/local/lib</TT>, the
<TT>dmalloc.h</TT> include file in <TT>/usr/local/include</TT>, and the
<TT>dmalloc</TT> utility in <TT>/usr/local/bin</TT>.  You may also want to
type <KBD>make installth</KBD> to install the thread libraries into place.
<P>
You may have specified a <SAMP>--prefix=PATH</SAMP> option to configure in
which case <SAMP>/usr/local</SAMP> will have been replaced with <SAMP>PATH</SAMP>.
<P>
</OL>
<P>
See the ``Getting Started'' section to get up and running with the
library.  See section <A HREF="dmalloc.html#SEC13">Getting Started with the Library</A>.
<P>
<EM>NOTE</EM>: This library has never been (and maybe never will be)
optimized for space nor speed.  in fact, some of its features make it
unable to use some of the organizational methods of other more efficient
heap libraries.
<P>
<H2><A NAME="SEC13" HREF="dmalloc_toc.html#SEC13">Getting Started with the Library</A></H2>
<P>
<A NAME="IDX65"></A>
<A NAME="IDX66"></A>
<A NAME="IDX67"></A>
<A NAME="IDX68"></A>
<A NAME="IDX69"></A>
<A NAME="IDX70"></A>
<P>
This section should give you a quick idea on how to get going.
Basically, you need to do the following things to make use of the
library:
<P>
<OL>
<P>
<LI>Make sure you have the latest version of the library.  It is
available via anonymous ftp from <SAMP>ftp.letters.com</SAMP> in the
<TT>/src/dmalloc</TT> directory.  See section <A HREF="dmalloc.html#SEC11">How to get the library.</A>.
<P>
<LI>Please examine the <TT>PERMISSIONS</TT> file.  If you are using
the library in a commercial setting, please consider paying for a
licensed copy of the software.
<P>
<LI>Follow the installation instructions on how to configure and
make and install the library (i.e. type: <KBD>make install</KBD>).
See section <A HREF="dmalloc.html#SEC12">Installation of the Library</A>.
<P>
<A NAME="IDX71"></A>
<A NAME="IDX72"></A>
<P>
<LI>You need to make sure that the dmalloc building process
above was able to locate one of the the <CODE>on_exit</CODE> or <CODE>atexit</CODE>
functions.  If so, then the dmalloc library should be able to
automatically call <CODE>dmalloc_shutdown</CODE> when <CODE>exit</CODE> is called.
This causes the memory statistics and unfreed information to be dumped
to the log file.  However, if your system has neither, you will need to
call <CODE>dmalloc_shutdown</CODE> yourself before your program exits.
<P>
<LI>Add an alias for dmalloc to your shell's rc file.  Bourne, bash,
ksh, and zsh users should add the following to their <TT>.bashrc</TT> or
<TT>.zshrc</TT> file respectively (notice the -b option for bourne shell
output):
<P>
<PRE>
function dmalloc { eval `command dmalloc -b $*` }
</PRE>
<P>
By the way, if you are looking for a shell, I heartily recommend trying
out zsh.  It is a bourne shell written from scratch with much the same
features as tcsh without the csh crap.  If you are <EM>still</EM> using
csh or tcsh, you should add the following to your <TT>.cshrc</TT> file
(notice the -C option for c-shell output):
<P>
<PRE>
alias dmalloc 'eval `\dmalloc -C \!*`'
</PRE>
<P>
<LI>Although not necessary, you may want to include <TT>dmalloc.h</TT>
in your C files and recompile.  This will allow the library to report
the file/line numbers of calls that generate problems.  See section <A HREF="dmalloc.html#SEC16">Allocation Macros</A>.
<P>
<LI>Link the dmalloc library into your program.
<P>
<LI>Enable the debugging features by typing <KBD>dmalloc -l logfile
-i 100 low</KBD> (for example).  This will:
<P>
<UL>
<P>
<LI>set the malloc log path to <TT>logfile</TT> (<KBD>-l logfile</KBD>)
<P>
<LI>have the library check itself every 100 iterations (<KBD>-i 100</KBD>)
<P>
<LI>enable a number of debug features (<KBD>low</KBD>).  You can
also try <KBD>runtime</KBD> for minimal checking or <KBD>medium</KBD> or
<KBD>high</KBD> for more extensive heap verification.  <KBD>all</KBD> is also
provided but generates a multitude of log messages without many more
tests.
<P>
</UL>
<P>
<KBD>dmalloc --usage</KBD> will provide verbose usage info for the dmalloc
program.  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
You may also want to install the <TT>dmallocrc</TT> file in your home
directory as <TT>.dmallocrc</TT>.  This allows you to add your own
combination of debug tokens.  See section <A HREF="dmalloc.html#SEC24">Run-Time Configuration File</A>.
<P>
<LI>Run your program, examine the logfile that should have been created by
dmalloc_shutdown, and use its information to help debug your program.
<P>
<A NAME="IDX73"></A>
<P>
<EM>NOTE</EM>: If a log file has not been created then go back and repeat
these items carefully.  You may want to use <KBD>ident</KBD> or <KBD>strings</KBD>
on your program and <KBD>grep</KBD> for <SAMP>chunk.c,v</SAMP> to make sure that
the library is actually getting linked into your program.
<P>
</OL>
<P>
<H1><A NAME="SEC14" HREF="dmalloc_toc.html#SEC14">Details About How to Use the Library.</A></H1>
<P>
<A NAME="IDX74"></A>
<A NAME="IDX75"></A>
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC15">Programming</A>: How to program with the library.
<LI><A HREF="dmalloc.html#SEC22">Environment Variable</A>: The variable name and its features.
<LI><A HREF="dmalloc.html#SEC23">Debug Tokens</A>: Description of the debugging tokens.
<LI><A HREF="dmalloc.html#SEC24">RC File</A>: Format of the run-time configuration file.
<LI><A HREF="dmalloc.html#SEC25">Dmalloc Program</A>: Env variable setting utility.
<LI><A HREF="dmalloc.html#SEC26">Using With a Debugger</A>: Using a debugger with the library.
<LI><A HREF="dmalloc.html#SEC30">Using With Threads</A>: Using the library with a thread package.
</UL>
<P>
<H2><A NAME="SEC15" HREF="dmalloc_toc.html#SEC15">Programming with the Library</A></H2>
<P>
<A NAME="IDX76"></A>
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC16">Allocation Macros</A>: For providing file and line information.
<LI><A HREF="dmalloc.html#SEC17">Return Address</A>: For providing caller information.
<LI><A HREF="dmalloc.html#SEC18">Argument Checking</A>: Special checking of function arguments.
<LI><A HREF="dmalloc.html#SEC19">Extensions</A>: Additional non-standard routines.
<LI><A HREF="dmalloc.html#SEC20">C++ and the Library</A>: Using the Library with C++.
<LI><A HREF="dmalloc.html#SEC21">Disabling the Library</A>: How to compile/link without the library.
</UL>
<P>
<H3><A NAME="SEC16" HREF="dmalloc_toc.html#SEC16">Allocation Macros</A></H3>
<P>
<A NAME="IDX77"></A>
<A NAME="IDX78"></A>
<A NAME="IDX79"></A>
<P>
By including <TT>dmalloc.h</TT> in your C files, your calls to malloc,
calloc, realloc, recalloc, memalign, valloc, strdup, and free are
replaced with calls to _malloc_leap, _calloc_leap, _realloc_leap,
_recalloc_leap, _memalign_leap, _valloc_leap, _strdup_leap, and
_free_leap.  Additionally the library replaces calls to xmalloc,
xcalloc, xrealloc, xrecalloc, xmemalign, xvalloc, xstrdup, and xfree
with associated _leap calls.
<P>
<A NAME="IDX80"></A>
<A NAME="IDX81"></A>
<P>
These <DFN>leap macros</DFN> use the c-preprocessor <CODE>__FILE__</CODE> and
<CODE>__LINE__</CODE> macros which get replaced at compilation time with the
current file and line-number of the source code in question.  The leap
routines take this information and pass it on to the library making it
able to produce verbose reports on memory problems.
<P>
<PRE>
not freed: '0x38410' (22 bytes) from 'dmalloc_t.c:92'
</PRE>
<P>
This line from a log file shows that memory was not freed from file
<TT>dmalloc_t.c</TT> line 92.  See section <A HREF="dmalloc.html#SEC28">Tracking down Non-Freed Memory</A>.
<P>
<A NAME="IDX82"></A>
<A NAME="IDX83"></A>
<A NAME="IDX84"></A>
<A NAME="IDX85"></A>
<P>
You may notice some non standard memory allocation functions in the
above leap list.  Recalloc is a routine like realloc that reallocates
previously allocated memory to a new size.  If the new memory size is
larger than the old, recalloc initializes the new space to all zeros.
This may or may not be supported natively by your operating system.
Memalign is like malloc but should insure that the returned pointer is
aligned to a certain number of specified bytes.  Currently, the memalign
function is not supported by the library.  It defaults to returning
possibly non-aligned memory for alignment values less than a block-size.
Valloc is like malloc but insures that the returned pointer will be
aligned to a page boundary.  This may or may not be supported natively
by your operating system but is fully supported by the library.  Strdup
is a string duplicating routine which takes in a null terminated string
pointer and returns an allocated copy of the string that will need to be
passed to free later to deallocate.
<P>
The X versions of the standard memory functions (xmalloc, xfree, etc.)
will print out an error message to standard error and will stop if the
library is unable to allocate any additional memory.  It is useful to
use these routines instead of checking everywhere in your program for
allocation routines returning NULL pointers.
<P>
<EM>WARNING</EM>: If you are including the <TT>dmalloc.h</TT> file in your
sources, it is recommended that it be at the end of your include file
list because dmalloc uses macros and may try to change declarations of
the malloc functions if they come after it.
<P>
<H3><A NAME="SEC17" HREF="dmalloc_toc.html#SEC17">Return Address Information</A></H3>
<P>
<A NAME="IDX86"></A>
<A NAME="IDX87"></A>
<A NAME="IDX88"></A>
<A NAME="IDX89"></A>
<P>
Even though the allocation macros can provide file/line information for
some of your code, there are still modules which either you can't
include <TT>dmalloc.h</TT> (such as library routines) or you just don't
want to.  You can still get information about the routines that call
dmalloc function from the return-address information.  To accomplish
this, you must be using this library on one of the supported
architecture/compilers.  See section <A HREF="dmalloc.html#SEC34">Portability Issues</A>.
<P>
<A NAME="IDX90"></A>
<P>
The library attempts to use some assembly hacks to get the the
return-address or the address of the line that called the dmalloc
function.  If you have the <SAMP>log-unknown</SAMP> token enabled and you run
your program, you might see the following non-freed memory messages.
<P>
<PRE>
not freed: '0x38410' (22 bytes) from 'ra=0xdd2c'
not freed: '0x38600' (10232 bytes) from 'ra=0x10234d'
not freed: '0x38220' (137 bytes) from 'ra=0x82cc'
</PRE>
<P>
<A NAME="IDX91"></A>
With the help of a debugger, these return-addresses (or ra) can then be
identified.  I've provided a <TT>ra_info.pl</TT> perl script in the
<TT>contrib/</TT> directory with the dmalloc sources which seems to work
well with gdb.  You can also use the manual methods below for gdb.
<P>
<PRE>
(gdb) x 0x10234d
0x10234d <_findbuf+132>: 0x7fffceb7
<P>
(gdb) info line *(0x82cc)
Line 1092 of argv.c starts at pc 0x7540 and ends at 0x7550.
</PRE>
<P>
In the above example, gdb was used to find that the two non-freed memory
pointers were allocated in <CODE>_findbuf()</CODE> and in file argv.c line
1092 respectively.  The <SAMP>x address</SAMP> (for examine) can always be
used on the return-addresses but the <SAMP>info line *(address)</SAMP> will
only work if that file was compiled using the -g option and has not been
stripped.  This limitation may not be true in later versions of gdb.
<P>
<H3><A NAME="SEC18" HREF="dmalloc_toc.html#SEC18">Argument Checking of Function Arguments</A></H3>
<P>
<A NAME="IDX92"></A>
<A NAME="IDX93"></A>
<A NAME="IDX94"></A>
<P>
One potential problem with the library and its multitude of checks and
diagnoses is that they only get performed when a dmalloc function is
called.  One solution this is to include <TT>dmalloc.h</TT> and compile
your source code with the <CODE>DMALLOC_FUNC_CHECK</CODE> flag defined and
enable the <CODE>check-funcs</CODE> token.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A>.
<P>
<PRE>
cc -DDMALLOC_FUNC_CHECK file.c
</PRE>
<P>
<EM>NOTE</EM>: Once you have compiled your source with DMALLOC_FUNC_CHECK
enabled, you will have to recompile with it off to disconnect the
library.  See section <A HREF="dmalloc.html#SEC21">Disabling the Library</A>.
<P>
<EM>WARNING</EM>: You should be sure to have <TT>dmalloc.h</TT> included at
the end of your include file list because dmalloc uses macros and may
try to change declarations of the checked functions if they come after
it.
<P>
When this is defined dmalloc will override a number of functions and
will insert a routine which knows how to check its own arguments and
then call the real function.  Dmalloc can check such functions as
<CODE>bcopy</CODE>, <CODE>index</CODE>, <CODE>strcat</CODE>, and <CODE>strcasecmp</CODE>.  For
the full list see the end of <TT>dmalloc.h</TT>.
<P>
When you call <CODE>strlen</CODE>, for instance, dmalloc will make sure the
string argument's fence-post areas have not been overwritten, its file
and line number locations are good, etc.  With <CODE>bcopy</CODE>, dmalloc
will make sure that the destination string has enough space to store the
number of bytes specified.
<P>
For all of the arguments checked, if the pointer is not in the heap then
it is ignored since dmalloc does not know anything about it.
<P>
<H3><A NAME="SEC19" HREF="dmalloc_toc.html#SEC19">Extension Routines</A></H3>
<P>
<A NAME="IDX95"></A>
<P>
The library has a number of variables that are not a standard part of
most malloc libraries:
<P>
<DL COMPACT>
<DT> char * dmalloc_logpath
<DD><A NAME="IDX96"></A>
<A NAME="IDX97"></A>
This variable can be used to set the dmalloc log filename.  The env
variable DMALLOC_LOGFILE overrides this variable.
<P>
<DT> int dmalloc_errno
<DD><A NAME="IDX98"></A>
<A NAME="IDX99"></A>
<A NAME="IDX100"></A>
This variable stores the internal dmalloc library error number like errno
does for the system calls.  It can be passed to <CODE>dmalloc_strerror()</CODE>
(see below) to get a string version of the error.  It will have a value
of zero if the library has not detected any problems.
<P>
<DT> int dmalloc_address
<DD><A NAME="IDX101"></A>
<A NAME="IDX102"></A>
<A NAME="IDX103"></A>
This variable holds the address to be specifically looked for when
allocating or freeing by the library.
<P>
<DT> int dmalloc_address_count
<DD><A NAME="IDX104"></A>
This variable stores the argument to the address library setting.  If it
is set to a greater than 0 value then after the library has seen the
<SAMP>addr</SAMP> address this many times, it will call
<CODE>dmalloc_error()</CODE>.
<P>
This works well in conjunction with the <CODE>STORE_SEEN_COUNT</CODE> option.
See section <A HREF="dmalloc.html#SEC28">Tracking down Non-Freed Memory</A>.
<P>
</DL>
<P>
Additionally the library provides a number of non-standard malloc
routines:
<P>
void dmalloc_shutdown ( void )
<P>
<A NAME="IDX105"></A>
<A NAME="IDX106"></A>
<P>
This function shuts the library down and logs the final statistics and
information especially the non-freed memory pointers.  The library has
code to support auto-shutdown if your system has <CODE>on_exit()</CODE> or
<CODE>atexit()</CODE> calls (see <TT>conf.h</TT>).  If you do not have these
routines, then <CODE>dmalloc_shutdown</CODE> should be called right before
<CODE>exit()</CODE> or as the last function in <CODE>main()</CODE>.
<P>
<PRE>
main()
{
        ...
        dmalloc_shutdown();
        exit(0);
}
</PRE>
<P>
void dmalloc_log_heap_map ( void )
<P>
<A NAME="IDX107"></A>
<A NAME="IDX108"></A>
<A NAME="IDX109"></A>
<P>
This routine logs to the logfile (if it is enabled) a graphical
representation of the current heap space.
<P>
void dmalloc_log_stats ( void )
<A NAME="IDX110"></A>
<A NAME="IDX111"></A>
<A NAME="IDX112"></A>
<P>
This routine outputs the current dmalloc statistics to the log file.
<P>
void dmalloc_log_unfreed( void )
<P>
<A NAME="IDX113"></A>
<A NAME="IDX114"></A>
<A NAME="IDX115"></A>
<P>
This function dumps the unfreed-memory information to the log file.
This is also useful to dump the currently allocated points to the log
file to be compared against another dump later on.
<P>
int dmalloc_verify ( char * <VAR>pnt</VAR> )
<P>
<A NAME="IDX116"></A>
<A NAME="IDX117"></A>
<A NAME="IDX118"></A>
<P>
This function verifies individual memory pointers that are suspect of
memory problems.  To check the entire heap pass in a NULL or 0 pointer.
The routine returns DMALLOC_VERIFY_ERROR or DMALLOC_VERIFY_NOERROR.
<P>
<EM>NOTE</EM>: <SAMP>dmalloc_verify()</SAMP> can only check the heap with the
functions that have been enabled.  For example, if fence-post checking
is not enabled, <SAMP>dmalloc_verify()</SAMP> cannot check the fence-post
areas in the heap.
<P>
void dmalloc_debug ( long <VAR>debug</VAR> )
<P>
<A NAME="IDX119"></A>
<A NAME="IDX120"></A>
<P>
This routine overrides the debug setting from the environment variable
and sets the library debugging features explicitly.  For instance, if
debugging should never be enabled for a program, a call to
<CODE>dmalloc_debug(0)</CODE> as the first call in <CODE>main()</CODE> will disable
all the memory debugging from that point on.
<P>
One problem however is that some systems make calls to memory allocation
functions <EM>before</EM> <CODE>main()</CODE> is reached therefore before
<CODE>dmalloc_debug()</CODE> can be called meaning some debugging information
may be generated regardless.
<P>
long dmalloc_debug_current ( void )
<P>
<A NAME="IDX121"></A>
<A NAME="IDX122"></A>
<P>
This routine returns the current debug value from the environment
variable.  This allows you to save a copy of the debug dmalloc settings
to be changed and then restored later.
<P>
int dmalloc_examine ( char * <VAR>pnt</VAR>, int * <VAR>size</VAR>,
char ** <VAR>file</VAR>, int * <VAR>line</VAR>, void ** <VAR>ret_address</VAR> )
<P>
<A NAME="IDX123"></A>
<A NAME="IDX124"></A>
<A NAME="IDX125"></A>
<P>
This function returns the size of a pointer's allocation as well as the
file and line or the return-address from where it was allocated.  It
will return NOERROR or ERROR depending on whether pnt is good or not.
<P>
<EM>NOTE</EM>: This function is <EM>certainly</EM> not provided by most if
not all other malloc libraries.
<P>
char * dmalloc_strerror ( int <VAR>errnum</VAR> )
<P>
<A NAME="IDX126"></A>
<A NAME="IDX127"></A>
<A NAME="IDX128"></A>
<P>
This function returns the string representation of the error value in
errnum (which probably should be dmalloc_errno).  This allows the
logging of more verbose memory error messages.
<P>
You can also display the string representation of an error value by a
call to the <TT>dmalloc</TT> program with a <SAMP>-e #</SAMP> option.
See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
<H3><A NAME="SEC20" HREF="dmalloc_toc.html#SEC20">C++ and the Library</A></H3>
<P>
<A NAME="IDX129"></A>
<A NAME="IDX130"></A>
<P>
For those people using the C++ language, some special things need to be
done to get the library to work.  The problem exists with the fact that
the dynamic memory routines in C++ are <CODE>new()</CODE> and <CODE>delete()</CODE>
as opposed to <CODE>malloc()</CODE> and <CODE>free()</CODE>.
<P>
The file <TT>dmalloc.cc</TT> is provided in the distribution which
effectively redirects <CODE>new</CODE> to the more familiar <CODE>malloc</CODE> and
<CODE>delete</CODE> to the more familiar <CODE>free</CODE>.  Compile and link this
file in with the C++ program you want to debug.
<P>
<EM>NOTE</EM>: The author is not a C++ hacker so feedback in the form of
other hints and ideas for C++ users would be much appreciated.
<P>
<H3><A NAME="SEC21" HREF="dmalloc_toc.html#SEC21">Disabling the Library</A></H3>
<P>
<A NAME="IDX131"></A>
<P>
When you are finished with the development and debugging sessions, you
may want to disable the dmalloc library and put in its place either the
system's memory-allocation routines, gnu-malloc, or maybe your own.
Attempts have been made to make this a reasonably painless process.  The
ease of the extraction depends heavily on how many of the library's
features your made use of during your coding.
<P>
Reasonable suggestions are welcome as to how to improve this process
while maintaining the effectiveness of the debugging.
<P>
<UL>
<LI>
If you want to <EM>totally</EM> disable the dmalloc library then you will
need to recompile all the C files that include <TT>dmalloc.h</TT> while
defining <CODE>DMALLOC_DISABLE</CODE>.  This will cause the dmalloc leap
macros to not be applied.  See section <A HREF="dmalloc.html#SEC16">Allocation Macros</A>.
<P>
<PRE>
cc -g -DDMALLOC_DISABLE main.c
</PRE>
<P>
<LI>
If you compiled any of your source modules with <CODE>DMALLOC_FUNC_CHECK</CODE>
defined then you must first recompile all those modules without the flag
enabled.
<P>
<A NAME="IDX132"></A>
<A NAME="IDX133"></A>
<P>
<LI>
If you have not compiled all your source with <CODE>DMALLOC_DISABLED</CODE>
defined then you need to link your program with the
<TT>libdmalloclp.a</TT> library.
<P>
<PRE>
cc main.o -L/usr/local/lib -ldmalloclp -lgmalloc
</PRE>
<P>
If you have disabled dmalloc with the <CODE>DMALLOC_DISABLED</CODE> flag or
never included <TT>dmalloc.h</TT> in any of your C files, then you will
not need the <TT>libdmalloclp.a</TT> library.
<P>
<PRE>
cc -g main.o -L/usr/local/lib -lgmalloc
</PRE>
<P>
If you get unresolved references like <CODE>_malloc_leap</CODE> or
<CODE>_dmalloc_bcopy</CODE> then something was not disabled as it should have
been.
</UL>
<P>
<H2><A NAME="SEC22" HREF="dmalloc_toc.html#SEC22">Environment Variable Features</A></H2>
<P>
<A NAME="IDX134"></A>
<A NAME="IDX135"></A>
<P>
An <DFN>environment variable</DFN> is a variable that is part of the user's
working environment and is shared by all the programs.  The
<SAMP>DMALLOC_OPTIONS</SAMP> variable is used by the dmalloc library to enable
or disable the memory debugging features, at runtime.  It can be set
either by hand or with the help of the dmalloc program.  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
<A NAME="IDX136"></A>
<A NAME="IDX137"></A>
<A NAME="IDX138"></A>
To set it by hand, C shell (csh or tcsh) users need to invoke:
<P>
<PRE>
setenv DMALLOC_OPTIONS value
</PRE>
<P>
<A NAME="IDX139"></A>
<A NAME="IDX140"></A>
<A NAME="IDX141"></A>
<A NAME="IDX142"></A>
<A NAME="IDX143"></A>
Bourne shell (sh, bash, ksh, or zsh) users should use:
<P>
<PRE>
DMALLOC_OPTIONS=value
export DMALLOC_OPTIONS
</PRE>
<P>
The value in the above examples is a comma separated list of tokens each
having a corresponding value.  The tokens are described below:
<P>
<DL COMPACT>
<DT> debug
<DD><A NAME="IDX144"></A>
This should be set to a value in hexadecimal which corresponds to the
functionality token values added together.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A>.  For
instance, if the user wanted to enable the logging of memory
transactions (value <SAMP>0x008</SAMP>) and wanted to check fence-post memory
(value <SAMP>0x400</SAMP>) then <SAMP>debug</SAMP> should be set to <SAMP>0x408</SAMP>
(<SAMP>0x008</SAMP> + <SAMP>0x400</SAMP>).
<P>
<EM>NOTE</EM>: You don't have to worry about remembering all the hex
values of the tokens because the dmalloc program automates the setting
of this variable especially.
<P>
<EM>NOTE</EM>: You can also specify the debug tokens directly, separated
by commas.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A>.  If <SAMP>debug</SAMP> and the tokens are
both used, the token values will be added to the debug value.
<P>
<DT> log
<DD><A NAME="IDX145"></A>
<A NAME="IDX146"></A>
Set this to a filename so that if <SAMP>debug</SAMP> has logging enabled, the
library can log transactions, administration information, and/or errors
to the file so memory problems and usage can be tracked.
<P>
To get different logfiles for different processes, you can assign
<SAMP>log</SAMP> to a string with <CODE>%d</CODE> in it (for instance
<SAMP>logfile.%d</SAMP>).  This will be replaced with the pid of the running
process (for instance <SAMP>logfile.2451</SAMP>).
<P>
<EM>WARNING</EM>: it is easy to core dump any program with dmalloc, if
you send in a format with arguments other than the one <CODE>%d</CODE>.
<P>
<DT> addr
<DD><A NAME="IDX147"></A>
<A NAME="IDX148"></A>
<A NAME="IDX149"></A>
When this is set to a hex address (taken from the dmalloc log-file for
instance) dmalloc will abort when it finds itself either allocating or
freeing that address.
<P>
The address can also have an <SAMP>:number</SAMP> argument.  For instance, if
it was set it to <SAMP>0x3e45:10</SAMP>, the library will kill itself the 10th
time it sees address <SAMP>0x3e45</SAMP>.  By setting the number argument to
0, the program will never stop when it sees the address.  This is useful
for logging all activity on the address and makes it easier to track
down specific addresses not being freed.
<P>
This works well in conjunction with the <CODE>STORE_SEEN_COUNT</CODE> option.
See section <A HREF="dmalloc.html#SEC28">Tracking down Non-Freed Memory</A>.
<P>
<EM>NOTE</EM>: dmalloc will also log all activity on this address along
with a count.
<P>
<DT> inter
<DD><A NAME="IDX150"></A>
By setting this to a number X, dmalloc will only check the heap every X
times.  This means a number of debugging features can be enabled while
still running the program within a finite amount of time.
<P>
A setting of <SAMP>100</SAMP> works well with reasonably memory intensive
programs.  This of course means that the library will not catch errors
exactly when they happen but possibly 100 library calls later.
<P>
<DT> start
<DD><A NAME="IDX151"></A>
Set this to a number X and dmalloc will begin checking the heap after X
times.  This means the intensive debugging can be started after a
certain point in a program.
<P>
<SAMP>start</SAMP> also has the format file:line.  For instance, if it is set
to <SAMP>dmalloc_t.c:126</SAMP> dmalloc will start checking the heap after it
sees a dmalloc call from the <TT>dmalloc_t.c</TT> file, line number 126.
If line number is 0 then dmalloc will start checking the heap after it
sees a call from anywhere in the <TT>dmalloc_t.c</TT> file.
<P>
This allows the intensive debugging to be started after a certain
routine or file has been reached in the program.
</DL>
<P>
Some examples are:
<P>
<PRE>
# turn on transaction and stats logging and set 'malloc' as the log-file
setenv DMALLOC_OPTIONS log-trans,log-stats,log=malloc
<P>
# enable debug flags 0x1f as well as heap-checking and set the interval
# to be 100
setenv DMALLOC_OPTIONS debug=0x1f,check-heap,inter=100
<P>
# enable 'malloc' as the log-file, watch for address '0x1234', and start
# checking when we see file.c line 123
setenv DMALLOC_OPTIONS log=malloc,addr=0x1234,start=file.c:123
</PRE>
<P>
<H2><A NAME="SEC23" HREF="dmalloc_toc.html#SEC23">Debugging Tokens</A></H2>
<P>
<A NAME="IDX152"></A>
<A NAME="IDX153"></A>
<P>
The below tokens and their corresponding descriptions are for the
setting of the debug library setting in the environment variable.
See section <A HREF="dmalloc.html#SEC22">Environment Variable Features</A>.  They should be specified in the user's
<TT>.dmallocrc</TT> file.  See section <A HREF="dmalloc.html#SEC24">Run-Time Configuration File</A>.
<P>
Each token, when specified, enables a specific debugging feature.  For
instance, if you have the log-stats token enabled, the library will log
general statistics to the logfile.
<P>
To get this information on the fly, use <SAMP>dmalloc -DV</SAMP>.  This will
print out the Debug tokens in Very-verbose mode.  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
<DL COMPACT>
<A NAME="IDX154"></A>
<DT> none
<DD>No debugging functionality
<P>
<A NAME="IDX155"></A>
<DT> log-stats
<DD>Log general statistics when dmalloc_shutdown or dmalloc_log_stats is
called.
<P>
<A NAME="IDX156"></A>
<DT> log-non-free
<DD>Log non-freed memory pointers when dmalloc_shutdown or dmalloc_log_unfreed
is called.
<P>
<A NAME="IDX157"></A>
<DT> log-thread-id
<DD>For systems that have multi-threaded programs (don't worry if this does
not make sense to you), log thread-id for allocated pointer (see
<TT>conf.h</TT>).
<P>
<A NAME="IDX158"></A>
<DT> log-trans
<DD>Log general memory transactions (quite verbose).
<P>
<A NAME="IDX159"></A>
<DT> log-stamp
<DD>Log a time stamp for all messages.
<P>
<A NAME="IDX160"></A>
<DT> log-admin
<DD>Log administrative information (quite verbose).
<P>
<A NAME="IDX161"></A>
<DT> log-blocks
<DD>Log detailed block information when dmalloc_log_heap_map is called.
<P>
<A NAME="IDX162"></A>
<DT> log-unknown
<DD>Like log-non-free but logs non-freed memory pointers that did not have
file/line information associated with them.
<P>
<A NAME="IDX163"></A>
<DT> log-bad-space
<DD>Log actual bytes in and around bad pointers.
<P>
<A NAME="IDX164"></A>
<DT> log-nonfree-space
<DD>Log actual bytes in non-freed pointers.
<P>
<A NAME="IDX165"></A>
<DT> log-elapsed-time
<DD>Log elapsed-time for allocated pointers (see <TT>conf.h</TT>).
<P>
<A NAME="IDX166"></A>
<DT> log-current-time
<DD>Log current-time for allocated pointers (see <TT>conf.h</TT>).
<P>
<A NAME="IDX167"></A>
<DT> check-fence
<DD>Check fence-post memory areas.
<P>
<A NAME="IDX168"></A>
<DT> check-heap
<DD>Verify heap administrative structure.
<P>
<A NAME="IDX169"></A>
<DT> check-lists
<DD>Examine internal heap linked-lists.
<P>
<A NAME="IDX170"></A>
<DT> check-blank
<DD>Check to see if space that was blanked by free-blank or alloc-blank has
been overwritten.
<P>
<A NAME="IDX171"></A>
<DT> check-funcs
<DD>Check the arguments of some functions (mostly string operations) looking
for bad pointers.
<P>
<A NAME="IDX172"></A>
<DT> realloc-copy
<DD>Always copy data to a new pointer when realloc.
<P>
<A NAME="IDX173"></A>
<A NAME="IDX174"></A>
<A NAME="IDX175"></A>
<A NAME="IDX176"></A>
<A NAME="IDX177"></A>
<A NAME="IDX178"></A>
<A NAME="IDX179"></A>
<A NAME="IDX180"></A>
<DT> free-blank
<DD>Write special bytes (decimal 197, octal 0305, hex 0xc5) into space when
it is freed.
<P>
<A NAME="IDX181"></A>
<A NAME="IDX182"></A>
<A NAME="IDX183"></A>
<DT> error-abort
<DD>Abort the program (and dump core) on errors.  See <CODE>error-dump</CODE> below.
<P>
<A NAME="IDX184"></A>
<A NAME="IDX185"></A>
<A NAME="IDX186"></A>
<A NAME="IDX187"></A>
<A NAME="IDX188"></A>
<A NAME="IDX189"></A>
<A NAME="IDX190"></A>
<A NAME="IDX191"></A>
<DT> alloc-blank
<DD>Write special bytes (decimal 197, octal 0305, hex 0xc5) into space when
it is allocated.
<P>
<A NAME="IDX192"></A>
<DT> heap-check-map
<DD>Log a heap-map to the logfile every time the heap is checked.
<P>
<A NAME="IDX193"></A>
<DT> print-messages
<DD>Log any errors and messages to the screen via standard-error.
<P>
<A NAME="IDX194"></A>
<A NAME="IDX195"></A>
<DT> catch-null
<DD>Abort the program immediately if the library fails to get more heap
space from sbrk.
<P>
<A NAME="IDX196"></A>
<DT> never-reuse
<DD>Have the heap never use space that has been used before and freed.
See section <A HREF="dmalloc.html#SEC28">Tracking down Non-Freed Memory</A>.  <EM>WARNING</EM>: This should be used with caution
since you may run out of heap space.
<P>
<A NAME="IDX197"></A>
<DT> allow-nonlinear
<DD>Have the heap not complain when additional program functionality seems
to have made use of the system's heap-allocation routine <CODE>sbrk</CODE>
directly.  This is now enabled by default since an increasing number of
operating system functions seem to be doing this -- one example is the
pthreads package.
<P>
<EM>WARNING</EM>: This should be used with caution since it may hide
certain heap problems.
<P>
<A NAME="IDX198"></A>
<DT> allow-free-null
<DD>The library will not generate an error when a program tries to free a
NULL pointer.  See ALLOW_FREE_NULL and ALLOW_FREE_NULL_MESSAGE settings
in the <TT>settings.h</TT> file which change the default behavior.
<P>
<EM>NOTE</EM>: This does not impact the ALLOW_REALLOC_NULL compilation
options which can be adjusted in <TT>conf.h</TT>.
<P>
<A NAME="IDX199"></A>
<A NAME="IDX200"></A>
<A NAME="IDX201"></A>
<DT> error-dump
<DD>Dump core on error and then continue.  Later core dumps overwrite
earlier ones if the program encounters more than one error.  See
<CODE>error-abort</CODE> above.
<P>
<EM>NOTE</EM>: This will only work if your system supports the <CODE>fork</CODE>
system call and the configuration utility was able to fork without going
recursive.
<P>
</DL>
<P>
<H2><A NAME="SEC24" HREF="dmalloc_toc.html#SEC24">Run-Time Configuration File</A></H2>
<P>
<A NAME="IDX202"></A>
<A NAME="IDX203"></A>
<A NAME="IDX204"></A>
<A NAME="IDX205"></A>
<A NAME="IDX206"></A>
<P>
By using a <DFN>RC File</DFN> (or run-time configuration file) you can alias
tags to combinations of debug tokens.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A>.  
<P>
<EM>NOTE</EM>: For beginning users, the dmalloc program has a couple of
tags built into it so it is not necessary for you to setup a RC file:
<P>
<DL COMPACT>
<DT> runtime
<DD>enables basic run-time tests
<P>
<DT> low
<DD>turns on minimal checking of heap structures
<P>
<DT> medium
<DD>significant checking of heap areas
<P>
<DT> high
<DD>extensive checking of heap areas
<P>
<DT> all
<DD>turns on all the checking possible.  This generates a multitude of log
messages without many more tests than high.
</DL>
<P>
For expert users, a sample <TT>dmallocrc</TT> file has been provided but
you are encouraged to roll your own combinations.  The name of default
rc-file is <TT>$HOME/.dmallocrc</TT>.  The <SAMP>$HOME</SAMP> environment
variable should be set by the system to point to your home-directory.
<P>
The file should contain lines in the general form of:
<P>
<PRE>
tag     token1, token2, ...
</PRE>
<P>
<SAMP>tag</SAMP> is to be matched with the tag argument passed to the dmalloc
program, while <SAMP>token1, token2, ...</SAMP> are debug capability
tokens.  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A> and section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A>.
<P>
A line can be finished with a <SAMP>\</SAMP> meaning it continues onto the
next line.  Lines beginning with <SAMP>#</SAMP> are treated as comments and
are ignored along with empty lines.
<P>
Here is an example of a <TT>.dmallocrc</TT> file:
<P>
<PRE>
#
# Dmalloc run-time configuration file for the debug malloc library
#
<P>
# no debugging
none    none
<P>
# basic debugging
debug1  log-stats, log-non-free, check-fence
<P>
# more logging and some heap checking
debug2  log-stats, log-non-free, log-trans, \
        check-fence, check-heap, check-lists, error-abort
<P>
# good utilities
debug3  log-stats, log-non-free, log-trans, \
        log-admin, check-fence, check-heap, check-lists, realloc-copy, \
        free-blank, error-abort
<P>
...
</PRE>
<P>
For example, with the above file installed, you can type <CODE>dmalloc
debug1</CODE> after setting up your shell alias.  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
This enables the logging of statistics, the logging of non-freed memory,
and the checking of fence-post memory areas.
<P>
Enter <CODE>dmalloc none</CODE> to disable all memory debugging features.
<P>
<H2><A NAME="SEC25" HREF="dmalloc_toc.html#SEC25">Dmalloc Utility Program</A></H2>
<P>
<A NAME="IDX207"></A>
<A NAME="IDX208"></A>
<P>
The dmalloc program is designed to assist in the setting of the
environment variable <SAMP>DMALLOC_OPTIONS</SAMP>.  See section <A HREF="dmalloc.html#SEC22">Environment Variable Features</A>.  It is designed to print the shell commands necessary to make
the appropriate changes to the environment.  Unfortunately, it cannot
make the changes on its own so the output from dmalloc should be sent
through the <CODE>eval</CODE> shell command which will do the commands.
<P>
With shells that have aliasing or macro capabilities: csh, bash, ksh,
tcsh, zsh, etc., setting up an alias to dmalloc to do the eval call
is recommended.  Csh/tcsh users (for example) should put the following
in their <TT>.cshrc</TT> file:
<P>
<PRE>
alias dmalloc 'eval `\dmalloc -C \!*`'
</PRE>
<P>
Bash and Zsh users on the other hand should put the following in their
<TT>.zshrc</TT> file:
<P>
<PRE>
function dmalloc { eval `command dmalloc -b $*` }
</PRE>
<P>
This allows the user to execute the dmalloc command as <SAMP>dmalloc
arguments</SAMP>.
<P>
The most basic usage for the program is <SAMP>dmalloc [-bC] tag</SAMP>.  The
<SAMP>-b</SAMP> or <SAMP>-C</SAMP> (either but not both flags used at a time) are
for generating Bourne or C shell type commands respectively.  dmalloc
will try and use the <CODE>SHELL</CODE> environment variable to determine
whether bourne or C shell commands should be generated but you may want
to explicitly specify the correct flag.
<P>
The <SAMP>tag</SAMP> argument to dmalloc should match a line from the user's
run-time configuration file or should be one of the built-in tags.
See section <A HREF="dmalloc.html#SEC24">Run-Time Configuration File</A>.  If no tag is specified and no other option-commands
used, dmalloc will display the current settings of the environment
variable.  It is useful to specify one of the verbose options when doing
this.
<P>
To find out the usage for the debug malloc program try <SAMP>dmalloc
--usage-long</SAMP>.  The standardized usage message that will be displayed is
one of the many features of the argv library included with this package.
It is available via ftp from <SAMP>ftp.letters.com</SAMP> in the
<TT>/src/argv</TT> directory.  See <TT>argv.info</TT> there for more
information.
<P>
Here is a detailed list of the flags that can passed to dmalloc:
<P>
<DL COMPACT>
<DT> -a address
<DD>Set the <SAMP>addr</SAMP> part of the <SAMP>DMALLOC_OPTIONS</SAMP> variable to
address (or alternatively address:number).
<P>
<DT> -b
<DD>Output Bourne shell type commands.
<P>
<DT> -C
<DD>Output C shell type commands.
<P>
<DT> -c
<DD>Clear/unset all of the settings not specified with other arguments.
<P>
<EM>NOTE</EM>: clear will never unset the <SAMP>debug</SAMP> setting.  Use
<SAMP>-d 0</SAMP> or a tag to <SAMP>none</SAMP> to achieve this.
<P>
<DT> -d bitmask
<DD>Set the <SAMP>debug</SAMP> part of the <SAMP>DMALLOC_OPTIONS</SAMP> env variable to
the bitmask value which should be in hex.  This is overridden (and
unnecessary) if a tag is specified.
<P>
<DT> -D
<DD>List all of the debug-tokens.  Useful for finding a token to be used
with the -p or -m options.  Use with -v or -V verbose options.
<P>
<DT> -e errno
<DD>Print the dmalloc error string that corresponds to the error number
errno.
<P>
<DT> -f filename
<DD>Use this configuration file instead of the RC file
<TT>$HOME/.dmallocrc</TT>.
<P>
<DT> -i number
<DD><A NAME="IDX209"></A>
Set the checking interval to number.
<P>
<DT> -k
<DD>Keep the settings when using a tag.  This overrides -r.
<P>
<DT> -l filename
<DD>Set the log-file to filename.
<P>
<DT> -L
<DD>Output the debug-value not in hex but by individual debug-tokens in long
form.
<P>
<DT> -m token(s)
<DD>Remove (minus) the debug capabilities of token(s) from the current debug
setting or from the selected tag (or -d value).  Multiple -m's can be
specified.
<P>
<DT> -n
<DD>Without changing the environment, output the commands resulting from the
supplied options.
<P>
<A NAME="IDX210"></A>
<DT> -o times
<DD>Set the ``lock-on'' period which dictates with the threaded version of
the library to not initialize or lock the mutex lock around the library
until after a certain number of allocation calls have been made.  Some
number between 2 and 30 is probably good.  See the ``Using With
Threads'' section for more information about the operation of the
library with threads.  See section <A HREF="dmalloc.html#SEC30">Using the Library with a Thread Package</A>.
<P>
<DT> -p token(s)
<DD>Add (plus) the debug capabilities of token(s) to the current debug
setting or to the selected tag (or -d value).  Multiple -p's can be
specified.
<P>
<DT> -r
<DD>Remove (unset) all settings when using a tag.  This is useful when you
are returning to a standard development tag and want the logfile,
address, and interval settings to be cleared automatically.  If you want
this behavior by default, this can be put into the dmalloc alias.
<P>
<DT> -s number
<DD>Set the <SAMP>start</SAMP> part of the <SAMP>DMALLOC_OPTIONS</SAMP> env variable to
number (alternatively <SAMP>file:line</SAMP>).
<P>
<DT> -S
<DD>Output the debug-value not in hex but by individual debug-tokens in short
form.
<P>
<DT> -t
<DD>List all of the tags in the rc-file.  Use with -v or -V verbose options.
<P>
<DT> -v
<DD>Give verbose output.  Especially useful when dumping current settings or
listing all of the tags.
</DL>
<P>
If no arguments are specified, dmalloc dumps out the current settings
that you have for the environment variable.  For example:
<P>
<PRE>
Debug-Flags  '0x40005c7' (runtime)
Address      0x1f008, count = 3
Interval     100
Logpath      'malloc'
Start-File   not-set
</PRE>
<P>
With a -v option and no arguments, dmalloc dumps out the current
settings in a verbose manner.  For example:
<P>
<PRE>
Debug-Flags  '0x40005c7' (runtime)
   log-stats, log-non-free, log-blocks, log-unknown, 
   log-bad-space, check-fence, catch-null
Address      0x1f008, count = 10
Interval     100
Logpath      'malloc'
Start-File   not-set
</PRE>
<P>
Here are some examples of dmalloc usage:
<P>
<PRE>
# start tough debugging, check the heap every 100 times,
# send the log information to file 'dmalloc'
dmalloc high -i 100 -l dmalloc
<P>
# find out what error code 20 is (from the logfile)
dmalloc -e 20
<P>
# cause the library to halt itself when it sees the address 0x34238
# for the 6th time.
dmalloc -a 0x34238:6
<P>
# return to the normal 'runtime' settings and clear out all
# other settings
dmalloc -c runtime
<P>
# enable basic 'low' settings plus (-p) the logging of
# transactions (log-trans) to file 'dmalloc'
dmalloc low -p log-trans -l dmalloc
<P>
# print out the current settings with Very-verbose output
dmalloc -V
<P>
# list the available debug malloc tokens with Very-verbose output
dmalloc -DV
<P>
# list the available tags from the rc file with verbose output
dmalloc -tv
</PRE>
<P>
<H2><A NAME="SEC26" HREF="dmalloc_toc.html#SEC26">Using Dmalloc With a Debugger</A></H2>
<P>
<A NAME="IDX211"></A>
<A NAME="IDX212"></A>
<P>
Here are a number of possible scenarios for using the dmalloc library to
track down problems with your program.
<P>
You should first enable a logfile filename (I use <TT>dmalloc</TT>) and
turn on a set of debug features.  You can use <KBD>dmalloc -l dmalloc
low</KBD> to accomplish this.  If you are interested in having the error
messages printed to your terminal as well, enable the <SAMP>print-error</SAMP>
token by typing <KBD>dmalloc -p print-error</KBD> afterwards.  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
<A NAME="IDX213"></A>
<A NAME="IDX214"></A>
Now you can enter your debugger (I use the <EM>excellent</EM> GNU debugger
gdb), and put a break-point in <CODE>dmalloc_error()</CODE> which is the
internal error routine for the library.  When your program is run, it
will stop there if a memory problem is detected.
<P>
If you are using GDB, I would recommend adding the contents of
<TT>dmalloc.gdb</TT> in the <TT>contrib</TT> subdirectory to your
<TT>.gdbinit</TT> file in your home directory.  This enables the
<CODE>dmalloc</CODE> command which will prompt you for the arguments to the
dmalloc command and will set a break point in <CODE>dmalloc_error()</CODE>
automatically.
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC27">General Errors</A>: Diagnosing general problems with a debugger.
<LI><A HREF="dmalloc.html#SEC28">Memory Leaks</A>: Tracking down non-freed memory.
<LI><A HREF="dmalloc.html#SEC29">Fence-Post Overruns</A>: Diagnosing fence-post overwritten memory.
</UL>
<P>
<H3><A NAME="SEC27" HREF="dmalloc_toc.html#SEC27">Diagnosing General Errors with a Debugger</A></H3>
<P>
<A NAME="IDX215"></A>
<A NAME="IDX216"></A>
<P>
If your program stops at the <CODE>dmalloc_error()</CODE> routine then one of
a number of problems could be happening.  Incorrect arguments could have
been passed to a malloc call: asking for negative number of bytes,
trying to realloc a non-heap pointer, etc..  There also could be a
problem with the system's allocations: you've run out of memory, some
other function in your program is using <CODE>sbrk</CODE>, etc.  However, it
is most likely that some code that has been executed was naughty.
<P>
To get more information about the problem, first print via the debugger
the dmalloc_errno variable to get the library's internal error code.
You can suspend your debugger and run <SAMP>dmalloc -e
value-returned-from-print</SAMP> to get an English translation of the error.
A number of the error messages are designed to indicate specific
problems with the library administrative structures and may not be
user-friendly.
<P>
If the problem was due to the arguments or system allocations then the
source of the problem has been found.  However, if some code did
something wrong, you may have some more work to do to locate the actual
problem.  The <CODE>check-heap</CODE> token should be enabled and the interval
setting disabled or set to a low value so that the library can find the
problem as close as possible to its source.  The code that was execute
right before the library halted, can then be examined closely for
irregularities.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A> and See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
<A NAME="IDX217"></A>
<P>
You may also want to put calls to <CODE>dmalloc_verify(0)</CODE> in your code
before the section which generated the error.  This should locate the
problem faster by checking the library's structures at that point.
See section <A HREF="dmalloc.html#SEC19">Extension Routines</A>.
<P>
<H3><A NAME="SEC28" HREF="dmalloc_toc.html#SEC28">Tracking down Non-Freed Memory</A></H3>
<P>
<A NAME="IDX218"></A>
<A NAME="IDX219"></A>
<P>
So you've run your program, examined the log-file and discovered (to
your horror) some un-freed memory.  Memory leaks can become large
problems since even the smallest and most insignificant leak can starve
the program given the right circumstances.
<P>
<PRE>
not freed: '0x45008' (12 bytes) from 'ra=0x1f8f4'
not freed: '0x45028' (12 bytes) from 'unknown'
not freed: '0x45048' (10 bytes) from 'argv.c:1077'
  known memory not freed: 1 pointer, 10 bytes
unknown memory not freed: 2 pointers, 24 bytes
</PRE>
<P>
Above you will see a sample of some non-freed memory messages from the
logfile.  In the first line the <SAMP>0x45008</SAMP> is the pointer that was
not freed, the <SAMP>12 bytes</SAMP> is the size of the unfreed block, and the
<SAMP>ra=0x1f8f4</SAMP> or return-address shows where the allocation
originated from.  See section <A HREF="dmalloc.html#SEC17">Return Address Information</A>.
<P>
The systems which cannot provide return-address information show
<SAMP>unknown</SAMP> instead, as in the 2nd line in the sample above.
<P>
The <SAMP>argv.c:1077</SAMP> information from the 3rd line shows the file and
line number which allocated the memory which was not freed.  This
information comes from the calls from C files which included
<TT>dmalloc.h</TT>.  See section <A HREF="dmalloc.html#SEC16">Allocation Macros</A>.
<P>
At the bottom of the sample it totals the memory for you and breaks it
down to known memory (those calls which supplied the file/line
information) and unknown (the rest).
<P>
Often, you may allocate memory in via <CODE>strdup()</CODE> or another
routine, so the logfile listing where in the <CODE>strdup</CODE> routine the
memory was allocated does not help locate the true source of the memory
leak -- the routine that called <CODE>strdup</CODE>.  Without a mechanism to
trace the calling stack, there is no way for the library to see who the
caller of the caller (so to speak) was.
<P>
<A NAME="IDX220"></A>
<A NAME="IDX221"></A>
<P>
However, there is a way to track down unfreed memory in this
circumstance.  You need to compile the library with
<CODE>STORE_SEEN_COUNT</CODE> defined in <TT>conf.h</TT>.  The library will then
record how many times a pointer has been allocated or freed.  It will
display the unfreed memory as:
<P>
<PRE>
not freed: '0x45008|s3' (12 bytes) from 'ra=0x1f8f4'
</PRE>
<P>
The <CODE>STORE_SEEN_COUNT</CODE> option adds a <SAMP>|s#</SAMP> qualifier to the
address.  This means that the address in question was seen <SAMP>#</SAMP> many
times.  In the above example, the address <SAMP>0x45008</SAMP> was seen
<SAMP>3</SAMP> times.  The last time it was allocated, it was not freed.
<P>
How can a pointer be ``seen'' 3 times?  Let say you <CODE>strdup</CODE> a
string of 12 characters and get address <SAMP>0x45008</SAMP> -- this is #1
time the pointer is seen.  You then free the pointer (seen #2) but later
<CODE>strdup</CODE> another 12 character string and it gets the <SAMP>0x45008</SAMP>
address from the free list (seen #3).
<P>
So to find out who is allocating this particular 12 bytes the 3rd time,
try <SAMP>dmalloc -a 0x45008:3</SAMP>.  The library will stop the program the
third time it sees the <SAMP>0x45008</SAMP> address.  You then enter a
debugger and put a break point at <CODE>dmalloc_error</CODE>.  Run the program
and when the breakpoint is reached you can examine the stack frame to
determine who called <CODE>strdup</CODE> to allocate the pointer.
<P>
To not bother with the <CODE>STORE_SEEN_COUNT</CODE> feature, you can also run
your program with the <SAMP>never-reuse</SAMP> token enabled.  This token will
cause the library to never reuse memory that has been freed.  Unique
addresses are always generated.  This should be used with caution since
it may cause your program to run out of memory.
<P>
<H3><A NAME="SEC29" HREF="dmalloc_toc.html#SEC29">Diagnosing Fence-Post Overwritten Memory</A></H3>
<P>
<A NAME="IDX222"></A>
<P>
For a definition of fence-posts please see the ``Features'' section.
See section <A HREF="dmalloc.html#SEC10">Features of the Library</A>.
<P>
If you have encountered a fence-post memory error, the logfile should be
able to tell you the offending address.
<P>
<PRE>
free: failed UNDER picket-fence magic-number checking: 
pointer '0x1d008' from 'dmalloc_t.c:427'
Dump of proper fence-bottom bytes: '\e\253\300\300\e\253\300\300'
Dump of '0x1d008'-8: '\e\253\300\300WOW!\003\001pforger\023\001\123'
</PRE>
<P>
The above sample shows that the pointer <SAMP>0x1d008</SAMP> has had its lower
fence-post area overwritten.  This means that the code wrote below the
bottom of the address or above the address right below this one.  In the
sample, the string that did it was <SAMP>WOW!</SAMP>.
<P>
The library first shows you what the proper fence-post information
should look like, and then shows what the pointer's bad information was.
If it cannot print the character, it will display the value as
<SAMP>\ddd</SAMP> where ddd are three octal digits.
<P>
By enabling the <CODE>check-heap</CODE> debugging token and assigning the
interval setting to a low number, you should be able to locate
approximately when this problem happened.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A> and
See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.
<P>
<H2><A NAME="SEC30" HREF="dmalloc_toc.html#SEC30">Using the Library with a Thread Package</A></H2>
<P>
<A NAME="IDX223"></A>
<P>
This is the newest section of the library and therefore contains the
least information about a subject on which I probably could write a
book.  My apologies.
<P>
<A NAME="IDX224"></A>
<P>
Threads are special operating system facilities which allow your
programs to have multiple threads of execution (hence the name).  In
effect your program can be doing a number of things ``at the same
time''.  This allows you to take full advantage of modern operating
system scheduling and multi-processor hardware.  If I've already lost
you or if any of the terminology below does not make sense, see manuals
about POSIX threads (pthreads) before going any further.  O'Reilly
publishes a pretty good pthreads manual for example.
<P>
The support for threads in dmalloc is minimal although probably adequate
for most if not all testing scenarios.  It provides support for mutex
locking itself to protect against race conditions that result in
multiple simultaneous execution.  One of the major problems is that most
thread libraries uses malloc themselves.  Since all of dmalloc's
initialization happens when a call to malloc is made, we may be
attempting to initialize or lock the mutex while the thread library is
booting up.  A baaaad thing since thread libraries aren't reentrant.
<P>
<A NAME="IDX225"></A>
<P>
The solution to this problem is to have the library not initialize or
lock its mutex variable until after a certain number of allocation calls
have been completed.  If the library does not wait before initializing
the locks, the thread library will probably core dump.  If it waits too
long then it can't protect itself from multiple execution and it will
abort or other bad things might happen.  You adjust the number of times
to wait at runtime with the ``lock-on'' option to the dmalloc program
(for example <KBD>dmalloc -o 20</KBD>).  See section <A HREF="dmalloc.html#SEC25">Dmalloc Utility Program</A>.  Times
values between 2 and 30 are probably good although operating systems
will vary significantly.  You know its too low if your program core
dumps and too high if the library generates an exception.
<P>
An additional complexity is when we are initializing the lock before
mutex locking around the library.  As mentioned, the initialization
itself may generate a malloc call causing the library to go recursive
and the pthread library to possibly core dump. With the THREAD_INIT_LOCK
setting defined in <TT>settings.h</TT>, you can tune how many times before
we start locking to try and initialize the mutex lock.  It defaults to 2
which seems to work for me.  If people need to have this runtime
configurable or would like to present an alternative default, please let
me know.
<P>
In addition to the ``lock-on'' option, you probably will need to enable
the <SAMP>allow-nonlinear</SAMP> token if you thread library needs to call
sbrk directly to allocate some storage.  See section <A HREF="dmalloc.html#SEC23">Debugging Tokens</A>.
<P>
To build the library with the threaded stubs type <KBD>make threads</KBD>
which should build <TT>libdmallocth.a</TT>.  The auto-configurations for
these functions is in its infancy and may or may not work depending on
the script's ability to detect your local thread functionality.  Feel
free to send me mail with comments or improvements to them.
<P>
So that's it.  If you have any specific questions or would like addition
information posted in this section, please let me know.  Experienced
thread programmers only please.
<P>
<H1><A NAME="SEC31" HREF="dmalloc_toc.html#SEC31">Source Code Information</A></H1>
<P>
<A NAME="IDX226"></A>
<P>
<UL>
<LI><A HREF="dmalloc.html#SEC32">Definitions</A>: Some terms and other information.
<LI><A HREF="dmalloc.html#SEC33">Compatibility</A>: General compatibility concerns.
<LI><A HREF="dmalloc.html#SEC34">Portability</A>: Issues important for porting the library.
</UL>
<P>
<H2><A NAME="SEC32" HREF="dmalloc_toc.html#SEC32">Definitions of Terms</A></H2>
<P>
<A NAME="IDX227"></A>
<P>
Here are a couple definitions and other information for those interested
in ``picking the brain'' of the library.  The code is a little ugly here
and there and it conforms to the Gray-Watson handbook of coding
standards only.
<P>
<DL COMPACT>
<DT> bblock
<DD>basic block containing 2 ^ BASIC_BLOCK bytes of info
<P>
<DT> bblock_adm
<DD>administration for a set of basic blocks
<P>
<DT> dblock
<DD>divided block containing some base 2 number of blocks smaller than a
basic block.
<P>
<DT> dblock_adm
<DD>administration for a set of divided blocks
<P>
<DT> chunk
<DD>some anonymous amount of memory
</DL>
<P>
For more information about administration structures, see the code and
comments from <TT>chunk_loc.h</TT>.
<P>
<H2><A NAME="SEC33" HREF="dmalloc_toc.html#SEC33">General Compatibility Concerns</A></H2>
<P>
<A NAME="IDX228"></A>
<P>
<UL>
<LI>
Realloc() backwards compatibility with being able to realloc from the
last freed block is <EM>not</EM> supported.  The author is interested to
know who is using this (cough, cough) feature and for what reason.
<P>
<LI>
Realloc() of a NULL pointer is supported in which case the library will
just make a call to malloc().  This can be disabled with the help of a
manual compilation option in the <TT>conf.h</TT> file.
<P>
<LI>
The library does <EM>not</EM> provide memalign() support as of yet, but
may in future releases.  The author is interested to know who is using
these functions and for what reason.
<P>
<LI>
Some systems allow free(0) to not be an error for some reason.  Since 0
is not a valid address returned by the malloc call, it is debatable that
this should be allowed.  See <TT>conf.h</TT> for some manual compilation
options to handle this.
<P>
<LI>
Aside from possibly being slower than the system's memory allocation
functions, the library should be fully compatible with the standard
memory routines.  If this is <EM>not</EM> the case, please bring this to
my attention.
</UL>
<P>
<H2><A NAME="SEC34" HREF="dmalloc_toc.html#SEC34">Portability Issues</A></H2>
<P>
<A NAME="IDX229"></A>
<P>
General portability issues center around:
<P>
<UL>
<LI>
<A NAME="IDX230"></A>
sbrk or compatible function usages
<P>
<LI>
<A NAME="IDX231"></A>
<A NAME="IDX232"></A>
Whether the systems' heap grows towards high or low memory.  The chunk.c
code is designed (loosely) around the fact that consecutive calls to
sbrk should give higher memory addresses.
<P>
The library has not been tested on a system whose heap grows towards low
memory.  If you are trying to run the library on such a system please
contact the author.
<P>
<LI>
<A NAME="IDX233"></A>
The locating of the caller's address from the dmalloc functions.
This is useful in locating problems from dmalloc functions called from C
files which did not include <TT>dmalloc.h</TT>: C library calls for
instance.
<P>
<A NAME="IDX234"></A>
See <TT>return.h</TT> for the available architecture/compiler
combinations.  You may want to examine the assembly code from gcc (GNUs
superior c-compiler) version 2+ being run on the following code.  It
should give you a good start on building a hack for your box.
<P>
<PRE>
static char * x;
<P>
a()
{
        x = __builtin_return_address(0);
}
<P>
main()
{
        a();
}
</PRE>
<P>
</UL>
<P>
<H1><A NAME="SEC35" HREF="dmalloc_toc.html#SEC35">Plugs and Soapbox Comments</A></H1>
<P>
<A NAME="IDX235"></A>
<A NAME="IDX236"></A>
<P>
The author would like to bring the following organizations to your
attention.  If you would like any more information about the below,
please mail to the supplied addresses or drop the author a line with any
questions.
<P>
<DL COMPACT>
<DT> The Electronic Frontier Foundation (EFF)
<DD><A NAME="IDX237"></A>
<A NAME="IDX238"></A>
The EFF is a organization committed to ensuring that the rules,
regulations, and laws being applied to emerging communications
technologies are in keeping with our society's highest traditions of the
free and open flow of ideas and information while protecting personal
privacy.  http://www.eff.org/
<P>
<DT> Computer Professionals for Social Responsibility (CPSR)
<DD><A NAME="IDX239"></A>
<A NAME="IDX240"></A>
CPSR is a public-interest alliance of computer scientists and others
interested in the impact of computer technology on society.  We work to
influence decisions regarding the development and use of computers
because those decisions have far-reaching consequences and reflect basic
values and priorities.  http://www.cpsr.org/
<P>
<DT> Berkeley Software Design, Inc. (BSDI)
<DD><A NAME="IDX241"></A>
<A NAME="IDX242"></A>
<A NAME="IDX243"></A>
<A NAME="IDX244"></A>
The author has been a proud and enthusiastic owner and user of the
BSD/OS operating system for some time now.  For around $1k you get a
<EM>complete</EM> BSD-flavor operating system with <EM>full source</EM> for
Intel class systems (binary licenses are available).  Along with the
obvious benefits of full source code come excellent customer
support/service and system features such as a MS-DOG runtime
environment, SCO binary compatibility, complete tcp/ip networking
facilities including nfs, full software development utilities, X, etc.
<bsdi-info@bsdi.com>
</DL>
<P>
<H1><A NAME="SEC36" HREF="dmalloc_toc.html#SEC36">Index of Concepts</A></H1>
<P>
<MENU>
<LI><A HREF="dmalloc.html#IDX206">.dmallocrc file</A>
<LI><A HREF="dmalloc.html#IDX61">ANSI-C compiler</A>
<LI><A HREF="dmalloc.html#IDX24">Allocation of zeros</A>
<LI><A HREF="dmalloc.html#IDX242">BSD/386</A>
<LI><A HREF="dmalloc.html#IDX243">BSD/OS</A>
<LI><A HREF="dmalloc.html#IDX241">BSDI</A>
<LI><A HREF="dmalloc.html#IDX244">Berkeley Software Design, Inc.</A>
<LI><A HREF="dmalloc.html#IDX139">Bourne shell usage</A>
<LI><A HREF="dmalloc.html#IDX136">C shell usage</A>
<LI><A HREF="dmalloc.html#IDX239">CPSR</A>
<LI><A HREF="dmalloc.html#IDX240">Computer Professionals for Social Responsibility</A>
<LI><A HREF="dmalloc.html#IDX94">DMALLOC_FUNC_CHECK flag</A>
<LI><A HREF="dmalloc.html#IDX135">DMALLOC_OPTIONS</A>
<LI><A HREF="dmalloc.html#IDX60">DMALLOC_SIZE variable</A>
<LI><A HREF="dmalloc.html#IDX62">Deansify.pl script</A>
<LI><A HREF="dmalloc.html#IDX237">EFF</A>
<LI><A HREF="dmalloc.html#IDX238">Electronic Frontier Foundation</A>
<LI><A HREF="dmalloc.html#IDX55">PERMISSIONS file</A>
<LI><A HREF="dmalloc.html#IDX220">STORE_SEEN_COUNT option</A>
<LI><A HREF="dmalloc.html#IDX148">address locating</A>
<LI><A HREF="dmalloc.html#IDX147">address setting</A>
<LI><A HREF="dmalloc.html#IDX102">address to look for</A>
<LI><A HREF="dmalloc.html#IDX191">alloc-blank</A>
<LI><A HREF="dmalloc.html#IDX14">allocation basics</A>
<LI><A HREF="dmalloc.html#IDX77">allocation macros</A>
<LI><A HREF="dmalloc.html#IDX198">allow-free-null</A>
<LI><A HREF="dmalloc.html#IDX197">allow-nonlinear</A>
<LI><A HREF="dmalloc.html#IDX48">anonymous ftp</A>
<LI><A HREF="dmalloc.html#IDX92">argument checking</A>
<LI><A HREF="dmalloc.html#IDX90">assembly hacks</A>
<LI><A HREF="dmalloc.html#IDX2">author</A>
<LI><A HREF="dmalloc.html#IDX71">automatic shutdown</A>
<LI><A HREF="dmalloc.html#IDX141">bash usage</A>
<LI><A HREF="dmalloc.html#IDX15">basic allocation information</A>
<LI><A HREF="dmalloc.html#IDX16">basic definitions</A>
<LI><A HREF="dmalloc.html#IDX70">beginning</A>
<LI><A HREF="dmalloc.html#IDX184">blank space</A>
<LI><A HREF="dmalloc.html#IDX185">blanking memory</A>
<LI><A HREF="dmalloc.html#IDX33">bounds checking</A>
<LI><A HREF="dmalloc.html#IDX52">building the library</A>
<LI><A HREF="dmalloc.html#IDX129">c++ usage</A>
<LI><A HREF="dmalloc.html#IDX23">calloc</A>
<LI><A HREF="dmalloc.html#IDX195">catch-null</A>
<LI><A HREF="dmalloc.html#IDX170">check-blank</A>
<LI><A HREF="dmalloc.html#IDX167">check-fence</A>
<LI><A HREF="dmalloc.html#IDX171">check-funcs</A>
<LI><A HREF="dmalloc.html#IDX168">check-heap</A>
<LI><A HREF="dmalloc.html#IDX169">check-lists</A>
<LI><A HREF="dmalloc.html#IDX93">checking arguments</A>
<LI><A HREF="dmalloc.html#IDX34">checking bounds</A>
<LI><A HREF="dmalloc.html#IDX187">clearing memory</A>
<LI><A HREF="dmalloc.html#IDX8">commercial license</A>
<LI><A HREF="dmalloc.html#IDX228">compatibility</A>
<LI><A HREF="dmalloc.html#IDX51">compiling the library</A>
<LI><A HREF="dmalloc.html#IDX58">conf.h file</A>
<LI><A HREF="dmalloc.html#IDX204">configuration file</A>
<LI><A HREF="dmalloc.html#IDX57">configure script</A>
<LI><A HREF="dmalloc.html#IDX53">configuring the library</A>
<LI><A HREF="dmalloc.html#IDX35">constancy verification</A>
<LI><A HREF="dmalloc.html#IDX3">copying</A>
<LI><A HREF="dmalloc.html#IDX200">core dump</A>
<LI><A HREF="dmalloc.html#IDX30">cpp</A>
<LI><A HREF="dmalloc.html#IDX137">csh usage</A>
<LI><A HREF="dmalloc.html#IDX122">current debug value</A>
<LI><A HREF="dmalloc.html#IDX144">debug setting</A>
<LI><A HREF="dmalloc.html#IDX152">debug tokens</A>
<LI><A HREF="dmalloc.html#IDX211">debugger usage with dmalloc</A>
<LI><A HREF="dmalloc.html#IDX188">decimal 197</A>
<LI><A HREF="dmalloc.html#IDX74">details</A>
<LI><A HREF="dmalloc.html#IDX215">diagnosing errors</A>
<LI><A HREF="dmalloc.html#IDX131">disabling the library</A>
<LI><A HREF="dmalloc.html#IDX207">dmalloc program</A>
<LI><A HREF="dmalloc.html#IDX130">dmalloc.cc file</A>
<LI><A HREF="dmalloc.html#IDX79">dmalloc.h file</A>
<LI><A HREF="dmalloc.html#IDX101">dmalloc_address variable</A>
<LI><A HREF="dmalloc.html#IDX104">dmalloc_address_count variable</A>
<LI><A HREF="dmalloc.html#IDX119">dmalloc_debug function</A>
<LI><A HREF="dmalloc.html#IDX121">dmalloc_debug_current function</A>
<LI><A HREF="dmalloc.html#IDX98">dmalloc_errno number</A>
<LI><A HREF="dmalloc.html#IDX214">dmalloc_error() routine</A>
<LI><A HREF="dmalloc.html#IDX123">dmalloc_examine function</A>
<LI><A HREF="dmalloc.html#IDX107">dmalloc_log_heap_map function</A>
<LI><A HREF="dmalloc.html#IDX110">dmalloc_log_stats function</A>
<LI><A HREF="dmalloc.html#IDX113">dmalloc_log_unfreed function</A>
<LI><A HREF="dmalloc.html#IDX96">dmalloc_logpath variable</A>
<LI><A HREF="dmalloc.html#IDX105">dmalloc_shutdown function</A>
<LI><A HREF="dmalloc.html#IDX126">dmalloc_strerror function</A>
<LI><A HREF="dmalloc.html#IDX64">dmalloc_t test program</A>
<LI><A HREF="dmalloc.html#IDX116">dmalloc_verify function</A>
<LI><A HREF="dmalloc.html#IDX217">dmalloc_verify() routine</A>
<LI><A HREF="dmalloc.html#IDX205">dmallocrc file</A>
<LI><A HREF="dmalloc.html#IDX46">downloading the library</A>
<LI><A HREF="dmalloc.html#IDX199">dump core</A>
<LI><A HREF="dmalloc.html#IDX134">environment variable</A>
<LI><A HREF="dmalloc.html#IDX128">error message</A>
<LI><A HREF="dmalloc.html#IDX100">error number</A>
<LI><A HREF="dmalloc.html#IDX183">error-abort</A>
<LI><A HREF="dmalloc.html#IDX201">error-dump</A>
<LI><A HREF="dmalloc.html#IDX124">examine a pointer</A>
<LI><A HREF="dmalloc.html#IDX95">extensions</A>
<LI><A HREF="dmalloc.html#IDX28">features</A>
<LI><A HREF="dmalloc.html#IDX32">fence-post checking</A>
<LI><A HREF="dmalloc.html#IDX222">fence-post errors</A>
<LI><A HREF="dmalloc.html#IDX29">file/line numbers</A>
<LI><A HREF="dmalloc.html#IDX27">free</A>
<LI><A HREF="dmalloc.html#IDX180">free-blank</A>
<LI><A HREF="dmalloc.html#IDX49">ftp</A>
<LI><A HREF="dmalloc.html#IDX234">gcc</A>
<LI><A HREF="dmalloc.html#IDX213">gdb</A>
<LI><A HREF="dmalloc.html#IDX216">general errors</A>
<LI><A HREF="dmalloc.html#IDX66">getting started</A>
<LI><A HREF="dmalloc.html#IDX47">getting the source</A>
<LI><A HREF="dmalloc.html#IDX232">growing the heap</A>
<LI><A HREF="dmalloc.html#IDX231">heap growing</A>
<LI><A HREF="dmalloc.html#IDX109">heap map</A>
<LI><A HREF="dmalloc.html#IDX20">heap memory</A>
<LI><A HREF="dmalloc.html#IDX192">heap-check-map</A>
<LI><A HREF="dmalloc.html#IDX190">hex 0xc5</A>
<LI><A HREF="dmalloc.html#IDX68">how to begin</A>
<LI><A HREF="dmalloc.html#IDX73">ident</A>
<LI><A HREF="dmalloc.html#IDX50">installing the library</A>
<LI><A HREF="dmalloc.html#IDX99">internal error number</A>
<LI><A HREF="dmalloc.html#IDX209">interval setting</A>
<LI><A HREF="dmalloc.html#IDX1">introduction</A>
<LI><A HREF="dmalloc.html#IDX67">jump start</A>
<LI><A HREF="dmalloc.html#IDX142">ksh usage</A>
<LI><A HREF="dmalloc.html#IDX219">leaking memory</A>
<LI><A HREF="dmalloc.html#IDX132">leap library</A>
<LI><A HREF="dmalloc.html#IDX80">leap macros</A>
<LI><A HREF="dmalloc.html#IDX133">libdmalloclp.a library</A>
<LI><A HREF="dmalloc.html#IDX5">library permissions</A>
<LI><A HREF="dmalloc.html#IDX4">license</A>
<LI><A HREF="dmalloc.html#IDX9">license, commercial</A>
<LI><A HREF="dmalloc.html#IDX225">lock on</A>
<LI><A HREF="dmalloc.html#IDX108">log a heap map</A>
<LI><A HREF="dmalloc.html#IDX111">log statistics</A>
<LI><A HREF="dmalloc.html#IDX114">log unfreed memory</A>
<LI><A HREF="dmalloc.html#IDX160">log-admin</A>
<LI><A HREF="dmalloc.html#IDX163">log-bad-space</A>
<LI><A HREF="dmalloc.html#IDX161">log-blocks</A>
<LI><A HREF="dmalloc.html#IDX166">log-current-time</A>
<LI><A HREF="dmalloc.html#IDX165">log-elapsed-time</A>
<LI><A HREF="dmalloc.html#IDX156">log-non-free</A>
<LI><A HREF="dmalloc.html#IDX164">log-nonfree-space</A>
<LI><A HREF="dmalloc.html#IDX159">log-stamp</A>
<LI><A HREF="dmalloc.html#IDX155">log-stats</A>
<LI><A HREF="dmalloc.html#IDX157">log-thread-id</A>
<LI><A HREF="dmalloc.html#IDX158">log-trans</A>
<LI><A HREF="dmalloc.html#IDX162">log-unknown</A>
<LI><A HREF="dmalloc.html#IDX97">logfile name</A>
<LI><A HREF="dmalloc.html#IDX145">logfile setting</A>
<LI><A HREF="dmalloc.html#IDX146">logging information to disk</A>
<LI><A HREF="dmalloc.html#IDX36">logging statistics</A>
<LI><A HREF="dmalloc.html#IDX103">looking for an address</A>
<LI><A HREF="dmalloc.html#IDX78">macros, allocation</A>
<LI><A HREF="dmalloc.html#IDX81">macros, leap</A>
<LI><A HREF="dmalloc.html#IDX54">making the library</A>
<LI><A HREF="dmalloc.html#IDX22">malloc</A>
<LI><A HREF="dmalloc.html#IDX21">malloc functions</A>
<LI><A HREF="dmalloc.html#IDX11">manuals, printed</A>
<LI><A HREF="dmalloc.html#IDX83">memalign</A>
<LI><A HREF="dmalloc.html#IDX17">memory definitions</A>
<LI><A HREF="dmalloc.html#IDX218">memory leaks</A>
<LI><A HREF="dmalloc.html#IDX45">memory problems in system functions</A>
<LI><A HREF="dmalloc.html#IDX196">never-reuse</A>
<LI><A HREF="dmalloc.html#IDX7">non-commercial license</A>
<LI><A HREF="dmalloc.html#IDX41">non-freed memory</A>
<LI><A HREF="dmalloc.html#IDX154">none token</A>
<LI><A HREF="dmalloc.html#IDX189">octal 305</A>
<LI><A HREF="dmalloc.html#IDX75">operation details</A>
<LI><A HREF="dmalloc.html#IDX120">override debug settings</A>
<LI><A HREF="dmalloc.html#IDX13">overview</A>
<LI><A HREF="dmalloc.html#IDX186">overwriting memory</A>
<LI><A HREF="dmalloc.html#IDX6">permissions of the library</A>
<LI><A HREF="dmalloc.html#IDX235">plugs</A>
<LI><A HREF="dmalloc.html#IDX125">pointer information</A>
<LI><A HREF="dmalloc.html#IDX221">pointer seen count</A>
<LI><A HREF="dmalloc.html#IDX229">portability</A>
<LI><A HREF="dmalloc.html#IDX193">print-messages</A>
<LI><A HREF="dmalloc.html#IDX10">printed manuals</A>
<LI><A HREF="dmalloc.html#IDX76">programming</A>
<LI><A HREF="dmalloc.html#IDX224">pthreads</A>
<LI><A HREF="dmalloc.html#IDX65">quick start</A>
<LI><A HREF="dmalloc.html#IDX89">ra</A>
<LI><A HREF="dmalloc.html#IDX202">rc file</A>
<LI><A HREF="dmalloc.html#IDX26">realloc</A>
<LI><A HREF="dmalloc.html#IDX172">realloc-copy</A>
<LI><A HREF="dmalloc.html#IDX82">recalloc</A>
<LI><A HREF="dmalloc.html#IDX12">registration</A>
<LI><A HREF="dmalloc.html#IDX233">return-address</A>
<LI><A HREF="dmalloc.html#IDX88">return.h file</A>
<LI><A HREF="dmalloc.html#IDX203">runtime-config file</A>
<LI><A HREF="dmalloc.html#IDX230">sbrk</A>
<LI><A HREF="dmalloc.html#IDX56">settings.dist file</A>
<LI><A HREF="dmalloc.html#IDX59">settings.h file</A>
<LI><A HREF="dmalloc.html#IDX140">sh usage</A>
<LI><A HREF="dmalloc.html#IDX106">shutdown the library</A>
<LI><A HREF="dmalloc.html#IDX72">shutdown, automatic</A>
<LI><A HREF="dmalloc.html#IDX236">soapbox comments</A>
<LI><A HREF="dmalloc.html#IDX226">source code</A>
<LI><A HREF="dmalloc.html#IDX227">source definitions</A>
<LI><A HREF="dmalloc.html#IDX19">stack memory</A>
<LI><A HREF="dmalloc.html#IDX151">start setting</A>
<LI><A HREF="dmalloc.html#IDX18">static memory</A>
<LI><A HREF="dmalloc.html#IDX37">statistics</A>
<LI><A HREF="dmalloc.html#IDX112">statistics logging</A>
<LI><A HREF="dmalloc.html#IDX85">strdup</A>
<LI><A HREF="dmalloc.html#IDX127">string error message</A>
<LI><A HREF="dmalloc.html#IDX44">system memory problems</A>
<LI><A HREF="dmalloc.html#IDX138">tcsh usage</A>
<LI><A HREF="dmalloc.html#IDX63">testing the library</A>
<LI><A HREF="dmalloc.html#IDX223">threads</A>
<LI><A HREF="dmalloc.html#IDX153">tokens, debug</A>
<LI><A HREF="dmalloc.html#IDX149">tracking addresses</A>
<LI><A HREF="dmalloc.html#IDX40">unfreed memory</A>
<LI><A HREF="dmalloc.html#IDX115">unfreed memory log</A>
<LI><A HREF="dmalloc.html#IDX212">using a debugger with dmalloc</A>
<LI><A HREF="dmalloc.html#IDX208">utility program</A>
<LI><A HREF="dmalloc.html#IDX84">valloc</A>
<LI><A HREF="dmalloc.html#IDX117">verify pointers</A>
<LI><A HREF="dmalloc.html#IDX118">verify the heap</A>
<LI><A HREF="dmalloc.html#IDX69">where to begin</A>
<LI><A HREF="dmalloc.html#IDX25">zeros, allocation of</A>
<LI><A HREF="dmalloc.html#IDX143">zsh usage</A>
</MENU>
<P>
<H1><A NAME="SEC37" HREF="dmalloc_toc.html#SEC37">Full Node Listing</A></H1>
<P>
<UL>
Top.
<P>
<LI><A HREF="dmalloc.html#SEC1">Copying</A>: Library copying and licensing conditions.
<LI><A HREF="dmalloc.html#SEC6">Overview</A>: Description of features and how to get started.
<LI><A HREF="dmalloc.html#SEC14">Details</A>: Details about how to use the library.
<LI><A HREF="dmalloc.html#SEC31">Source Code</A>: Information on the source and general concerns.
<LI><A HREF="dmalloc.html#SEC35">Plugs</A>: A couple soapbox comments.
<LI><A HREF="dmalloc.html#SEC36">Index of Concepts</A>: Index of concepts in the manual.
<LI><A HREF="dmalloc.html#SEC37">Full Node Listing</A>: Listing of all the nodes in the manual.
<P>
Copying.
<P>
<LI><A HREF="dmalloc.html#SEC2">Non-Commercial License</A>: Permissions for non-commercial entities.
<LI><A HREF="dmalloc.html#SEC3">Commercial License</A>: Permissions for commercial entities.
<LI><A HREF="dmalloc.html#SEC4">Printed Manuals</A>: Printed/bound manuals and source floppies.
<LI><A HREF="dmalloc.html#SEC5">Registration Information</A>: Permissions for commercial entities.
<P>
Overview.
<P>
<LI><A HREF="dmalloc.html#SEC7">Allocation Basics</A>: Basic description of terms and functions.
<LI><A HREF="dmalloc.html#SEC10">Features</A>: The general features of the library.
<LI><A HREF="dmalloc.html#SEC11">How To Get</A>: How to get the library.
<LI><A HREF="dmalloc.html#SEC12">Installation</A>: How to install the library.
<LI><A HREF="dmalloc.html#SEC13">Getting Started</A>: Getting started with the library.
<LI><A HREF="dmalloc.html#SEC30">Using With Threads</A>: Using the library with a thread package.
<P>
Allocation Basics.
<P>
<LI><A HREF="dmalloc.html#SEC8">Basic Definitions</A>: General memory terms and concepts.
<LI><A HREF="dmalloc.html#SEC9">Malloc Functions</A>: Functionality supported by all malloc libs.
<P>
Details.
<P>
<LI><A HREF="dmalloc.html#SEC15">Programming</A>: How to program with the library.
<LI><A HREF="dmalloc.html#SEC22">Environment Variable</A>: The variable name and its features.
<LI><A HREF="dmalloc.html#SEC23">Debug Tokens</A>: Description of the debugging tokens.
<LI><A HREF="dmalloc.html#SEC24">RC File</A>: Format of the run-time configuration file.
<LI><A HREF="dmalloc.html#SEC25">Dmalloc Program</A>: Env variable setting utility.
<LI><A HREF="dmalloc.html#SEC26">Using With a Debugger</A>: Using a debugger with the library.
<LI><A HREF="dmalloc.html#SEC30">Using With Threads</A>: Using the library with a thread package.
<P>
Source Code.
<P>
<LI><A HREF="dmalloc.html#SEC32">Definitions</A>: Some terms and other information.
<LI><A HREF="dmalloc.html#SEC33">Compatibility</A>: General compatibility concerns.
<LI><A HREF="dmalloc.html#SEC34">Portability</A>: Issues important for porting the library.
<P>
Programming.
<P>
<LI><A HREF="dmalloc.html#SEC16">Allocation Macros</A>: For providing file and line information.
<LI><A HREF="dmalloc.html#SEC17">Return Address</A>: For providing caller information.
<LI><A HREF="dmalloc.html#SEC18">Argument Checking</A>: Special checking of function arguments.
<LI><A HREF="dmalloc.html#SEC19">Extensions</A>: Additional non-standard routines.
<LI><A HREF="dmalloc.html#SEC20">C++ and the Library</A>: Using the Library with C++.
<LI><A HREF="dmalloc.html#SEC21">Disabling the Library</A>: How to compile/link without the library.
<P>
Using Dmalloc With a Debugger.
<P>
<LI><A HREF="dmalloc.html#SEC27">General Errors</A>: Diagnosing general problems with a debugger.
<LI><A HREF="dmalloc.html#SEC28">Memory Leaks</A>: Tracking down non-freed memory.
<LI><A HREF="dmalloc.html#SEC29">Fence-Post Overruns</A>: Diagnosing fence-post overwritten memory.
</UL>
<P>
