home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sources / misc / 3903 < prev    next >
Encoding:
Text File  |  1992-09-04  |  56.7 KB  |  2,001 lines

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