home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbmalloc.zip / malloc.man < prev    next >
Text File  |  1993-01-04  |  45KB  |  1,585 lines

  1.  
  2.  
  3.  
  4.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  5.  
  6.  
  7.  
  8.      NAME
  9.       dbmalloc - debugging malloc library
  10.  
  11.      SYNOPSIS
  12.       #include <malloc.h>
  13.  
  14.       int malloc_chain_check(flag);
  15.       int flag;
  16.  
  17.       void malloc_dump(fd);
  18.       int fd;
  19.  
  20.       void malloc_list(fd,histid1,histid2);
  21.       int fd;
  22.       unsigned long    histid1, histid2;
  23.  
  24.       unsigned long    malloc_inuse(histidptr);
  25.       unsigned long    * histidptr;
  26.  
  27.       void malloc_mark(ptr);
  28.       char * ptr;
  29.  
  30.       int dbmallopt(cmd,val);
  31.       int cmd;
  32.       union    dbmalloptarg val;
  33.  
  34.       void malloc_abort();
  35.  
  36.       void malloc_enter(func);
  37.       char * func;
  38.  
  39.       void malloc_leave(func);
  40.       char * func;
  41.  
  42.      DESCRIPTION
  43.       This malloc library is a replacement for the standard
  44.       library to be    used during software development/debugging.
  45.       See the standard malloc(3) pages for more information    on the
  46.       use of the following functions:
  47.  
  48.            calloc(), cfree(), free(), malloc(), realloc()
  49.  
  50.       This library differs from the    standard malloc    library    in the
  51.       following ways:
  52.  
  53.       1. Each malloc segment contains a magic number so that free
  54.       can verify that the pointer passed points to a valid malloc
  55.       segment.
  56.  
  57.       2. Each malloc segment is filled with    a non-zero pattern so
  58.       that code that depends upon malloc segments being null will
  59.       fail.
  60.  
  61.  
  62.  
  63.      Page 1               1.11
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  71.  
  72.  
  73.  
  74.       3. The size of each segment will be at least 1 byte larger
  75.       than requested and the extra bytes will be filled with a
  76.       non-zero pattern.  When free is called, it will verify that
  77.       you did not go beyond    the number of bytes you    asked for.
  78.  
  79.       4. When a segment is freed, it will be filled    with a
  80.       different non-zero pattern to    ensure that the    program
  81.       doesn't depend upon the use of already freed data.
  82.  
  83.       5. Whenever any of the string    or memory functions (str*, b*,
  84.       mem*)    are called with    a pointer that is within the malloc
  85.       arena,  the operation    is checked to verify that it does not
  86.       overrun the malloced segment.     A failure of this check is
  87.       considered a "warning    level error" (described    later) and is
  88.       handled accordingly.
  89.  
  90.       6. Run time checking can include verification    of the malloc
  91.       chain    at each    and every call to one of the malloc functions
  92.       or manually by calling the malloc_chain_check    function.
  93.  
  94.       7. Extensive support for tracking memory leaks is provided.
  95.  
  96.       When a problem is found, the following error message is
  97.       displayed:
  98.  
  99.            MALLOC Warning from funcname() (called from filename.c line ###):
  100.            Warning message goes here
  101.  
  102.       funcname is the name of the function that has    found the
  103.       problem and will usually be an entry point into the library.
  104.       The information that identifies where    the function is    called
  105.       from will only be available if the source module was
  106.       compiled with    the malloc.h file included.
  107.  
  108.       If the error is caused by a problem in the malloc chain and
  109.       the offending    chain element can be identified, the following
  110.       information is also displayed    (NOTE: this is just a guess by
  111.       the software,    it may not be the actual culprit):
  112.  
  113.            This error is *probably*    associated with    the following allocation:
  114.  
  115.           A call to malloc for 33 bytes    in program.c on    line 834.
  116.           This was the 172nd call to malloc.
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2               1.11
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  137.  
  138.  
  139.  
  140.       This example assumes that program.c included the debugging
  141.       library malloc.h file.  If not, the identification
  142.       information will be as follows:
  143.  
  144.            This error is *probably*    associated with    the following allocation:
  145.  
  146.           A call to malloc for 33 bytes    in an unknown file.
  147.           This was the 172nd call to malloc.
  148.  
  149.       The identification of    which call to malloc is    associated
  150.       with the problem is helpful in that it gives you the
  151.       information necessary    to set the breakpoint on the
  152.       allocation function for that particular invocation
  153.       (breakpoints usually can have    counters associated with
  154.       them).  The counters for the three primary allocation    entry
  155.       points (malloc, calloc, and realloc) are managed separately.
  156.  
  157.       NOTE 1: if you want to set a breakpoint to capture this
  158.       invocation of    malloc,    the actual function that is being
  159.       called is debug_malloc (or debug_realloc for realloc and
  160.       debug_calloc for calloc) and that is where the breakpoint
  161.       should be set.
  162.  
  163.       NOTE 2: Since    the software is    guessing at the    offending
  164.       malloc chain segment,    it is possible that one    of the nearby
  165.       segments is actually the culprit.  If    the environment
  166.       variable MALLOC_SHOW_LINKS is    set, both the segment
  167.       preceding and    the segment following the accused segment will
  168.       also be identified.  The following is    a sample output:
  169.  
  170.            This error is *probably*    associated with    the following allocation:
  171.  
  172.            A call to malloc for    33 bytes in an unknown file.
  173.            This    was the    172nd call to malloc.
  174.  
  175.            The malloc chain element prior to the suspect allocation is from:
  176.  
  177.            A call to calloc for    512 bytes in main.c line 16.
  178.            This    was the    4th call to calloc.
  179.            This    block was freed    on the 2nd call    to free()
  180.            in main.c on    line 51.
  181.  
  182.            The malloc chain element following the suspect allocation is    from:
  183.  
  184.            A call to realloc for 4096 bytes in func.c line 376.
  185.            This    was the    1st call to realloc.
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.      Page 3               1.11
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  203.  
  204.  
  205.  
  206.       Once the error message has been displayed, the software will
  207.       then determine how to    handle the error.  This    handling will
  208.       be based upon    the type of error level    (warning or fatal) and
  209.       the error handling in    effect for that    error level (as
  210.       specified by calls to    mallopt    or via environment variables).
  211.       The coding for the error handling is as follows:
  212.  
  213.         0    continue operations
  214.         1    drop core and exit
  215.         2    just exit
  216.         3    drop core, but continue    executing.  Core files will be
  217.         placed into core.[PID].[counter] i.e: core.00123.001
  218.       128    dump malloc chain and continue
  219.       129    dump malloc chain, dump    core, and exit
  220.       130    dump malloc chain, exit
  221.       131    dump malloc chain, dump    core, continue processing
  222.  
  223.       dbmallopt() is used to set the malloc    debugging options. The
  224.       following options can    be set:
  225.  
  226.       MALLOC_WARN          set the error handling for warning level
  227.                   errors.  val.i is    an integer that    can
  228.                   contain any one of the following values:
  229.  
  230.                   M_HANDLE_IGNORE      ignore error (just
  231.                           display warning
  232.                           message and continue
  233.                           processing)
  234.                   M_HANDLE_ABORT      drop core and    exit
  235.                   M_HANDLE_EXIT      just exit (no    core
  236.                           drop)
  237.                   M_HANDLE_CORE      drop core, but keep
  238.                           on going
  239.  
  240.                   In addition, M_HANDLE_DUMP may be    or'd
  241.                   in to cause a dump of the    current    malloc
  242.                   chain.
  243.  
  244.                   The default action for MALLOC_WARN is
  245.                   M_HANDLE_IGNORE.
  246.  
  247.       MALLOC_FATAL          set the error handling for fatal level
  248.                   errors.  val.i is    equivalent to val.i
  249.                   for MALLOC_WARN.
  250.  
  251.                   The default action for MALLOC_FATAL is
  252.                   M_HANDLE_ABORT.
  253.  
  254.       MALLOC_ERRFILE      set the destination for malloc error
  255.                   messages.     val.str is a pointer to a
  256.                   character    string containing the name of
  257.                   the file to be used for error messages.
  258.  
  259.  
  260.  
  261.      Page 4               1.11
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  269.  
  270.  
  271.  
  272.                   Note that    error messages are APPENDED to
  273.                   this file, so existing error messages
  274.                   will not be removed.
  275.  
  276.                   If MALLOC_ERRFILE    is not set, all    error
  277.                   messages will be sent to stderr.
  278.  
  279.       MALLOC_CKCHAIN      set the malloc chain checking flag.  If
  280.                   val.i is non-zero, chain checking    at
  281.                   every call to malloc is turned on. The
  282.                   default behavior is to not check the
  283.                   chain at each call to malloc because of
  284.                   performance issues (the library is
  285.                   considerably slower when this function
  286.                   is enabled).
  287.  
  288.       MALLOC_FREEMARK     sets the behavior    of freeing of marked
  289.                   areas.  By default, a free of a marked
  290.                   segment generates    a warning.  If val.i
  291.                   is zero, warnings    will not be generated.
  292.  
  293.       MALLOC_FILLAREA     set the malloc fill area flag.  val.i
  294.                   specifies    the malloc filling mode    to be
  295.                   used.   There are    four modes: 0, 1, 2
  296.                   and 3.  Mode 0 disables all filling and
  297.                   checking of filled areas (thereby
  298.                   reducing the effectiveness of the
  299.                   library).     Mode 1    enables    the filling of
  300.                   boundary areas before and    after the
  301.                   allocation areas which are used to check
  302.                   for writing before or after the pointer.
  303.                   Mode 2 includes mode 1 and adds the
  304.                   filling of malloced regions with a
  305.                   specified    fill pattern so    that a program
  306.                   does not depend upon malloced regions to
  307.                   be filled    with zeros.  Mode 3 includes
  308.                   all of mode 2 and    adds the filling of
  309.                   free'd regions so    that an    attempt    to
  310.                   used a freed data    area will result in an
  311.                   error.
  312.  
  313.                   As far as    performance is concerned, mode
  314.                   0    will be    the fastest mode, while
  315.                   (somewhat    unexpectedly) mode 3 is    the
  316.                   next "fastest" mode with mode 1 bring up
  317.                   the tail end.
  318.  
  319.                   The default behavior for MALLOC_FILLAREA
  320.                   is mode 3.
  321.  
  322.       MALLOC_LOWFRAG      set the malloc allocation    fragmentation
  323.                   handling level.  By default, malloc uses
  324.  
  325.  
  326.  
  327.      Page 5               1.11
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  335.  
  336.  
  337.  
  338.                   a    first fit algorithm for    new
  339.                   allocations.  Under certain allocation
  340.                   scenarios, this can lead to significant
  341.                   memory fragmentation because of the fact
  342.                   that little allocations can break    big
  343.                   blocks up.
  344.  
  345.                   If val.i is non-zero, malloc uses    a best
  346.                   fit algorithm which will reduce
  347.                   fragmentation.  This mechanism, while
  348.                   using less memory, is slower because the
  349.                   entire free list is checked instead of
  350.                   just checking until we find a segment
  351.                   that is at least big enough.  Normally
  352.                   you will not need    to set this variable.
  353.  
  354.       MALLOC_CKDATA          enable/disable the checking of pointers
  355.                   passed to    the memory (mem*,b*) and
  356.                   string (str*) functions.    This can be
  357.                   used to startup the code with checking
  358.                   disabled (when you know the startup code
  359.                   is functioning correctly)    and then turn
  360.                   it on later when you get into the    area
  361.                   of the code that is in question.
  362.  
  363.                   if val.i is non-zero, pointer checking
  364.                   is enabled (which    is the default mode).
  365.  
  366.       MALLOC_REUSE          enable/disable the reuse of freed
  367.                   segments.     This option can be used to
  368.                   help identify where a freed pointer is
  369.                   being re-used, or    where it is being
  370.                   freed a second time, since the location
  371.                   where it was freed is also kept.
  372.  
  373.                   It should    be noted that the memory
  374.                   requirements for a program will
  375.                   typically    increase significantly if this
  376.                   option is    used.
  377.  
  378.                   if val.i is zero,    freed segments are not
  379.                   reused for subsequent allocations.   If
  380.                   non-zero,    freed segments can be reused.
  381.                   If freed segments    are not    re-used, you
  382.                   might want to disable filling of freed
  383.                   segments (see the    MALLOC_FILLAREA
  384.                   discussions) so that you can see the
  385.                   data in the segment - this would be fill
  386.                   mode 2 or    below.
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.      Page 6               1.11
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  401.  
  402.  
  403.  
  404.       For example, to set up the session to    generate a core    file
  405.       for every malloc warning, to drop core and exit on a malloc
  406.       fatal, and to    log all    messages to the    file "malloc_log" do
  407.       the following:
  408.  
  409.            #include    <malloc.h>
  410.            union dbmalloptarg  m;
  411.  
  412.            m.i = M_HANDLE_CORE | M_HANDLE_DUMP;
  413.            dbmallopt(MALLOC_WARN,m);
  414.  
  415.            m.i = M_HANDLE_ABORT;
  416.            dbmallopt(MALLOC_FATAL,m);
  417.  
  418.            m.str = "malloc_log";
  419.            dbmallopt(MALLOC_ERRFILE,m);
  420.  
  421.       dbmallopt() can be used to set/alter the debugging options
  422.       at any time (i.e. you    may want to turn on chain-checking
  423.       after    the program startup if the program startup does    a lot
  424.       of allocations which are known to be OK).
  425.  
  426.       malloc_chain_check() will check the status of    the malloc
  427.       arena.  If flag is non-zero, an error    found in the chain
  428.       will cause a fatal error.  malloc_chain_check() returns zero
  429.       when there are no problems found in the malloc chain,    non-
  430.       zero otherwise.
  431.  
  432.       malloc_dump()    will dump a list of all    in-use malloc segments
  433.       and the first    few bytes of each segment.  If the environment
  434.       variable MALLOC_DETAIL is set    to a non-zero integer, all
  435.       segments (including those that have been freed) are listed
  436.       and additional internal information is displayed.  fd    is the
  437.       file descriptor to write the data to.
  438.  
  439.       malloc_list()    will dump a list in the    same format as
  440.       malloc_dump but only the items that are still    in use and
  441.       which    have been allocated within the malloc history id range
  442.       specified by histid1 and histid2, inclusive.    The histids
  443.       are obtained from calls to malloc_inuse(). This is
  444.       especially useful in tracking    down memory leaks.  fd is the
  445.       file descriptor to write the data to.
  446.  
  447.       malloc_inuse() returns the amount of malloc data that    is
  448.       currently in use (in bytes).    If histidptr is    not NULL, it
  449.       is taken to be a pointer to a    place to store the current
  450.       malloc history id which can be used later when malloc_list
  451.       is called to list items that are still in use.
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7               1.11
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  467.  
  468.  
  469.  
  470.       The following    example    shows the typical use of the
  471.       malloc_inuse and malloc_list functions in tracking down
  472.       memory leaks:
  473.  
  474.            unsigned    long  histid1, histid2,    orig_size, current_size;
  475.  
  476.            orig_size = malloc_inuse(&histid1);
  477.  
  478.            /* .....    go do lots of stuff ...... */
  479.  
  480.            current_size = malloc_inuse(&histid2);
  481.  
  482.            if( current_size    != orig_size )
  483.            {
  484.             malloc_list(2,histid1,histid2);
  485.            }
  486.  
  487.       malloc_mark()    marks a    segment    as a non-leak.    Segments that
  488.       are marked are not counted or    listed when dealing with
  489.       memory leaks.     This is designed to be    used on    pointers that
  490.       remain around    forever    and shouldn't be considered to be a
  491.       leak (in order to decrease the amount    of entries in the leak
  492.       lists)
  493.  
  494.       malloc_abort() causes    the current program to drop core and
  495.       exit.     This function simply calls abort() to do its dirty
  496.       work and is here solely for the purpose of allowing the
  497.       programmer to    substitute thier own abort routine to handle
  498.       fatal    errors.     If a substitute routine is used, it must not
  499.       return to the    caller or else the program will    use the
  500.       abort() system call to cause the program to stop.
  501.  
  502.       malloc_enter() and malloc_leave() provide a rudimentary
  503.       mechanism to track the calling stack that was    in place when
  504.       the allocation was made.  In order to    use this feature, the
  505.       enter    function should    be called upon entry to    a function,
  506.       while    the leave function is called when you exit from    the
  507.       function.  In    order to be accurate, the two functions    must
  508.       be used in conjunction with each other and a missing call
  509.       will result in an error generated by the library (if it is
  510.       detected).
  511.  
  512.       NOTE:    the argument to    either of these    functions must be a
  513.       constant character string or a static    data area.  This is
  514.       because the stack mechanism does not maintain    it's own copy
  515.       of these strings, it just records pointers to    the strings
  516.       and if the strings are on the    stack, they will go away.
  517.       Typically the    functions would    be used    with "funcname"    as the
  518.       argument and this will avoid any problems.
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.      Page 8               1.11
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  533.  
  534.  
  535.  
  536.       The stack is listed on the dump and/or list reports and on
  537.       an error message for a segment that has already been freed.
  538.  
  539.       If these functions have been used, error messages will
  540.       include the stack information    when the identity of the error
  541.       is displayed.     For example:
  542.  
  543.            This error is *probably*    associated with    the following allocation:
  544.  
  545.            A call to malloc for    1 bytes    in teststack.c on line 75.
  546.            This    was the    13th call to malloc.
  547.            Stack from where allocated:
  548.             -> sub3() in teststack.c(73)
  549.             -> sub2() in teststack.c(59)
  550.             -> main() in teststack.c(23)
  551.  
  552.  
  553.  
  554.      USAGE
  555.       The library can be used in several modes, each increasingly
  556.       intrusive (i.e. requiring changes to be made to the build
  557.       process and/or source    code).    However, the extra cost    of a
  558.       little intrusiveness is repaid in much better    problem
  559.       identification.  Each    mode is    built upon the previous    modes
  560.       and therefore    requires the changes and/or commands specified
  561.       in the lower modes.
  562.  
  563.       MODE 1 - library substitution
  564.  
  565.       The simplest use is to just link the object module with the
  566.       libdbmalloc.a.  Be sure to have this library before the C
  567.       library (libc.a) on the link command (this is    automatic if
  568.       you use cc to    link and specify the debug library without
  569.       specifying the C library).
  570.  
  571.       This mode links in all of the    debug versions of the library
  572.       modules and will trap    as many    errors as it can (yes, there
  573.       are errors that the malloc library cannot catch).
  574.       Environment variables    can be used to control the behavior of
  575.       the library.
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.      Page 9               1.11
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  599.  
  600.  
  601.  
  602.       MODE 2 - malloc.h inclusion
  603.  
  604.       This mode involves including the malloc.h file included with
  605.       the debugging    library.  The malloc.h file includes macros
  606.       that will identify the source    line and file name for each
  607.       debugging function called.  This is how the library is able
  608.       to tell you that it was the call to malloc on    line 55    in
  609.       file junk.c.
  610.  
  611.       Typically you    should always include malloc.h in your source
  612.       files    and just use the -I INCLUDEDIR directive for the
  613.       compiler to point the    compiler to the    debugging version of
  614.       the header file instead of the normal    file.  That way    you
  615.       don't    have to    change the source files    when you want to turn
  616.       off the debugging library.
  617.  
  618.       NOTE:    Once you compile code in this mode, you    must recompile
  619.       the code without the debugging malloc.h include file in
  620.       order    to get the software to use the non-debugging
  621.       functions.
  622.  
  623.       MODE 3 - run-time specification of options
  624.  
  625.       Environment variables    can be used to control the behavior of
  626.       the debugging    library    to some    extent.     However, this control
  627.       is very coarse in that you only have one setting available
  628.       for the entire running of the    program.
  629.  
  630.       This can be a    problem    if you want to turn on malloc chain
  631.       checking, but    know that the problem occurs between a
  632.       relatively narrow portion of the code    and don't want to take
  633.       the hit of having chain checking on for the entire program
  634.       execution.
  635.  
  636.       The solution to this problem is to include calls to
  637.       dbmallopt() with the debugging options which set the
  638.       appropriate modes when you want them set.  Since you don't
  639.       want to have to change the code to remove and    add these
  640.       functions every time you decide to include malloc debugging
  641.       or not, the malloc.h file defines the    preprocessor symbol
  642.       _DEBUG_MALLOC_INC which can be used in your code as follows:
  643.  
  644.            #ifdef _DEBUG_MALLOC_INC
  645.             dbmallopt(.... );
  646.            #endif
  647.  
  648.       In addition to setting behavior options, you might want to
  649.       make use of the memory leak detection    routines in this mode.
  650.       These    calls should also be surrounded    by #ifdefs for the
  651.       debug    malloc symbol so that you can leave them in the    code
  652.       and automatically get    the increased functionality whenever
  653.       you compile with the debugging library.
  654.  
  655.  
  656.  
  657.      Page 10               1.11
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  665.  
  666.  
  667.  
  668.       MODE 4 - deeper inclusion of malloc calls
  669.  
  670.       This mode involves inserting calls to    the special functions
  671.       supported by the malloc library (like    the leak detection or
  672.       stack    maintenance routines).    The effects of the inclusions
  673.       depends upon the modules included and    the amount to which
  674.       they are used.
  675.  
  676.       It is    strongly recommended that you setup your code with the
  677.       following lines in a header file that    is included by all
  678.       modules, or just add the code    to the beginning of the
  679.       modules themselves:
  680.  
  681.            #ifndef _DEBUG_MALLOC_INC
  682.            #define malloc_enter(func)
  683.            #define malloc_leave(func)
  684.            #define malloc_chain_check()
  685.            #define malloc_dump(fd)
  686.            #define malloc_list(a,b,c)
  687.            #define malloc_inuse(hist)    (*(hist) =    0, 0)
  688.            #endif
  689.  
  690.       This will automatically disable the referenced functions
  691.       when the malloc library is not included (as should be    the
  692.       case when you    make a production build).
  693.  
  694.      ENVIRONMENT VARIABLES
  695.       Environment variables    can be used to control error handling,
  696.       error    logging    and malloc chain checking at run time.    Most
  697.       of these environment variables can be    set via    the
  698.       dbmallopt() routine and are well described in    that portion
  699.       of the document.  Look for further information there.
  700.  
  701.       The following    environment variables are used:
  702.  
  703.       MALLOC_BOUNDSIZE    This specifies the minimum number    of
  704.                   bytes that the allocation    routines will
  705.                   leave unused at the end of each segment.
  706.                   This value may be    any non-zero positive
  707.                   integer (although    you must remember that
  708.                   the amount of memory used    is directly
  709.                   related to this buffer area.
  710.  
  711.                   It may be    necessary to increase this
  712.                   value if you think you have a module
  713.                   that is writing far enough beyond    its
  714.                   malloc segment that it changes the next
  715.                   segment (and therefore doesn't make a
  716.                   change that this library would be    able
  717.                   to detect.
  718.  
  719.                   The default for this value is 1
  720.  
  721.  
  722.  
  723.      Page 11               1.11
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  731.  
  732.  
  733.  
  734.                   (although    because    of memory alignment
  735.                   issues, you will usually have more than
  736.                   one byte of filler at the    end of most
  737.                   segments).
  738.       MALLOC_CKCHAIN      if 1, turns on malloc chain checking at
  739.                   every call to any    of the malloc
  740.                   functions.
  741.       MALLOC_DETAIL          if set to    a non-zero integer,
  742.                   malloc_dump shows    some internal detail
  743.                   for each entry in    the chain.  This info
  744.                   is probably only of use if you are
  745.                   debugging    the malloc library itself.
  746.       MALLOC_ERRFILE      specifies    the error log file for error
  747.                   messages.     Error messages    generated by
  748.                   the library are APPENDED to this file,
  749.                   so if you    want a clean file, you will
  750.                   have to remove or    empty it yourself
  751.                   between runs.  If    this option is used,
  752.                   no indication of an error    will be    sent
  753.                   to stdout    or stderr (this    is
  754.                   purposefully done    this way so that if
  755.                   you are running a    full screen program,
  756.                   it doesn't mess up the screen).
  757.       MALLOC_FATAL          specifies    the error handling for fatal
  758.                   errors
  759.       MALLOC_FILLAREA     specifies    the fill area flag setting.
  760.                   If zero, malloc/free area    filling    and
  761.                   checking is disabled (thereby increasing
  762.                   performance, while decreasing
  763.                   effectiveness of the library).  See the
  764.                   discussion of the    dbmallopt() arguments
  765.                   for more info on other settings.
  766.       MALLOC_FILLBYTE     This specifies the integer value of the
  767.                   character    to use when filling allocated
  768.                   areas.  This value defaults to 1 and
  769.                   must be within the range of 0 - 255.
  770.                   This capability is useful    if you believe
  771.                   that you are having a problem with code
  772.                   that is trashing its malloc region with
  773.                   a    data pattern that matches the default
  774.                   fill pattern.
  775.  
  776.                   NOTE: if an attempt is made to use a
  777.                   value outside the    specified range, the
  778.                   new value    is silently ignored and    the
  779.                   default is used.
  780.       MALLOC_FREEBYTE     This specifies the integer value of the
  781.                   character    to use when filling freed
  782.                   areas.  This value defaults to 1 and
  783.                   must be within the range of 0 - 255. It
  784.                   should also be different from
  785.                   MALLOC_FILLBYTE, but that    is not
  786.  
  787.  
  788.  
  789.      Page 12               1.11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  797.  
  798.  
  799.  
  800.                   enforced.
  801.  
  802.                   NOTE: if an attempt is made to use a
  803.                   value outside the    specified range, the
  804.                   new value    is silently ignored and    the
  805.                   default is used.
  806.       MALLOC_LOWFRAG      if 1, turns on best fit allocation
  807.                   algorithm.  Otherwise, first fit
  808.                   algorithm    is used    for finding allocation
  809.                   segments (which can cause    memory
  810.                   fragmentation).
  811.       MALLOC_CKDATA          if 0, disables checking of pointers
  812.                   passed to    string/memory functions    for
  813.                   malloc region overwrites.
  814.       MALLOC_REUSE          if 0, disables reuse of freed memory
  815.                   segments and it does not fill free'd
  816.                   segments with the    fill pattern.  If 1,
  817.                   freed segments are filled    and they can
  818.                   be reused.  If 2,    freed segments can be
  819.                   reused, but they are not filled when
  820.                   freed.
  821.       MALLOC_SHOW_LINKS   when an error is found, the suspected
  822.                   allocation is displayed.    However, since
  823.                   it is possible that the next or previous
  824.                   allocation in the    malloc chain was the
  825.                   actual culprit these links may be    of
  826.                   interest.     If this variable is set to a
  827.                   non-zero integer (i.e. 1)    the links will
  828.                   also be shown.
  829.       MALLOC_WARN          specifies    the error handling for warning
  830.                   errors
  831.  
  832.       As an    example, to set    up the session to generate a core file
  833.       for every malloc warning, to drop core and exit on a malloc
  834.       fatal, and to    log all    messages to the    file "malloc_log" do
  835.       the following:
  836.  
  837.            MALLOC_WARN=131
  838.            MALLOC_FATAL=1
  839.            MALLOC_ERRFILE=malloc_log
  840.  
  841.            export MALLOC_WARN MALLOC_FATAL MALLOC_ERRFILE
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.      Page 13               1.11
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  863.  
  864.  
  865.  
  866.      ERROR MESSAGES
  867.       The following    error messages are reported by the library:
  868.  
  869.       M_CODE_BAD_CONNECT        Pointers between this segment
  870.                     and adjoining segments are
  871.                     invalid.
  872.  
  873.                     This error indicates that the
  874.                     malloc chain has been
  875.                     corrupted.  This is most often
  876.                     caused by an overwrite of the
  877.                     malloc header by an access via
  878.                     the previous malloc segment.
  879.  
  880.       M_CODE_BAD_MAGIC        Malloc region does not have a
  881.                     valid magic number in header.
  882.  
  883.                     This error is caused by
  884.                     several    mechanisms including
  885.                     free()ing the same pointer
  886.                     twice or a pointer that    was
  887.                     not returned by    malloc(), or
  888.                     writing    beyond the end of a
  889.                     segment.
  890.  
  891.       M_CODE_BAD_PTR        Pointer    is not within malloc
  892.                     region.
  893.  
  894.                     The pointer passed to free
  895.                     orrealloc is not pointer
  896.                     returned by malloc.  Another
  897.                     cause is corruption of the
  898.                     malloc chain by    writing    beyond
  899.                     the end    of a segment.
  900.  
  901.       M_CODE_CHAIN_BROKE        Malloc chain is    corrupted,
  902.                     pointers out of    order.
  903.  
  904.                     Corruption has been detected
  905.                     in the malloc chain that is
  906.                     related    to the relative
  907.                     positions of the malloc    chain
  908.                     segments in memory.  This is
  909.                     an indication that someone has
  910.                     overwritten beyond the amount
  911.                     they allocated.
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.      Page 14               1.11
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  929.  
  930.  
  931.  
  932.       M_CODE_FREELIST_BAD        Malloc segment in free list is
  933.                     in-use.
  934.  
  935.                     A segment that is in the
  936.                     free-list is flagged as    in-
  937.                     use.  This is usually caused
  938.                     by overwriting from the
  939.                     previous segment in the    malloc
  940.                     chain.
  941.  
  942.       M_CODE_FREEMARK        Free called to free a segment
  943.                     that has been marked.
  944.  
  945.                     Marking    a segment is done
  946.                     because    you believe that the
  947.                     segment    will not be free'd and
  948.                     therefore don't    want it    to
  949.                     appear in the list of possible
  950.                     leaks.    If you then go on to
  951.                     free it, perhaps it shouldn't
  952.                     have been marked.
  953.  
  954.                     This error message can be
  955.                     disabled with the
  956.                     MALLOC_FREEMARK    option on the
  957.                     dbmallopt() function.
  958.  
  959.       M_CODE_NOBOUND        Unable to determine doubleword
  960.                     boundary
  961.  
  962.                     The code was unable to figure
  963.                     out the    boundary requirements
  964.                     for a doubleword.  This    error
  965.                     should never occur.
  966.  
  967.       M_CODE_NOMORE_MEM        Unable to get additional
  968.                     memory from the    system.
  969.  
  970.                     The system call    sbrk failed to
  971.                     obtain more memory for the
  972.                     program.
  973.  
  974.       M_CODE_NOT_INUSE        Data is    not in use (can't be
  975.                     freed or reallocated).
  976.  
  977.                     A pointer to a malloc segment
  978.                     has been passed    to free() or
  979.                     realloc(), but this segment
  980.                     has already been freed.
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.      Page 15               1.11
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  995.  
  996.  
  997.  
  998.       M_CODE_NO_END            Malloc chain is    corrupted, end
  999.                     before end pointer.
  1000.  
  1001.                     Yet another overwrite problem.
  1002.                     This error means that we got
  1003.                     to what    we believe is the end
  1004.                     of the chain, but it does not
  1005.                     match the recorded end of the
  1006.                     chain.
  1007.  
  1008.       M_CODE_OUTOF_BOUNDS        Pointer    within malloc region,
  1009.                     but outside of malloc data
  1010.                     bounds.
  1011.  
  1012.                     This is    caused by a call to
  1013.                     one of the string/memory
  1014.                     functions that attempt to
  1015.                     read/write bytes that are not
  1016.                     included in the    allocation
  1017.                     associated with    that memory.
  1018.                     This is    the most typical error
  1019.                     that you will see from the
  1020.                     malloc library.
  1021.  
  1022.       M_CODE_OVERRUN        Data has overrun beyond
  1023.                     requested number of bytes.
  1024.  
  1025.                     This error is detected by
  1026.                     free() and indicates that the
  1027.                     current    segment    has written
  1028.                     data beyond the    number of
  1029.                     bytes that it requested.  This
  1030.                     only catches overwrites    when
  1031.                     they are within    the extra
  1032.                     space allocated    with each
  1033.                     segment    (this can range    from
  1034.                     one to eight bytes).  If the
  1035.                     overwrite occurs further along
  1036.                     it will    usually    cause some
  1037.                     corruption in the malloc
  1038.                     chain.
  1039.  
  1040.       M_CODE_REUSE            Data in    free'd area has    been
  1041.                     modified.
  1042.  
  1043.                     Data in    a freed    segment    has
  1044.                     been modified.    This usually
  1045.                     indicates that the program is
  1046.                     using a    pointer    after it
  1047.                     called free, but it may    also
  1048.                     be caused by an    overwrite from
  1049.                     a previous segment in the
  1050.  
  1051.  
  1052.  
  1053.      Page 16               1.11
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1061.  
  1062.  
  1063.  
  1064.                     chain.
  1065.  
  1066.       M_CODE_STK_BADFUNC        Current    function name doesn't
  1067.                     match name on stack.
  1068.  
  1069.                     malloc_leave() was called with
  1070.                     a function name    that is    not
  1071.                     the current function.  This is
  1072.                     usually    caused by a missing
  1073.                     call to    malloc_enter() in the
  1074.                     same function, or a missing
  1075.                     call to    malloc_leave() in a
  1076.                     sub-function.
  1077.  
  1078.       M_CODE_STK_NOCUR        No current function on stack,
  1079.                     probably missing call to
  1080.                     malloc_enter().
  1081.  
  1082.                     malloc_leave() was called with
  1083.                     a function name    and there is
  1084.                     no current function (the stack
  1085.                     is empty). This    is usually
  1086.                     caused by a missing call to
  1087.                     malloc_enter(),    or an extra
  1088.                     call to    malloc_leave() in the
  1089.                     same function.
  1090.  
  1091.       M_CODE_UNDERRUN        Data has written before
  1092.                     beginning of requested bytes.
  1093.  
  1094.                     This error is detected by
  1095.                     free() and indicates that the
  1096.                     current    segment    has written
  1097.                     data before the    beginning of
  1098.                     the requested block.  This
  1099.                     only catches overwrites    when
  1100.                     they are within    the extra
  1101.                     space allocated    before each
  1102.                     segment    (this is usually four
  1103.                     bytes).     If the    overwrite
  1104.                     occurs further back it will
  1105.                     usually    cause some corruption
  1106.                     in the malloc chain.
  1107.  
  1108.       M_CODE_ZERO_ALLOC        An allocation routine was
  1109.                     called to allocate zero    bytes.
  1110.  
  1111.                     While ANSI C requires that
  1112.                     allocations of zero bytes are
  1113.                     permissible and    should be
  1114.                     supported, the behavior    of
  1115.                     such an    operation can be
  1116.  
  1117.  
  1118.  
  1119.      Page 17               1.11
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1127.  
  1128.  
  1129.  
  1130.                     undefined on non-ANSI systems.
  1131.                     This warning will alert    you to
  1132.                     the locations where these
  1133.                     calls are made.
  1134.  
  1135.                     This error message can be
  1136.                     disabled with the MALLOC_ZERO
  1137.                     option on the dbmallopt()
  1138.                     function.
  1139.  
  1140.  
  1141.      DUMP OUTPUT
  1142.       Sample dump/list output:
  1143.  
  1144.            ************************** Dump of Malloc Chain ****************************
  1145.            POINTER       FILE     WHERE           LINE     ALLOC          DATA     HEX DUMP
  1146.            TO DATA        ALLOCATED          NUMBER     FUNCT         LENGTH  OF    BYTES 1-7
  1147.            --------    -------------------- ------- -------------- ------- --------------
  1148.            0x403DB4    teststack.c          75 malloc(1)         40 01010101010101
  1149.             -> sub3() in teststack.c(73)
  1150.             -> main() in teststack.c(23)
  1151.            0x403E0C    testerr.c          16 realloc(1)         20 01010101010101
  1152.  
  1153.       The info in each column is as    follows:
  1154.  
  1155.       POINTER          the pointer returned by the allocation
  1156.                   function (the pointer the    the allocated
  1157.                   data area).
  1158.  
  1159.       FILE              the name of the file where the
  1160.                   allocation function was called.  This
  1161.                   information is only available if the
  1162.                   source file includes the malloc.h    file
  1163.                   from this    library    (as opposed to the
  1164.                   system include file).  If    the source
  1165.                   file did not include this    file, the file
  1166.                   will be listed as    unknown    and the    line
  1167.                   number will be blank.  Note that any
  1168.                   malloc calls from    system libraries will
  1169.                   probably not have    been compiled with the
  1170.                   malloc.h file included and will
  1171.                   therefore    appear as unknown.
  1172.  
  1173.       LINE NUM          The line number of the line that called
  1174.                   the allocation function.    This field
  1175.                   will be left blank if the    malloc.h from
  1176.                   this library was not included in the
  1177.                   source file when it was compiled.
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.      Page 18               1.11
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1193.  
  1194.  
  1195.  
  1196.       ALLOC    FUNC          The allocation function called: malloc,
  1197.                   realloc, or calloc.  The number in
  1198.                   parenthesis following the    function name
  1199.                   is the call number for that particular
  1200.                   function.     For example: malloc(1)    means
  1201.                   that this    allocation was the 1st call to
  1202.                   malloc.
  1203.  
  1204.       DATA LEN          The number of bytes allocated.
  1205.  
  1206.       HEX DUMP          A    hexadecimal dump of the    first seven
  1207.                   bytes in the allocated data.  This
  1208.                   example shows the    bytes filled with
  1209.                   0x01s which happen to be the fill
  1210.                   pattern used by the malloc library (to
  1211.                   make sure    that one doesn't depend    upon
  1212.                   the fact that some calls to malloc
  1213.                   result in    NULL bytes).  So the
  1214.                   allocations that are shown haven't
  1215.                   stored any data in the area yet.
  1216.  
  1217.       The lines that begin with a "->" are stack dump lines    which
  1218.       show the calling environment that was    present    when the are
  1219.       was allocated.  The environment is managed via the use of
  1220.       the malloc_enter() and malloc_leave()    routines.
  1221.  
  1222.       If the environment variable MALLOC_DETAIL is non-zero, the
  1223.       following additional information will    be included:
  1224.  
  1225.            ************************************************************** Du...
  1226.                         FREE     FREE           ACTUAL SIZE      ...
  1227.          PTR      NEXT       PREV        NEXT     PREV      FLAGS       INT      HEX      ...
  1228.            --------    -------- -------- -------- -------- ---------- --------    --------- ...
  1229.            0x403C94    0x403CEC 0x40326C 0x000000 0x000000 0x03156111         48(0x000030) ...
  1230.            0x403CEC    0x403D2C 0x403C94 0x000000 0x000000 0x03156121         24(0x000018) ...
  1231.            0x403D2C    0x403D6C 0x403CEC 0x000000 0x403D6C 0x03156120         24(0x000018) ...
  1232.            0x403D6C    0x000000 0x403D2C 0x403D2C 0x000000 0x03156120         24(0x000018) ...
  1233.  
  1234.            Malloc start:      0x40326C
  1235.            Malloc end:      0x403D2C
  1236.            Malloc data start: 0x403C94
  1237.            Malloc data end:      0x405C94
  1238.            Malloc free list:  0x403D6C
  1239.                    -> 0x403D2C
  1240.  
  1241.       NOTE that I cut off the example at the point where the
  1242.       normal output    would begin (hence the ...).
  1243.  
  1244.       The info in each column is as    follows:
  1245.  
  1246.       PTR          The malloc chain pointer for the segment
  1247.               (the address of the segment).
  1248.  
  1249.  
  1250.  
  1251.      Page 19               1.11
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1259.  
  1260.  
  1261.  
  1262.       NEXT          The pointer to the next segment in the
  1263.               chain.
  1264.  
  1265.       PREV          The pointer to the previous segment in the
  1266.               chain.
  1267.  
  1268.       FREE NEXT      The pointer to the next segment in the free
  1269.               list.
  1270.  
  1271.       FREE PREV      The pointer to the previous segment in the
  1272.               free list.
  1273.  
  1274.       FLAGS          The flags associated with this segment.
  1275.               This is a long integer which contains    the
  1276.               following fields
  1277.  
  1278.               0xFFFFFF00  the magic    number.     This should
  1279.                       be 0x03156100 (probably
  1280.                       someone's    birthday).
  1281.  
  1282.               0x00000070  the type of allocation function.
  1283.                       Malloc (x010), realloc (0x20),
  1284.                       or calloc    (0x30) are the only
  1285.                       valid values for this field).
  1286.  
  1287.               0x00000001  the in-use flag.    if this    value
  1288.                       is non-zero, the indicated
  1289.                       segment is currently in use (not
  1290.                       freed).
  1291.  
  1292.       ACTUAL SIZE      The actual size reserved for the allocation
  1293.               in both decimal and hex.  This will be at
  1294.               least    one byte more than the requested size,
  1295.               and as much as 8, so that we can check to
  1296.               see if the allocation    has been overrun.
  1297.  
  1298.       Malloc start and end are pointers to the first and last
  1299.       malloc chain segment,    respectively.
  1300.  
  1301.       Malloc data start and    data end are the lowest    and highest
  1302.       data bytes managed my    the malloc sub-system.    These are only
  1303.       used as a quick check    to see if a pointer is in the malloc
  1304.       region before    we go hunting down the chain trying to
  1305.       identify the segment it belongs to.
  1306.  
  1307.       Malloc free list is a    chain of the elements in the free list
  1308.       (so it is easier for the programmer to follow    the free list
  1309.       if they choose to).  The address of each element in the list
  1310.       follows below    the list head.
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20               1.11
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1325.  
  1326.  
  1327.  
  1328.      X PROGRAM DEBUGGING
  1329.       The malloc library includes a    set of compatibility routines
  1330.       for the Xt toolkit allocation    routines: XtMalloc(),
  1331.       XtCalloc(), XtRealloc(),and XtFree().      These    routines
  1332.       provide the same level of malloc area    integrity checking
  1333.       that is provided by the basic    malloc functions while
  1334.       maintaining complete compatibility with the X11R5 functions.
  1335.  
  1336.       If you link an X package with    the debug library and you make
  1337.       a call to any    of the Xt allocation routines, the debug
  1338.       modules will automatically be    included.  If you don't    call
  1339.       them directly, but you still want to include them in order
  1340.       to better debug their    use, you can add a -u linker
  1341.       specification    for XtRealloc.    For example:
  1342.  
  1343.            cc -o xapp -u XtRealloc xapp.o -ldbmalloc -lXt -lX....
  1344.  
  1345.       Note that you    may have to add    an underscore before the
  1346.       XtRealloc if your compiler does this automatically.
  1347.  
  1348.       A second potential problem with X is caused by a difference
  1349.       between X11R4    and X11R5.  If you only    have one of theses
  1350.       packages, then the malloc library will be automatically
  1351.       configured to    handle that package.  If, however, you have
  1352.       both of them installed and you need to be able to link with
  1353.       either system, you may have to add a -u _XtHeapInit to the
  1354.       link line on the X11R5 links.     This is because X11R5 defines
  1355.       both the heap    management and malloc management routines in
  1356.       the same module, while X11R4 defines them in different
  1357.       modules.
  1358.  
  1359.       The sign of this problem is a    link error due to duplicate
  1360.       references to    the Xt allocation routines (XtMalloc, etc).
  1361.  
  1362.      LINKING
  1363.       The order in which you link your programs can    have a
  1364.       significant effect on    the usefulness of the library and even
  1365.       on the ability to link itself.  The debug library should be
  1366.       placed as the    first system library that you are linking to
  1367.       (assuming that you are calling at least one of the malloc,
  1368.       string, or memory functions).
  1369.  
  1370.       For example, if the following    is your    normal link command:
  1371.  
  1372.            cc -o app app.o supp.o else.o applib.a -lmath -lcurses
  1373.  
  1374.       You should add the malloc debug library in between applib.a
  1375.       and -lmath, which would result in the    following:
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.      Page 21               1.11
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1391.  
  1392.  
  1393.  
  1394.            cc -o app app.o supp.o else.o applib.a -ldbmalloc -lmath    -lcurses
  1395.  
  1396.       This will ensure that    the debug malloc library overrides all
  1397.       of the allocation routines within the    other libraries.
  1398.  
  1399.       If you have other problems compiling or linking with the
  1400.       library you should look at the PROBLEMS file in the source
  1401.       directory.  This file    contains descriptions of common
  1402.       problems and the recommended solutions to the    problems.
  1403.  
  1404.      PERFORMANCE
  1405.       This malloc library and its associated string    and memory
  1406.       functions are    much less efficient than the standard
  1407.       functions due    in part    to the extra error checking.  You do
  1408.       not want to use this library when generating a production
  1409.       (i.e.    releasable) version of your software.  It should only
  1410.       be used during development and testing.
  1411.  
  1412.       The following    environment variable settings will give    you
  1413.       the best performance (at the expense of some additional
  1414.       error    checking):
  1415.  
  1416.            MALLOC_CKCHAIN=0
  1417.            MALLOC_CKDATA=0
  1418.            MALLOC_FILLAREA=0
  1419.            MALLOC_LOWFRAG=0
  1420.  
  1421.       We recommend against setting MALLOC_FILLAREA to zero
  1422.       because, while it will increase the performance, it takes
  1423.       away the capability to uncover small malloc overruns which
  1424.       don't    overrite the pointers surrounding the malloc regions.
  1425.       The same anti-recommendation applies to MALLOC_CKDATA.
  1426.  
  1427.       Anyway, with these settings, the malloc library runs at
  1428.       about    1/2 the    speed (things only take    twice as long) as the
  1429.       standard library.  If    you program spends most    of its time in
  1430.       malloc, it will still    be slow    (but perhaps this is an
  1431.       indication that you need to consider changing    the way    you
  1432.       are using malloc).
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.      Page 22               1.11
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1457.  
  1458.  
  1459.  
  1460.      WARNINGS
  1461.       The include file for this library "malloc.h" should be
  1462.       included after the includes for any system related
  1463.       information.    This is    because    "malloc.h" redefines several
  1464.       system functions including string and    memory routines    and
  1465.       this will usually cause compilation errors if    malloc.h is
  1466.       processed first (of course, the compile errors will talk
  1467.       about    errors in the other system include files like
  1468.       string.h).
  1469.  
  1470.       This goes hand in hand with the fact that if you have    local
  1471.       definitions of the return types of standard functions    like
  1472.       strcmp() or malloc(),    these lines will cause compile errors
  1473.       due to the #defines in the malloc.h header file.  Therefore,
  1474.       it is    suggested that you remove all such definitions from
  1475.       your code and    rely on    the system header files    to define
  1476.       these    functions, or you surround the definitions with    #ifdef
  1477.       DEBUG_MALLOC_INC.
  1478.  
  1479.       There    is a possibility that the use of sbrk()    by other
  1480.       modules will cause this library to get confused and possibly
  1481.       report some pointers as bad when the really aren't part of
  1482.       the malloc chain itself.  Therefore the direct use of    sbrk()
  1483.       is strongly discouraged.
  1484.  
  1485.       This library attempts    to trap    errors and exit/handle them
  1486.       gracefully. However, the nature of the problems may be such
  1487.       that it causes the code in the library itself    to crash.
  1488.       There    is no way to avoid this, but if    it does    occur,    turn
  1489.       on chain checking to narrow the place    where it will occur.
  1490.  
  1491.       The functions    in this    library    will often conflict with
  1492.       duplicate functions in shared    library    versions of libc.a.
  1493.       This is usually due to the fact that some shared library
  1494.       modules have explicit    references to shared library versions
  1495.       of the debug functions.  The only way    around this is to not
  1496.       use the shared library when linking.
  1497.  
  1498.       This malloc library, like most malloc    libraries, is not re-
  1499.       entrant and therefore    should not be called from interrupt
  1500.       handlers because of the potential for    receiving an interrupt
  1501.       in the middle    of a call to malloc which would    really mess
  1502.       things up.
  1503.  
  1504.      SEE ALSO
  1505.       malloc(3), string(3),    memory(3)
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.      Page 23               1.11
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      DEBUG_MALLOC(3)           (VTI)           DEBUG_MALLOC(3)
  1523.  
  1524.  
  1525.  
  1526.      COPYRIGHT
  1527.        (c) Copyright 1990, 1991, 1992 Conor    P. Cahill (cpcahil@virtech.vti.com)
  1528.  
  1529.        This    software may be    distributed freely as long as the following conditions
  1530.        are met:
  1531.           * the    distribution, or any derivative    thereof, may not be
  1532.             included as    part of    a commercial product
  1533.           * full source    code is    provided including this    copyright
  1534.           * there is no    charge for the software    itself (there may be
  1535.             a minimal charge for the copying or    distribution effort)
  1536.           * this copyright notice is not modified or removed from any
  1537.               source file
  1538.  
  1539.  
  1540.      AUTHOR
  1541.       Conor    P. Cahill
  1542.       Virtual Technologies Incorporated
  1543.       46030    Manekin    Plaza, Suite 160
  1544.       Sterling VA 22170
  1545.       703-430-9247
  1546.  
  1547.       cpcahil@virtech.vti.com
  1548.       uunet!virtech!cpcahil
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.      Page 24               1.11
  1582.  
  1583.  
  1584.  
  1585.