home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / reviewed / volume02 / malloclb / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-03-31  |  57.3 KB

  1. From: Conor P. Cahill <cpcahil%virtech@uunet.UU.NET>
  2. Subject: v02i002: malloclib - Malloc Debugging Library, Part01/05
  3. Newsgroups: comp.sources.reviewed
  4. Approved: csr@calvin.dgbt.doc.ca
  5.  
  6. Submitted-by: Conor P. Cahill <cpcahil%virtech@uunet.UU.NET>
  7. Posting-number: Volume 2, Issue 2
  8. Archive-name: malloclib/part01
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 1 (of 5)."
  17. # Contents:  README CHANGES MANIFEST CHECKSUMS PROBLEMS Makefile
  18. #   Buildpatch calloc.c debug.h dump.c leak.c patchlevel tostring.h
  19. # Wrapped by cpcahil@virtech on Tue Jan 28 16:46:33 1992
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'README' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'README'\"
  23. else
  24. echo shar: Extracting \"'README'\" \(9797 characters\)
  25. sed "s/^X//" >'README' <<'END_OF_FILE'
  26. X# (c) Copyright 1990,1991 Conor P. Cahill. (uunet!virtech!cpcahil) 
  27. X# You may copy, distribute, and use this software as long as this
  28. X# copyright statement is not removed.
  29. X
  30. XThis package is a collection of routines which are a drop-in replacement
  31. Xfor the malloc(3), memory(3), string(3), and bstring(3) library functions.
  32. XThese replacement modules are different from the original modules in that
  33. Xthey provide a full set of debugging features which detect malloc 
  34. Xmemory overruns and other types of misuse.
  35. X
  36. XThe software has been developed for UNIX systems and should be somewhat
  37. Xportable amongst them.  Your milage will vary on other architectures. 
  38. X
  39. X
  40. X--------------------------------------------------------------------------
  41. XPORTING NOTES:
  42. X
  43. X1. Edit the makefile and set the appropriate flags for the compilations
  44. X
  45. X2. Review the settings for DATATYPE, SIZETYPE, and VOIDTYPE in malloc.h
  46. X   to make sure they conform to your system's requirements.  SIZETYPE will
  47. X   typically need to match what is used as an argument to malloc and/or
  48. X   what is returned by functions like strlen(). This will usually be
  49. X   one of the following:
  50. X
  51. X        int,  unsigned long, unsigned int, size_t
  52. X
  53. X   DATATYPE should match the type of pointer that is taken as an argument
  54. X   to memcpy, or what is returned by malloc() itself.  The pointer will 
  55. X   usually be char *, or void *.  Therefore DATATYPE will usually be 
  56. X   char or void.
  57. X
  58. X   VOIDTYPE will be void if your compiler supports the type void and int
  59. X   otherwise.
  60. X
  61. X3. Type make (See the PROBLEMS file if you have a problem compiling)
  62. X
  63. X4. Type make runtests to build and runt the tests (some of which will take
  64. X   a long time and some which will abort).  See the notes below for 
  65. X   more info on the tests and the expected output
  66. X
  67. X5. Install libdbmalloc.a and malloc.h somewhere where users can get
  68. X   to them by using make install (make sure INSTDIR is set correctly
  69. X   in the makefile)
  70. X
  71. X--------------------------------------------------------------------------
  72. XUSAGE:
  73. X
  74. XTo use the library, include the malloc.h header included with this
  75. Xlibrary ( this is not entirely necessary, but the identification of where
  76. Xthe problems originated will be much better if it is), compile the 
  77. Xobject files, and link with the libdbmalloc.a (make sure it is before
  78. Xthe libc.a on the link command - this is the default if you don't specifically
  79. Xinclude libc.a on your link).
  80. X
  81. XFor more info on how to use the library, see the man page in
  82. Xmalloc.3 ([nt]roff source) or malloc.man (already nroffed).
  83. X
  84. X--------------------------------------------------------------------------
  85. XTEST PROGRAMS
  86. X
  87. XThe library comes with several test programs that should be run before
  88. Xit is installed on the system.  There are three test programs:
  89. X
  90. Xtestmalloc - this program runs through zillions of mallocs/reallocs and frees
  91. Xin order to exercise the malloc system.  The output from this program will
  92. Xlook something like the following:
  93. X
  94. X    MAXITER 1000000 MAXOBJS 1000 BIGOBJ 90000, TINYOBJ 80, nbig/ntiny 1/100
  95. X    Memory use at start: 20140 bytes
  96. X    Starting the test...
  97. X    0 iterations
  98. X    10000 iterations
  99. X    20000 iterations
  100. X    ....(lots of iterations skipped)....
  101. X    980000 iterations
  102. X    990000 iterations
  103. X
  104. X    Did 1000000 iterations, 999 objects, 515733 mallocs, 484267 reallocs
  105. X    Memory use at end: 1617580 bytes
  106. X    Memory use after free: 1617580 bytes
  107. X
  108. X    ************************************************************...
  109. X                     FREE     FREE                 ...
  110. X      PTR      NEXT     PREV     NEXT     PREV      FLAGS     ...
  111. X    -------- -------- -------- -------- -------- ---------- -...
  112. X    0x403C30 0x407510 0x000000 0x000000 0x000000 0x00000000  ...
  113. X    0x407510 0x407640 0x403C30 0x000000 0x000000 0x03156111  ...
  114. X    0x407640 0x000000 0x407510 0x000000 0x000000 0x03156100  ...
  115. X    Malloc start:      0x403C30
  116. X    Malloc end:        0x407640
  117. X    Malloc data start: 0x407510
  118. X    Malloc data end:   0x58F510
  119. X    Malloc free list:  0x407640
  120. X
  121. X    startsize 20140 != endsize 1617580
  122. X
  123. XThis is normal output.  If it doesn't get to 1000000 iterations or if there
  124. Xare any allocations still in effect that were initiated by testmalloc.c,
  125. Xsomething went wrong (the library didn't pass the test).
  126. X
  127. XNote that there may be several entries in the malloc chain if the C startup
  128. Xfunction has allocated data before the main gets called.  The key is that
  129. Xthere are no allocated entries (those with the 1 bit on in the flags field)
  130. Xleft that are identified as being allocated within the testmalloc.c file.
  131. XIn the example above, the middle entry does in fact have the 1 bit on, but
  132. Xin the info that was cut-off, there was no indication that it was allocated
  133. Xwithin testmalloc.c, therefore it must have been allocated somewhere else.
  134. XThe last line in the chain will usually say it was allocated within testmalloc.c;
  135. Xhowever, as in this case, it will also indicate that it is not in use (the 1 
  136. Xbit will be off in the flags field).
  137. X
  138. XMost likely, if the program ran to completion (processed 1000000 iterations),
  139. Xthe test was successful.
  140. X
  141. XAlso note that this program does alot of allocations and will likely take
  142. Xa long time to run.  To decrease the amount of time it takes, set the 
  143. Xenvironment variable MALLOC_FILLAREA to 0 and run the test.  With this setting,
  144. Xthe test takes around 50 seconds on a 33MHZ 486.  Another way to speed up
  145. Xthe test is to decrease the number of itereations.  I won't do this on my
  146. Xsystem (or in the default) because I want to be sure that the malloc
  147. Xfunctions are well exercised.
  148. X
  149. Xtestmem - this program tests many of the string and memory functions to verify
  150. Xthat they work as they are supposed to.  You should get no output from this
  151. Xtest.  If you do, something is wrong.
  152. X
  153. Xtesterr - this program tests several malloc related program errors (to make
  154. Xsure that the library is correctly identifying the problems).  The output
  155. Xfrom the test goes to stderr and should be similar to the following (although
  156. Xbecause of machine architectures the error messages may be slightly different):
  157. X
  158. X    -------------------------------------
  159. X    Error from strcpy() - out of bounds
  160. X    MALLOC Warning from strncpy() (called from testerr.c line 27):
  161. X    Pointer within malloc region, but outside of malloc data bounds
  162. X    This error is *probably* associated with the following allocation:
  163. X
  164. X        A call to malloc for 10 bytes in testerr.c on line 23.
  165. X        This was the 2nd call to malloc.
  166. X
  167. X    -------------------------------------
  168. X    Error from memset() - out of bounds
  169. X    MALLOC Warning from memset() (called from testerr.c line 31):
  170. X    Pointer within malloc region, but outside of malloc data bounds
  171. X    This error is *probably* associated with the following allocation:
  172. X
  173. X        A call to malloc for 20 bytes in testerr.c on line 21.
  174. X        This was the 1st call to malloc.
  175. X
  176. X    -------------------------------------
  177. X    Error from free() - overrun
  178. X    MALLOC Warning from free() (called from testerr.c line 35):
  179. X    Data has overrun beyond requested number of bytes
  180. X    This error is *probably* associated with the following allocation:
  181. X
  182. X        A call to malloc for 20 bytes in testerr.c on line 21.
  183. X        This was the 1st call to malloc.
  184. X
  185. X    MALLOC Warning from free() (called from testerr.c line 35):
  186. X    Data has overrun beyond requested number of bytes
  187. X    This error is *probably* associated with the following allocation:
  188. X
  189. X        A call to malloc for 20 bytes in testerr.c on line 21.
  190. X        This was the 1st call to malloc.
  191. X
  192. X    -------------------------------------
  193. X    NO error from bzero
  194. X    -------------------------------------
  195. X    Error from bzero() - out of bounds
  196. X    MALLOC Warning from bzero() (called from testerr.c line 43):
  197. X    Pointer within malloc region, but outside of malloc data bounds
  198. X    This error is *probably* associated with the following allocation:
  199. X
  200. X        A call to malloc for 10 bytes in testerr.c on line 23.
  201. X        This was the 2nd call to malloc.
  202. X
  203. X    -------------------------------------
  204. X    Error from free() - overrun
  205. X    MALLOC Warning from free() (called from testerr.c line 47):
  206. X    Data has overrun beyond requested number of bytes
  207. X    This error is *probably* associated with the following allocation:
  208. X
  209. X        A call to malloc for 10 bytes in testerr.c on line 23.
  210. X        This was the 2nd call to malloc.
  211. X
  212. X    MALLOC Warning from free() (called from testerr.c line 47):
  213. X    Data has overrun beyond requested number of bytes
  214. X    This error is *probably* associated with the following allocation:
  215. X
  216. X        A call to malloc for 10 bytes in testerr.c on line 23.
  217. X        This was the 2nd call to malloc.
  218. X
  219. X    -------------------------------------
  220. X    Error from free() - invalid magic
  221. X    MALLOC Warning from free() (called from testerr.c line 51):
  222. X    Malloc region does not have valid magic number in header
  223. X    -------------------------------------
  224. X    Error from memset() - out of bounds
  225. X    MALLOC Warning from memset() (called from testerr.c line 58):
  226. X    Pointer within malloc region, but outside of malloc data bounds
  227. X    This error is *probably* associated with the following allocation:
  228. X
  229. X        A call to malloc for 10 bytes in testerr.c on line 53.
  230. X        This was the 3rd call to malloc.
  231. X
  232. X    -------------------------------------
  233. X    Error from malloc() - chain broken
  234. X    MALLOC Warning from malloc() (called from testerr.c line 62):
  235. X    Pointers between this segment and ajoining segments are invalid
  236. X    This error is *probably* associated with the following allocation:
  237. X
  238. X        A call to malloc for 10 bytes in testerr.c on line 53.
  239. X        This was the 3rd call to malloc.
  240. X
  241. X    MALLOC Warning from malloc() (called from testerr.c line 62):
  242. X    Malloc region does not have valid magic number in header
  243. X    MALLOC Fatal error from malloc() (called from testerr.c line 62):
  244. X    Pointer is not within malloc area
  245. X
  246. Xabort-core dumped (or something about SIGIOT) can be expected at the end
  247. Xof the test because of a purposefull overwrite of memory.  Depending upon the
  248. Xarchitecture, the purposful overwrite may actually cause some other form
  249. Xof core dump.  If it dumps somewhere in the last error, you can *probably*
  250. Xconsider it normal.
  251. X
  252. END_OF_FILE
  253. if test 9797 -ne `wc -c <'README'`; then
  254.     echo shar: \"'README'\" unpacked with wrong size!
  255. fi
  256. # end of 'README'
  257. fi
  258. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  259.   echo shar: Will not clobber existing file \"'CHANGES'\"
  260. else
  261. echo shar: Extracting \"'CHANGES'\" \(3311 characters\)
  262. sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  263. X$Id: CHANGES,v 1.8 1992/01/28 21:42:25 cpcahil Exp $
  264. X
  265. Xpatchlevel 7
  266. X
  267. X    - general
  268. X        - added support for overriding the use of void for systems
  269. X          that do not support it
  270. X        - added more info to the PROBLEMS and README files
  271. X    - free.c
  272. X        - added call to MALLOC_INIT to initialize the malloc subsystem
  273. X          when free is the first entry point.
  274. X    - malloc.c
  275. X        - fixed typo which resulted in truncation of error message
  276. X        - increased size of error string buffers and added
  277. X          overflow checks
  278. X    - malloc.h
  279. X        - added code so that it could be included by c++ programs
  280. X        - added additional info on setting SIZETYPE and DATATYPE
  281. X        - added code to prevent inclusions of string.h and memory.h
  282. X          after malloc.h has been included (since they conflict)
  283. X        - added prototypes for malloc_dump and malloc_list
  284. X        - added #ifdefs to get the code to compile outof the box for 
  285. X          known systems (hpux,IBMRS6000, and ISC UNIX)
  286. X    - memory.c
  287. X        - changed memccpy to only check the number of chars it is
  288. X          going to copy (some stdio implementations use memccpy with
  289. X          a source string that may not be the full length).
  290. X    - malloc.3
  291. X        - reformatted the SYNOPSIS section and cleaned up some other
  292. X          parts of the doc.
  293. X        - added more warnings about potential problems
  294. X    - Buildpatch
  295. X        - changed to build the patch based upon the old shar files,
  296. X          as opposed to the information in the RCS files
  297. X        - added verification of successful patch
  298. X    - Makefile
  299. X        - misc cleanups for making patch releases
  300. X        - removed \c escape sequende from test run script
  301. X
  302. Xpatchlevel 6
  303. X
  304. X    - README file updated with expanded porting/usage/test program info
  305. X    - PROBLEM file added to mention typical porting problems
  306. X    - CHECKSUMS file added to allow verification of proper transmission
  307. X    - NAME change - default library name changed to libdbmalloc.a so that
  308. X      it doesn't conflict with system libmalloc.a files.
  309. X    - performance enhancments 
  310. X        - selected use of registers for pointers referenced frequently
  311. X        - addition of free list chain, so allocations just search a
  312. X          list of available blocks
  313. X        - portable optimization of the malloc_memset function so that
  314. X          it is much faster when filling malloc'd areas
  315. X        - added ability to turn off pre/post-filling of malloced 
  316. X          areas via an environment variable and/or mallopt()
  317. X        - added option to override first fit algorithm with best fit
  318. X          algorithm (should reduce memory fragmentation)
  319. X    - use #if __STDC__ instead of #ifdef, so if the symbol is defined, but
  320. X      is not set to a 1, it is not interpreted as an ANSI C compiler
  321. X    - cleanup of some warnings from gcc -Wall
  322. X    - makefile changes
  323. X        - addition of manual page installation
  324. X        - added frcinstall target which forces installation
  325. X        - added DESTDIR (eqivalent to INSTDIR) which defaults to
  326. X          /usr/local
  327. X        - added targets to build and run tests and removed test
  328. X          building from the all target
  329. X        - documented usefull targets
  330. X        - changed to using cshar to generate shar files with MANIFEST
  331. X        - added building of CHECKSUMS file
  332. X    - manual page changes
  333. X        - minor changes to make it compatible with groff
  334. X        - fixed bug in eX macro which was causing fixed font output to
  335. X          be extremely wide
  336. X        - changed references to malloc_opt to mallopt and updated to 
  337. X          the correct usage (using the union malloptarg)
  338. X        - documented new environment variable to control fragmentation
  339. X
  340. X
  341. END_OF_FILE
  342. if test 3311 -ne `wc -c <'CHANGES'`; then
  343.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  344. fi
  345. # end of 'CHANGES'
  346. fi
  347. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  348.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  349. else
  350. echo shar: Extracting \"'MANIFEST'\" \(1848 characters\)
  351. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  352. X   File Name        Archive #    Description
  353. X-----------------------------------------------------------
  354. X README                     1    READ THIS FIRST
  355. X CHANGES                    1    List of changes
  356. X MANIFEST                   1    This shipping list
  357. X CHECKSUMS                  1    Checksums (BSD and SYSV) for each file
  358. X PROBLEMS                   1    List of typical porting/use problems
  359. X Makefile                   1    
  360. X Buildpatch                 1    Shell to build patch file
  361. X calloc.c                   1    calloc and related functions
  362. X debug.h                    1    debugging output header
  363. X dump.c                     1    malloc chain dumper
  364. X free.c                     2    free and related functions
  365. X leak.c                     1    memory leak detection stuff
  366. X m_init.c                   2    malloclib initializations
  367. X m_perror.c                 2    malloc error printer
  368. X malloc.3                   2    malloc man page ([nt]roff source)
  369. X malloc.c                   3    malloc and related functions
  370. X malloc.h                   2    include files for programs using the library
  371. X malloc.man                 4    nroff'd version of the manual page
  372. X malloc_chk.c               3    error checking modules
  373. X malloc_chn.c               3    chain checking modules
  374. X mallocint.h                3    internal header file
  375. X mallopt.c                  3    mallopt and related stuff
  376. X memory.c                   4    mem* and b* functions
  377. X patchlevel                 1    current patch level
  378. X prototypes.h               4    functional prototypes 
  379. X realloc.c                  4    realloc and related functions.
  380. X string.c                   5    str* functions
  381. X testerr.c                  3    error test program
  382. X testmalloc.c               5    malloc exerciser
  383. X testmem.c                  5    mem*/str*/b* exerciser
  384. X tostring.c                 3    numeric to string converter
  385. X tostring.h                 1    header for numeric converter
  386. END_OF_FILE
  387. if test 1848 -ne `wc -c <'MANIFEST'`; then
  388.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  389. fi
  390. # end of 'MANIFEST'
  391. fi
  392. if test -f 'CHECKSUMS' -a "${1}" != "-c" ; then 
  393.   echo shar: Will not clobber existing file \"'CHECKSUMS'\"
  394. else
  395. echo shar: Extracting \"'CHECKSUMS'\" \(1302 characters\)
  396. sed "s/^X//" >'CHECKSUMS' <<'END_OF_FILE'
  397. XSYSV sums:
  398. X
  399. X62610 4 MANIFEST
  400. X1187 1 patchlevel
  401. X27235 20 README
  402. X10037 12 PROBLEMS
  403. X23200 7 CHANGES
  404. X62145 7 Buildpatch
  405. X34105 13 Makefile
  406. X13678 55 malloc.3
  407. X16766 56 malloc.man
  408. X33884 54 malloc.c
  409. X19053 13 free.c
  410. X504 14 realloc.c
  411. X4903 7 calloc.c
  412. X45253 32 string.c
  413. X8370 16 malloc_chk.c
  414. X37030 12 malloc_chn.c
  415. X13781 16 memory.c
  416. X8736 6 tostring.c
  417. X59423 5 m_perror.c
  418. X64059 6 m_init.c
  419. X62288 6 mallopt.c
  420. X23987 19 dump.c
  421. X32181 6 leak.c
  422. X42372 9 testmalloc.c
  423. X24534 42 testmem.c
  424. X43850 3 testerr.c
  425. X48611 28 malloc.h
  426. X24913 8 mallocint.h
  427. X51173 6 debug.h
  428. X44284 2 tostring.h
  429. X20904 17 prototypes.h
  430. X
  431. XBSD sums (generated using sum -r on SYSV system):
  432. X
  433. X42144     4 MANIFEST
  434. X06674     1 patchlevel
  435. X41108    20 README
  436. X45711    12 PROBLEMS
  437. X07903     7 CHANGES
  438. X48438     7 Buildpatch
  439. X05384    13 Makefile
  440. X16416    55 malloc.3
  441. X41089    56 malloc.man
  442. X60527    54 malloc.c
  443. X34447    13 free.c
  444. X60381    14 realloc.c
  445. X16679     7 calloc.c
  446. X39948    32 string.c
  447. X19377    16 malloc_chk.c
  448. X16676    12 malloc_chn.c
  449. X25862    16 memory.c
  450. X50374     6 tostring.c
  451. X17174     5 m_perror.c
  452. X58901     6 m_init.c
  453. X13692     6 mallopt.c
  454. X53612    19 dump.c
  455. X63148     6 leak.c
  456. X11858     9 testmalloc.c
  457. X06136    42 testmem.c
  458. X04806     3 testerr.c
  459. X45851    28 malloc.h
  460. X01105     8 mallocint.h
  461. X41836     6 debug.h
  462. X19119     2 tostring.h
  463. X27295    17 prototypes.h
  464. END_OF_FILE
  465. if test 1302 -ne `wc -c <'CHECKSUMS'`; then
  466.     echo shar: \"'CHECKSUMS'\" unpacked with wrong size!
  467. fi
  468. # end of 'CHECKSUMS'
  469. fi
  470. if test -f 'PROBLEMS' -a "${1}" != "-c" ; then 
  471.   echo shar: Will not clobber existing file \"'PROBLEMS'\"
  472. else
  473. echo shar: Extracting \"'PROBLEMS'\" \(5936 characters\)
  474. sed "s/^X//" >'PROBLEMS' <<'END_OF_FILE'
  475. X
  476. XThis file documents the problems that have been found when the library
  477. Xis ported to different machines.  Where posible, a generic solution
  478. Xhas been added to the library so that the problem is not re-occuring.
  479. X
  480. X0. Compilation problems with the library itself.
  481. X
  482. X    This is a fairly common problem and is most often associated with
  483. X    the settings for SIZETYPE and DATATYPE.  If you get any compilation
  484. X    errors for modules within this library, the first thing you should
  485. X    do is verify that you are using the correct settings for these
  486. X    typedefs.  Review the description on what they should be set to and 
  487. X    review the original settings.
  488. X
  489. X    Another common problem is attempting to compile the library and/or
  490. X    test with a strict ANSI-C compiler.  Since ANSI reserves symbols
  491. X    like malloc, memcpy, strcpy, etc you can expect to have alot of
  492. X    problems.  This is especially so if the ANSI is very strict 
  493. X    because the library does make use of UNIX functionality like fork,
  494. X    wait, open, write, etc.
  495. X
  496. X    If you have access to an standard K&R compiler (or a more relaxed 
  497. X    ANSI compiler, especially one that uses the system K&R style header
  498. X    files (i.e. gcc without -pedantic on a system with a non-ANSI cc)
  499. X    you should use it to compile the library.  Once the library is
  500. X    compiled, you should be able to use it with code compiled under
  501. X    other compilers (assuming, of course, that they are compatible).
  502. X    
  503. X
  504. X1. Conflicts with system provided string.h/memory.h includes
  505. X
  506. X    The library provides its own versions of these functions, but includes
  507. X    the system header files so that if it compiles with no errors, you
  508. X    will know that the two agree exactly.  If they fail because there
  509. X    is a difference, either the SIZETYPE and/or DATATYPE definitions in
  510. X    malloc.h need to be changed, or you need to check to verify that 
  511. X    the malloclib versions are not incompatible with the system
  512. X    versions.  
  513. X
  514. X    If everything looks ok, you can remove the string.h/memory.h
  515. X    inclusions from the mallocint.h header file.
  516. X
  517. X2. Duplicate symbols from libc.a (or its equivalent shared library)
  518. X
  519. X    This is most often caused by one of the system library functions
  520. X    including an additional function/variable definition in one of the
  521. X    memory/string library modules. (i.e. some systems have a cfree()
  522. X    call that is in the calloc.o library module).
  523. X
  524. X    There are several ways to get around this problem.  The best way
  525. X    would be to duplicate the functionaly of the extra reference 
  526. X    whereever it is appropriate in the malloc library (similarly to
  527. X    the addition of cfree in the calloc.c module).   If you do this,
  528. X    please send me the new function and a description of the system and/or
  529. X    compiler so that I can determine if it should go into the standard
  530. X    distribution.
  531. X
  532. X    Another, less desirable way would be to disable the offending function
  533. X    in this library.  This option is less desirable because the disabled
  534. X    function would no longer provide any error checking (which is 
  535. X    supposed to be the purpose of this library).
  536. X
  537. X    With shared libraries, there are some formats (perhaps all) that
  538. X    have explicit references to functions in the shared library that
  539. X    are duplicated in the debug library.  On these systems, the
  540. X    only way around the problem is to not use the shared library 
  541. X    when linking the test version of the software.
  542. X
  543. X3. Compilation errors in string.c and/or memory.c
  544. X
  545. X    There are several compilers that provide in-line expansion of
  546. X    routines like strcpy.  This can cause real problems when we 
  547. X    try to compile our own version.  If you can disable the in-line
  548. X    expansion, that is the best way to go.  This should only be
  549. X    needed for the malloc library itself.  The source you are debugging
  550. X    should include the malloc.h file and therefore won't be calling
  551. X    strcpy, but instead will be calling DBstrcpy (because of a macro
  552. X    in malloc.h).
  553. X
  554. X    Disabling the in-lining of functions is usually accomplished by
  555. X    setting a compiler flag, or sometimes by predefining some #def
  556. X    that is used by system include files.
  557. X
  558. X    If you can't disable the in-line expansion, you will have to 
  559. X    disable the debug versions of the offending functions in the
  560. X    malloc library by adding a #ifdef around the code.  Be sure to
  561. X    just disable the functions that are giving you problems (i.e. don't
  562. X    disable all of string.c and don't disable the DB functions, because
  563. X    any code that includes malloc.h will attempt to use them).
  564. X
  565. X4. Conflicts/problems with prototypes.h
  566. X
  567. X    Prototypes.h is a generated file that has zillions of function
  568. X    prototypes for the malloc library.  You should not need to remake
  569. X    this module.  If, however, you have made changes to the calling
  570. X    arguements for some of the functions due to conflicts with system
  571. X    headers, you may have to modify or rebuild this file.
  572. X
  573. X    To rebuild the file using the makefile targets you must have the
  574. X    cproto prototype generator (available in comp.sources.misc, vols 17
  575. X    and 18).
  576. X
  577. X5. Argument mis-matches and syntax errors when including malloc.h
  578. X
  579. X    This is usually the result of including malloc.h before string.h
  580. X    and/or memory.h which causes lots of problems.  malloc.h attempts
  581. X    to avoid this problem by #defining a bunch of typical symbols used
  582. X    to preclude multiple inclusions of these files, but some systems do
  583. X    not have this multiple inclusion protection, or use a slightly 
  584. X    different symbol for the protection.
  585. X
  586. X    To get around this problem you could do one of the following:
  587. X
  588. X        1. change the code so that it includes malloc.h last.
  589. X        2. add multiple inclusion protection to the system include
  590. X           files.
  591. X        3. remove the #defines from malloc.h (which decreases the
  592. X           ability for the debug library to identify the source of
  593. X           the problems).
  594. X
  595. X    Another similar problem is the use of standard symbols for variable
  596. X    and/or structure element names.  This happens most often with the
  597. X    variable index. 
  598. X
  599. X    To fix this, you can change the name of the variable, #undef index
  600. X    after including the malloc library, or remove the #define index
  601. X    line from malloc.h
  602. X        
  603. END_OF_FILE
  604. if test 5936 -ne `wc -c <'PROBLEMS'`; then
  605.     echo shar: \"'PROBLEMS'\" unpacked with wrong size!
  606. fi
  607. # end of 'PROBLEMS'
  608. fi
  609. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  610.   echo shar: Will not clobber existing file \"'Makefile'\"
  611. else
  612. echo shar: Extracting \"'Makefile'\" \(6187 characters\)
  613. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  614. X#
  615. X# (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  616. X# You may copy, distribute, and use this software as long as this
  617. X# copyright statement is not removed.
  618. X#
  619. X# $Id: Makefile,v 1.20 1992/01/28 18:05:37 cpcahil Exp $
  620. X#
  621. X# This is the Makefile for the malloc debugging library
  622. X#
  623. X# NOTE: while most porting changes are made here, the malloc.h file
  624. X#       may require hand editing (mostly the DATATYPE and SIZETYPE
  625. X#    typedefs) because of system wierdities.
  626. X#
  627. X# Usefull targets:
  628. X#
  629. X#    all        make all programs/libs in the local directory
  630. X#    install        install updated programs/libs
  631. X#    frcinstall    install all programs/libs
  632. X#    tests        build tests
  633. X#    runtests    build and run all tests
  634. X#    clean        clean up after yourself
  635. X#
  636. X# NOTE: there are several other targets used by myself for souce code
  637. X# maintenance related functions.  These are probably specific to my system
  638. X# and may not do what they are supposed to do in a different environment.
  639. X# Therefore, unless you know what you are doing, I would suggest not running
  640. X# them (hence why they are not documented here).
  641. X#
  642. X# And now, onto a few definitions that you may need to alter
  643. X#
  644. X# The following defines may be added as necessary to the CFLAGS definition:
  645. X#
  646. X# -DNO_ANSI_NULLS     if you have and ANSI-C compiler, but still
  647. X#            wish to be warned about calls to free and/or
  648. X#            realloc that pass a NULL pointer.
  649. X# -DHAS_VADVISE     if your system supports this call.
  650. X# -DUSE_SETENV        if you system has setenv instead of putenv
  651. X#
  652. X#
  653. XCFLAGS=-g
  654. X#
  655. X# Where the code will be installed
  656. X#
  657. X#    DESTDIR        root for installation directory
  658. X#    INSTDIR     installation directory
  659. X#    LIBINSTDIR    install directory for library
  660. X#    INCINSTDIR    install directory for include files
  661. X#    MANINSTDIR    manual installation directory
  662. X#    MANINSTNAME    name to install the manual as
  663. X#    MANINSTVER    manual install version (use malloc.3 for troff/nroff
  664. X#            source and malloc.man for pre-formatted)
  665. X#
  666. XDESTDIR=
  667. XINSTDIR=$(DESTDIR)/usr/local
  668. XLIBINSTDIR=$(INSTDIR)/lib
  669. XINCINSTDIR=$(INSTDIR)/include
  670. XMANINSTDIR=$(INSTDIR)/man/man3
  671. XMANINSTNAME=dbmalloc.3
  672. XMANINSTVER=malloc.3
  673. X
  674. X#
  675. X# miscellaneous commands
  676. X#
  677. X# NOTE: if you change CC to a non-K&R compiler be sure to read the 
  678. X#       PROBLEMS file first.
  679. X#
  680. XCC=cc
  681. XCPROTO=/usr/local/bin/cproto
  682. XLINT=lint
  683. XNROFF=nroff
  684. XSHARCMD=makekit -p -m -nmallocshar.
  685. XSHELL=/bin/sh
  686. X
  687. XLIB=libdbmalloc.a
  688. X
  689. X#
  690. X# You shouldn't have to modify anything below this line
  691. X#
  692. XLIBSRCS=    malloc.c    \
  693. X        free.c        \
  694. X        realloc.c    \
  695. X        calloc.c    \
  696. X        string.c    \
  697. X        malloc_chk.c    \
  698. X        malloc_chn.c    \
  699. X        memory.c    \
  700. X        tostring.c    \
  701. X        m_perror.c    \
  702. X        m_init.c    \
  703. X        mallopt.c    \
  704. X        dump.c         \
  705. X        leak.c    
  706. X
  707. XLIBOBJS=    malloc.o    \
  708. X        free.o        \
  709. X        realloc.o    \
  710. X        calloc.o    \
  711. X        string.o    \
  712. X        malloc_chk.o    \
  713. X        malloc_chn.o    \
  714. X        memory.o    \
  715. X        tostring.o    \
  716. X        m_perror.o    \
  717. X        m_init.o    \
  718. X        mallopt.o    \
  719. X        dump.o         \
  720. X        leak.o    
  721. X
  722. XSRCS=$(LIBSRCS) testmalloc.c testmem.c testerr.c
  723. XHDRS= malloc.h mallocint.h debug.h tostring.h
  724. X
  725. XBUILDFILES=malloc.man prototypes.h 
  726. X
  727. XMANSRCFILES=patchlevel README PROBLEMS CHANGES Buildpatch Makefile \
  728. X    malloc.3 malloc.man $(SRCS) $(HDRS) prototypes.h
  729. XSRCFILES=MANIFEST $(MANSRCFILES)
  730. X
  731. XTESTS=testmalloc testmem testerr
  732. X
  733. Xall:    $(LIB)
  734. X
  735. Xinstall: $(LIBINSTDIR)/$(LIB) $(INCINSTDIR)/malloc.h \
  736. X    $(MANINSTDIR)/$(MANINSTNAME)
  737. X
  738. Xfrcinstall: rminstall install
  739. X
  740. Xrminstall:
  741. X    rm -f $(LIBINSTDIR)/$(LIB) $(INCINSTDIR)/malloc.h \
  742. X    $(MANINSTDIR)/$(MANINSTNAME)
  743. X
  744. X$(LIBINSTDIR)/$(LIB): $(LIB)
  745. X    -rm -f $@.old
  746. X    -mv -f $@ $@.old
  747. X    cp $? $@
  748. X    -chmod 644 $@
  749. X    -rm -f $@.old
  750. X
  751. X$(INCINSTDIR)/malloc.h: malloc.h
  752. X    -rm -f $@.old
  753. X    -mv -f $@ $@.old
  754. X    cp $? $@
  755. X    -chmod 644 $@
  756. X    -rm -f $@.old
  757. X    
  758. X$(MANINSTDIR)/$(MANINSTNAME): $(MANINSTVER)
  759. X    -rm -f $@.old
  760. X    -mv -f $@ $@.old
  761. X    cp $? $@
  762. X    -chmod 644 $@
  763. X    -rm -f $@.old
  764. X
  765. Xtests:    $(TESTS)
  766. X
  767. X#
  768. X# runtests - target for building and running the tests.  Note that we 
  769. X# run testmalloc with fill_area disabled.  This is because testmalloc is
  770. X# a malloc exerciser and we just want to see if we broke malloc, not verify
  771. X# that the test doesn't overwrite memory (since it doesn't).
  772. X#
  773. Xruntests: tests
  774. X    @echo "Running tests.  See the readme for info on what is expected" \
  775. X        "from each test"
  776. X    @echo "Running testmem.  This should have no output"
  777. X    testmem
  778. X    @echo "Running testmalloc, this will take a while."
  779. X    MALLOC_FILLAREA=0 testmalloc
  780. X    @echo "Running testerr.  This should abort"
  781. X    -testerr
  782. X
  783. Xclean:  
  784. X    rm -f $(TESTS) pgm $(LIB) *.o *.ln
  785. X
  786. Xsharfile: $(SRCFILES) CHECKSUMS
  787. X    $(SHARCMD)
  788. X
  789. XCHECKSUMS: $(SRCFILES)
  790. X    echo "SYSV sums:\n" > CHECKSUMS
  791. X    sum $(SRCFILES) >> CHECKSUMS
  792. X    echo "\nBSD sums (generated using sum -r on SYSV system):\n" >>CHECKSUMS
  793. X    sum -r $(SRCFILES) >> CHECKSUMS
  794. X
  795. XMANIFEST: $(MANSRCFILES)    
  796. X    $(SHARCMD) -x
  797. X    chmod -w MANIFEST
  798. X    
  799. X$(LIB): $(LIBOBJS)
  800. X    ar ru $(LIB) $(LIBOBJS)
  801. X    -if test -s /bin/ranlib; then /bin/ranlib $(LIB); else exit 0; fi
  802. X    -if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(LIB); else exit 0;fi
  803. X
  804. X#
  805. X# stuff for building the nroffed version of the manual page
  806. X#
  807. Xman:    malloc.man
  808. X
  809. Xmalloc.man: malloc.3
  810. X    rm -f malloc.man
  811. X    $(NROFF) -man malloc.3 | col -b > malloc.man
  812. X
  813. X#
  814. X# stuff for building the test programs
  815. X#
  816. Xtestmalloc:    $(LIB) testmalloc.o
  817. X    $(CC) $(CFLAGS) -o $@ testmalloc.o $(LIB)
  818. X
  819. Xtestmem:    $(LIB) testmem.o
  820. X    $(CC) $(CFLAGS) -o $@ testmem.o $(LIB)
  821. X
  822. Xtesterr:    $(LIB) testerr.o
  823. X    $(CC) $(CFLAGS) -o $@ testerr.o $(LIB)
  824. X
  825. X#
  826. X# misc stuff for source code maintenance
  827. X#
  828. Xlint:    
  829. X    $(LINT) $(CFLAGS) $(SRCS)
  830. X
  831. Xproto:
  832. X    rm -f prototypes.h
  833. X    make prototypes.h
  834. X
  835. Xprototypes.h: $(LIBSRCS) $(HDRS)
  836. X    @if [ ! -s $(CPROTO) ]; then \
  837. X        echo "Need cproto to rebuild prototypes file";\
  838. X        exit 1; \
  839. X    fi
  840. X    -rm -f prototypes.h
  841. X    cp /dev/null prototypes.h
  842. X    $(CPROTO) -D__STDC__ -m__stdcargs -f4 $(LIBSRCS) > prototypes.new
  843. X    mv prototypes.new prototypes.h
  844. X    chmod -w prototypes.h
  845. X    
  846. Xpatch: $(SRCFILES)
  847. X    sh Buildpatch $(SRCFILES)
  848. X
  849. Xrcsclean: $(BUILDFILES)
  850. X    -rcsclean -q $(SRCFILES)
  851. X    -ls $(SRCFILES) 2>/dev/null > files.list
  852. X    -rcs -i -t/dev/null `cat files.list` 2>/dev/null
  853. X    @set -e; \
  854. X    echo "files to be checked in: `cat files.list`"; \
  855. X    echo "\n\tMessage: \c"; \
  856. X    read message; \
  857. X    echo ""; \
  858. X    rcs -q -l `cat files.list`; \
  859. X    ci -m"$$message" `cat files.list`; \
  860. X    co -u $(SRCFILES)
  861. X
  862. X#
  863. X# include file dependencies
  864. X#
  865. X$(LIBOBJS):    malloc.h mallocint.h
  866. X
  867. Xtesterr.o testmalloc.o testmem.o:    malloc.h
  868. X
  869. Xtostring.o malloc.o dump.o:    tostring.h
  870. END_OF_FILE
  871. if test 6187 -ne `wc -c <'Makefile'`; then
  872.     echo shar: \"'Makefile'\" unpacked with wrong size!
  873. fi
  874. # end of 'Makefile'
  875. fi
  876. if test -f 'Buildpatch' -a "${1}" != "-c" ; then 
  877.   echo shar: Will not clobber existing file \"'Buildpatch'\"
  878. else
  879. echo shar: Extracting \"'Buildpatch'\" \(3293 characters\)
  880. sed "s/^X//" >'Buildpatch' <<'END_OF_FILE'
  881. X#
  882. X# Buildpatch - shell script for automatically building patch files
  883. X#
  884. X# $Id: Buildpatch,v 1.6 1992/01/28 18:05:37 cpcahil Exp $
  885. X#
  886. Xif [ $# = 0 ]; then
  887. X    echo "usage: Buildpatch srcfiles..."
  888. X    exit 1
  889. Xfi
  890. X
  891. X#
  892. X# see if any files are still locked.  If so, we cannot proceed (they must be
  893. X# unlocked before a patch file can be built
  894. X#
  895. Xif rlog $* 2>rlog.err |egrep "^locks:[     ]*[a-z][a-z]*:" >/dev/null; then
  896. X    echo "all files must be checked in before a patch file can be built"
  897. X    exit 1
  898. Xfi
  899. X
  900. Xif [ -s rlog.err ]; then
  901. X    echo "all files must be checked in before a patch file can be built"
  902. X    exit 1
  903. Xfi
  904. X
  905. Xrm -f rlog.err
  906. X
  907. X#
  908. X# determine the old and new patch levels and name the patchfile
  909. X#
  910. Xrm -f patchlevel    2> /dev/null
  911. Xco -q patchlevel     2> /dev/null
  912. X
  913. Xread title oldlevel < patchlevel
  914. Xlevel=`expr "$oldlevel" + 1`
  915. X
  916. Xif [ "$level" -lt 10 ]; then
  917. X    PATCH=patch.0$level
  918. Xelse
  919. X    PATCH=patch.$level
  920. Xfi
  921. X    
  922. X
  923. X#
  924. X# check out current version of all files
  925. X#
  926. Xco -q -u $*
  927. X
  928. X#
  929. X# create the new patchlevel file
  930. X#
  931. Xecho "Buillding patch number $level..."
  932. Xco -q -l patchlevel
  933. Xecho "$title $level" > patchlevel 
  934. Xci -u -q -m"patch number $level" -t/dev/null patchlevel
  935. X
  936. X#
  937. X# create a new, empty patch file and empty directory for old versions of files
  938. X#
  939. X> $PATCH
  940. X
  941. Xif [ -d old ]; then
  942. X    rm -rf old
  943. Xfi
  944. Xmkdir old
  945. X
  946. X#
  947. X# Unpack the old shar files into the old directory
  948. X#
  949. X(
  950. X    echo "Building old directory for diff base"
  951. X
  952. X    cd old
  953. X    if [ "$oldlevel" -lt 10 ]; then
  954. X        oldlevel=0$oldlevel
  955. X    fi
  956. X    unshar -h /dev/null ../oldshars/$oldlevel/* > /dev/null 2>&1
  957. X)
  958. X
  959. X#
  960. X# process each source file
  961. X#
  962. Xecho "Generating diffs"
  963. Xfor i in $*
  964. Xdo
  965. X    #
  966. X    # if the file exists (then it has been changed and must be part of
  967. X    # the patch file
  968. X    #
  969. X    if [ -s $i ]; then
  970. X
  971. X        #
  972. X        # if the file hasn't changed, skip it
  973. X        #
  974. X        if cmp -s $i old/$i ; then
  975. X            continue;
  976. X        fi
  977. X
  978. X        #
  979. X        # name the file
  980. X        #
  981. X        echo "\nIndex: $i" >> $PATCH
  982. X
  983. X        #
  984. X        # if there is an old version, add the prerequisite
  985. X        #
  986. X        if [ -s old/$i ]; then
  987. X            
  988. X            #
  989. X            # get old rcs id
  990. X            #
  991. X            PREREQ="`rlog -rpatchlevel_$oldlevel $i |
  992. X                 grep '^revision' | cut -f2 -d' ' 2>/dev/null`"
  993. X
  994. X            #
  995. X            # if the id is in the file, add the prereq line
  996. X            #
  997. X            if fgrep "$PREREQ" old/$i > /dev/null 2>&1; then
  998. X
  999. X                echo "Prereq: $PREREQ" >> $PATCH
  1000. X
  1001. X            elif [ "$i" = "patchlevel" ]; then
  1002. X
  1003. X                echo "Prereq: $oldlevel" >> $PATCH
  1004. X
  1005. X            fi
  1006. X        else
  1007. X            > old/$i
  1008. X        fi
  1009. X
  1010. X        # 
  1011. X        # diff the file to generate the patch stuff
  1012. X        #
  1013. X        diff -c old/$i $i >> $PATCH
  1014. X
  1015. X    fi
  1016. X
  1017. Xdone
  1018. X
  1019. X#
  1020. X# and now to check to verify that the patchfile correctly updates the
  1021. X# old code to the current version.  First apply the patch to the old
  1022. X# code and then see if there are any differences between the files.
  1023. X#
  1024. Xecho "Verifying patch..."
  1025. X(
  1026. X    cd old
  1027. X    patch < ../$PATCH > /dev/null 2>&1
  1028. X)
  1029. X
  1030. Xecho "ready: \c" 
  1031. Xread junk
  1032. XFILES="`
  1033. Xfor i in $*
  1034. Xdo
  1035. X    if cmp -s $i old/$i; then
  1036. X        continue;
  1037. X    fi
  1038. X
  1039. X    echo file $i did not patch correctly > /dev/tty
  1040. X    echo $i
  1041. Xdone `"
  1042. X
  1043. Xif [ ! -z "$FILES" ]; then
  1044. X
  1045. X    echo "patch file did not build correctly($FILES)."
  1046. X    exit 1
  1047. X
  1048. Xfi
  1049. X
  1050. Xrm -rf old
  1051. X
  1052. Xecho "Verification complete"
  1053. X
  1054. X#
  1055. X# and now freeze all the files at this patchlevel, and checkout the current
  1056. X# versions of the files
  1057. X#
  1058. X
  1059. Xecho "freezing source at patch level $level"
  1060. Xecho "." | rcsfreeze patchlevel_$level  > /dev/null 2>&1 
  1061. X
  1062. Xecho "checking out current version (unlocked)"
  1063. Xco -q -u -rpatchlevel_$level $*
  1064. X
  1065. Xexit 0
  1066. END_OF_FILE
  1067. if test 3293 -ne `wc -c <'Buildpatch'`; then
  1068.     echo shar: \"'Buildpatch'\" unpacked with wrong size!
  1069. fi
  1070. # end of 'Buildpatch'
  1071. fi
  1072. if test -f 'calloc.c' -a "${1}" != "-c" ; then 
  1073.   echo shar: Will not clobber existing file \"'calloc.c'\"
  1074. else
  1075. echo shar: Extracting \"'calloc.c'\" \(3469 characters\)
  1076. sed "s/^X//" >'calloc.c' <<'END_OF_FILE'
  1077. X/*
  1078. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  1079. X * You may copy, distribute, and use this software as long as this
  1080. X * copyright statement is not removed.
  1081. X */
  1082. X#include <stdio.h>
  1083. X
  1084. X#include "mallocint.h"
  1085. X
  1086. X#ifndef lint
  1087. Xstatic char rcs_header[] = "$Id: calloc.c,v 1.11 1992/01/10 17:28:03 cpcahil Exp $";
  1088. X#endif
  1089. X
  1090. X/*
  1091. X * Function:    calloc()
  1092. X *
  1093. X * Purpose:    to call debug_calloc to do the allocation
  1094. X *
  1095. X * Arguments:    nelem    - number of elements
  1096. X *        elsize    - size of each element
  1097. X *
  1098. X * Returns:    whatever debug_calloc returns
  1099. X *
  1100. X * Narrative:    call debug_calloc and return it's return
  1101. X */
  1102. XDATATYPE *
  1103. Xcalloc(nelem,elsize)
  1104. X    SIZETYPE       nelem;
  1105. X    SIZETYPE      elsize;
  1106. X{
  1107. X    return( debug_calloc((char *)NULL,(int)-1,nelem,elsize) );
  1108. X}
  1109. X
  1110. X/*
  1111. X * Function:    debug_calloc()
  1112. X *
  1113. X * Purpose:    to allocate and nullify a data area
  1114. X *
  1115. X * Arguments:    nelem    - number of elements
  1116. X *        elsize    - size of each element
  1117. X *
  1118. X * Returns:    NULL    - if malloc fails
  1119. X *        or pointer to allocated space
  1120. X *
  1121. X * Narrative:    determine size of area to malloc
  1122. X *        malloc area.
  1123. X *        if malloc succeeds
  1124. X *            fill area with nulls
  1125. X *        return ptr to malloc'd region
  1126. X */
  1127. X
  1128. XDATATYPE *
  1129. Xdebug_calloc(file,line,nelem,elsize)
  1130. X    const char    * file;
  1131. X    int          line;
  1132. X    SIZETYPE       nelem;
  1133. X    SIZETYPE       elsize;
  1134. X{
  1135. X    static IDTYPE      call_counter;
  1136. X    struct mlist    * mptr;
  1137. X    DATATYPE    * ptr;
  1138. X    SIZETYPE      size;
  1139. X
  1140. X    MALLOC_INIT();
  1141. X
  1142. X    /*
  1143. X     * increment the call counter
  1144. X     */
  1145. X    call_counter++;
  1146. X
  1147. X    /*
  1148. X     * calculate the size to allocate
  1149. X     */
  1150. X    size = elsize * nelem;
  1151. X
  1152. X    if( (ptr = debug_malloc(file,line,size)) != NULL)
  1153. X    {
  1154. X        /*
  1155. X         * change the id information put in by malloc so that the 
  1156. X         * record appears like it got added by calloc
  1157. X         */
  1158. X        mptr = (struct mlist *) (((char *)ptr) - M_SIZE);
  1159. X        mptr->id = call_counter;
  1160. X        SETTYPE(mptr,M_T_CALLOC);
  1161. X
  1162. X        /*
  1163. X         * clear the area that was allocated
  1164. X         */
  1165. X        VOIDCAST memset(ptr,'\0',size);
  1166. X    }
  1167. X
  1168. X    return(ptr);
  1169. X
  1170. X} /* debug_calloc(... */
  1171. X
  1172. X/*
  1173. X * Function:    cfree()
  1174. X *
  1175. X * Purpose:    to free an area allocated by calloc (actually frees any
  1176. X *        allocated area)
  1177. X *
  1178. X * Arguments:    cptr    - pointer to area to be freed
  1179. X *
  1180. X * Returns:    nothing of any use
  1181. X *
  1182. X * Narrative:    just call the appropriate function to perform the free
  1183. X *
  1184. X * Note:    most systems do not have such a call, but for the few that do,
  1185. X *        it is here.
  1186. X */
  1187. XVOIDTYPE
  1188. Xcfree( cptr )
  1189. X    DATATYPE    * cptr;
  1190. X{
  1191. X    debug_cfree((const char *)NULL,(int)-1, cptr);
  1192. X}
  1193. X
  1194. XVOIDTYPE
  1195. Xdebug_cfree(file,line,cptr)
  1196. X    const char    * file;
  1197. X    int          line;
  1198. X    DATATYPE    * cptr;
  1199. X{
  1200. X    DBFfree("cfree",file,line,cptr);
  1201. X}
  1202. X
  1203. X/*
  1204. X * $Log: calloc.c,v $
  1205. X * Revision 1.11  1992/01/10  17:28:03  cpcahil
  1206. X * Added support for overriding void datatype
  1207. X *
  1208. X * Revision 1.10  1991/12/06  17:58:42  cpcahil
  1209. X * added cfree() for compatibility with some wierd systems
  1210. X *
  1211. X * Revision 1.9  91/12/02  19:10:08  cpcahil
  1212. X * changes for patch release 5
  1213. X * 
  1214. X * Revision 1.8  91/11/25  14:41:51  cpcahil
  1215. X * Final changes in preparation for patch 4 release
  1216. X * 
  1217. X * Revision 1.7  91/11/24  00:49:21  cpcahil
  1218. X * first cut at patch 4
  1219. X * 
  1220. X * Revision 1.6  90/05/11  00:13:07  cpcahil
  1221. X * added copyright statment
  1222. X * 
  1223. X * Revision 1.5  90/02/24  20:41:57  cpcahil
  1224. X * lint changes.
  1225. X * 
  1226. X * Revision 1.4  90/02/24  17:25:47  cpcahil
  1227. X * changed $header to $id so full path isn't included.
  1228. X * 
  1229. X * Revision 1.3  90/02/24  13:32:24  cpcahil
  1230. X * added function header.  moved log to end of file.
  1231. X * 
  1232. X * Revision 1.2  90/02/22  23:08:26  cpcahil
  1233. X * fixed rcs_header line
  1234. X * 
  1235. X * Revision 1.1  90/02/22  23:07:38  cpcahil
  1236. X * Initial revision
  1237. X * 
  1238. X */
  1239. END_OF_FILE
  1240. if test 3469 -ne `wc -c <'calloc.c'`; then
  1241.     echo shar: \"'calloc.c'\" unpacked with wrong size!
  1242. fi
  1243. # end of 'calloc.c'
  1244. fi
  1245. if test -f 'debug.h' -a "${1}" != "-c" ; then 
  1246.   echo shar: Will not clobber existing file \"'debug.h'\"
  1247. else
  1248. echo shar: Extracting \"'debug.h'\" \(2738 characters\)
  1249. sed "s/^X//" >'debug.h' <<'END_OF_FILE'
  1250. X/*
  1251. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  1252. X * You may copy, distribute, and use this software as long as this
  1253. X * copyright statement is not removed.
  1254. X */
  1255. X/************************************************************************/
  1256. X/*                                    */
  1257. X/* this include sets up some macro functions which can be used while    */
  1258. X/* debugging the program, and then left in the code, but turned of by    */
  1259. X/* just not defining "DEBUG".  This way your production version of     */
  1260. X/* the program will not be filled with bunches of debugging junk    */
  1261. X/*                                    */
  1262. X/************************************************************************/
  1263. X/*
  1264. X * $Id: debug.h,v 1.3 1991/11/25 14:41:51 cpcahil Exp $
  1265. X */
  1266. X
  1267. X#ifdef DEBUG
  1268. X
  1269. X#if DEBUG == 1            /* if default level            */
  1270. X#undef DEBUG
  1271. X#define DEBUG    100        /*   use level 100            */
  1272. X#endif
  1273. X
  1274. X#include <stdio.h>
  1275. X
  1276. X#define DEBUG0(val,str)\
  1277. X                {\
  1278. X                  if( DEBUG > val ) \
  1279. X                    fprintf(stderr,"%s(%d): %s\n",\
  1280. X                        __FILE__,__LINE__,str);\
  1281. X                }
  1282. X#define DEBUG1(val,str,a1)\
  1283. X                    {\
  1284. X                  char _debugbuf[100];\
  1285. X                  if( DEBUG > val )\
  1286. X                   {\
  1287. X                    sprintf(_debugbuf,str,a1);\
  1288. X                    fprintf(stderr,"%s(%d): %s\n",\
  1289. X                        __FILE__,__LINE__,_debugbuf);\
  1290. X                   }\
  1291. X                       }
  1292. X
  1293. X#define DEBUG2(val,str,a1,a2)\
  1294. X                    {\
  1295. X                 char _debugbuf[100];\
  1296. X                  if( DEBUG > val )\
  1297. X                   {\
  1298. X                    sprintf(_debugbuf,str,a1,a2);\
  1299. X                    fprintf(stderr,"%s(%d): %s\n",\
  1300. X                        __FILE__,__LINE__,_debugbuf);\
  1301. X                   }\
  1302. X                       }
  1303. X
  1304. X#define DEBUG3(val,str,a1,a2,a3)\
  1305. X                    {\
  1306. X                  char _debugbuf[100];\
  1307. X                  if( DEBUG > val )\
  1308. X                   {\
  1309. X                    sprintf(_debugbuf,str,a1,a2,a3);\
  1310. X                    fprintf(stderr,"%s(%d): %s\n",\
  1311. X                        __FILE__,__LINE__,_debugbuf);\
  1312. X                   }\
  1313. X                       }
  1314. X
  1315. X#define DEBUG4(val,str,a1,a2,a3,a4)\
  1316. X                     {\
  1317. X                  char _debugbuf[100];\
  1318. X                  if( DEBUG > val )\
  1319. X                   {\
  1320. X                    sprintf(_debugbuf,str,a1,a2,a3,a4);\
  1321. X                    fprintf(stderr,"%s(%d): %s\n",\
  1322. X                        __FILE__,__LINE__,_debugbuf);\
  1323. X                   }\
  1324. X                       }
  1325. X
  1326. X#define DEBUG5(val,str,a1,a2,a3,a4,a5)\
  1327. X                     {\
  1328. X                  char _debugbuf[100];\
  1329. X                  if( DEBUG > val )\
  1330. X                   {\
  1331. X                    sprintf(_debugbuf,str,a1,a2,a3,a4,a5);\
  1332. X                    fprintf(stderr,"%s(%d): %s\n",\
  1333. X                        __FILE__,__LINE__,_debugbuf);\
  1334. X                   }\
  1335. X                       }
  1336. X
  1337. X#else
  1338. X
  1339. X#define DEBUG0(val,s)
  1340. X#define DEBUG1(val,s,a1)
  1341. X#define DEBUG2(val,s,a1,a2)
  1342. X#define DEBUG3(val,s,a1,a2,a3)
  1343. X#define DEBUG4(val,s,a1,a2,a3,a4)
  1344. X#define DEBUG5(val,s,a1,a2,a3,a4,a5)
  1345. X
  1346. X#endif /* DEBUG */
  1347. X
  1348. X
  1349. X/*
  1350. X * $Log: debug.h,v $
  1351. X * Revision 1.3  1991/11/25  14:41:51  cpcahil
  1352. X * Final changes in preparation for patch 4 release
  1353. X *
  1354. X * Revision 1.2  90/05/11  00:13:08  cpcahil
  1355. X * added copyright statment
  1356. X * 
  1357. X * Revision 1.1  90/02/23  07:09:01  cpcahil
  1358. X * Initial revision
  1359. X * 
  1360. X */
  1361. END_OF_FILE
  1362. if test 2738 -ne `wc -c <'debug.h'`; then
  1363.     echo shar: \"'debug.h'\" unpacked with wrong size!
  1364. fi
  1365. # end of 'debug.h'
  1366. fi
  1367. if test -f 'dump.c' -a "${1}" != "-c" ; then 
  1368.   echo shar: Will not clobber existing file \"'dump.c'\"
  1369. else
  1370. echo shar: Extracting \"'dump.c'\" \(9467 characters\)
  1371. sed "s/^X//" >'dump.c' <<'END_OF_FILE'
  1372. X/*
  1373. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  1374. X * You may copy, distribute, and use this software as long as this
  1375. X * copyright statement is not removed.
  1376. X */
  1377. X#include <stdio.h>
  1378. X#include "mallocint.h"
  1379. X#include "tostring.h"
  1380. X
  1381. X#ifndef lint
  1382. Xstatic
  1383. Xchar rcs_hdr[] = "$Id: dump.c,v 1.9 1992/01/10 17:28:03 cpcahil Exp $";
  1384. X#endif
  1385. X
  1386. X/*
  1387. X * various macro definitions used within this module.
  1388. X */
  1389. X
  1390. X#define WRITEOUT(fd,str,len)    if( write(fd,str,(unsigned)(len)) != (len) ) \
  1391. X                { \
  1392. X                    VOIDCAST write(2,ERRSTR,\
  1393. X                             (unsigned)strlen(ERRSTR));\
  1394. X                    exit(120); \
  1395. X                }
  1396. X
  1397. X#define DETAIL_NONE         0
  1398. X#define DETAIL_NOT_SET_YET    -1
  1399. X#define DETAIL_ST_COL        (sizeof(DETAIL_HDR_3)-1)
  1400. X#define ERRSTR    "I/O Error on malloc dump file descriptor\n"
  1401. X#define FILE_LEN        20
  1402. X#define LIST_ALL        1
  1403. X#define LIST_SOME        2
  1404. X#define NUM_BYTES        7
  1405. X#define TITLE            " Dump of Malloc Chain "
  1406. X
  1407. X#define DETAIL_HDR_1 \
  1408. X     "                             FREE     FREE                  ACTUAL SIZE    "
  1409. X#define DETAIL_HDR_2 \
  1410. X     "  PTR      NEXT     PREV     NEXT     PREV      FLAGS       INT    HEX     "
  1411. X#define DETAIL_HDR_3 \
  1412. X     "-------- -------- -------- -------- -------- ---------- -------- --------- "
  1413. X
  1414. X#define NORMAL_HDR_1 \
  1415. X "POINTER     FILE  WHERE         LINE      ALLOC        DATA     HEX DUMP   \n"
  1416. X#define NORMAL_HDR_2 \
  1417. X "TO DATA      ALLOCATED         NUMBER     FUNCT       LENGTH  OF BYTES 1-7 \n"
  1418. X#define NORMAL_HDR_3 \
  1419. X "-------- -------------------- ------- -------------- ------- --------------\n"
  1420. X
  1421. X#define THISBUFSIZE (sizeof(NORMAL_HDR_3)+sizeof(DETAIL_HDR_3))
  1422. X
  1423. X
  1424. X/*
  1425. X * Function:    malloc_dump()
  1426. X *
  1427. X * Purpose:    to dump a printed copy of the malloc chain and
  1428. X *        associated data elements
  1429. X *
  1430. X * Arguments:    fd    - file descriptor to write data to
  1431. X *
  1432. X * Returns:    nothing of any use
  1433. X *
  1434. X * Narrative:    Just print out all the junk
  1435. X *
  1436. X */
  1437. XVOIDTYPE
  1438. Xmalloc_dump(fd)
  1439. X    int        fd;
  1440. X{
  1441. X    malloc_list_items(fd,LIST_ALL,0L,0L);
  1442. X}
  1443. X
  1444. X/*
  1445. X * Function:    malloc_list()
  1446. X *
  1447. X * Purpose:    to dump a printed copy of the malloc chain and
  1448. X *        associated data elements
  1449. X *
  1450. X * Arguments:    fd    - file descriptor to write data to
  1451. X *        histid1 - id of the first record to display
  1452. X *        histid2 - id one above the last record to display
  1453. X *
  1454. X * Returns:    nothing of any use
  1455. X *
  1456. X * Narrative:    Just call malloc_list_items to display the junk
  1457. X *
  1458. X */
  1459. XVOIDTYPE
  1460. Xmalloc_list(fd,histid1,histid2)
  1461. X    int        fd;
  1462. X    IDTYPE        histid1;
  1463. X    IDTYPE        histid2;
  1464. X{
  1465. X    malloc_list_items(fd, LIST_SOME, histid1, histid2);
  1466. X}
  1467. X
  1468. X/*
  1469. X * Function:    malloc_list_items()
  1470. X *
  1471. X * Purpose:    to dump a printed copy of the malloc chain and
  1472. X *        associated data elements
  1473. X *
  1474. X * Arguments:    fd      - file descriptor to write data to
  1475. X *        list_type - type of list (all records, or a selected list)
  1476. X *        histid1      - first id to list (if type is some)
  1477. X *        histid2   - one above last id to list
  1478. X *
  1479. X * Returns:    nothing of any use
  1480. X *
  1481. X * Narrative:    Just print out all the junk
  1482. X *
  1483. X * Notes:    This function is implemented using low level calls because
  1484. X *         of the likelyhood that the malloc tree is damaged when it
  1485. X *        is called.  (Lots of things in the c library use malloc and
  1486. X *        we don't want to get into a catch-22).
  1487. X *
  1488. X */
  1489. XVOIDTYPE
  1490. Xmalloc_list_items(fd,list_type,histid1,histid2)
  1491. X    int              fd;
  1492. X    int              list_type;
  1493. X    IDTYPE              histid1;
  1494. X    IDTYPE              histid2;
  1495. X{
  1496. X    char              buffer[THISBUFSIZE];
  1497. X    static int          detail = DETAIL_NOT_SET_YET;
  1498. X    VOIDTYPE              exit();
  1499. X    char            * func;
  1500. X    int              i;
  1501. X    int              loc;
  1502. X    struct mlist         * ptr;
  1503. X
  1504. X    MALLOC_INIT();
  1505. X
  1506. X    /*
  1507. X     * See if they want full detail (includes internal pointer info)
  1508. X     */
  1509. X    if( detail == DETAIL_NOT_SET_YET)
  1510. X    {
  1511. X        if( getenv("MALLOC_DETAIL") != NULL )
  1512. X        {
  1513. X            detail = DETAIL_ST_COL;
  1514. X        }
  1515. X        else
  1516. X        {
  1517. X            detail = DETAIL_NONE;
  1518. X        }
  1519. X    }
  1520. X
  1521. X    /*
  1522. X     * fill the title line with asterisks
  1523. X     */
  1524. X    for(i=0; i < (detail + sizeof(NORMAL_HDR_3)-1); i++)
  1525. X    {
  1526. X        buffer[i] = '*';
  1527. X    }
  1528. X    buffer[i] = '\n';
  1529. X    buffer[i+1] = EOS;
  1530. X
  1531. X    /*
  1532. X     * add in the title  (centered, of course)
  1533. X     */
  1534. X    loc = (i - sizeof(TITLE)) / 2;
  1535. X    for(i=0; i < (sizeof(TITLE)-1); i++)
  1536. X    {
  1537. X        buffer[loc+i] = TITLE[i];
  1538. X    }
  1539. X
  1540. X    /*
  1541. X     * and write it out
  1542. X     */
  1543. X    WRITEOUT(fd,buffer,strlen(buffer));
  1544. X
  1545. X    /*
  1546. X     * write out the column headers
  1547. X     */
  1548. X    if( detail != DETAIL_NONE )
  1549. X    {
  1550. X        WRITEOUT(fd,DETAIL_HDR_1,sizeof(DETAIL_HDR_1)-1);
  1551. X        WRITEOUT(fd,NORMAL_HDR_1,sizeof(NORMAL_HDR_1)-1);
  1552. X        WRITEOUT(fd,DETAIL_HDR_2,sizeof(DETAIL_HDR_2)-1);
  1553. X        WRITEOUT(fd,NORMAL_HDR_2,sizeof(NORMAL_HDR_2)-1);
  1554. X        WRITEOUT(fd,DETAIL_HDR_3,sizeof(DETAIL_HDR_3)-1);
  1555. X        WRITEOUT(fd,NORMAL_HDR_3,sizeof(NORMAL_HDR_3)-1);
  1556. X    }
  1557. X    else
  1558. X    {
  1559. X        WRITEOUT(fd,NORMAL_HDR_1,sizeof(NORMAL_HDR_1)-1);
  1560. X        WRITEOUT(fd,NORMAL_HDR_2,sizeof(NORMAL_HDR_2)-1);
  1561. X        WRITEOUT(fd,NORMAL_HDR_3,sizeof(NORMAL_HDR_3)-1);
  1562. X    }
  1563. X
  1564. X    /*
  1565. X     * for each element in the trace
  1566. X     */
  1567. X    for(ptr = &malloc_start; ptr; ptr = ptr->next)
  1568. X    {
  1569. X        /*
  1570. X         * if this item is not in use and we are not in detail mode or
  1571. X         * we are not in list-all mode.
  1572. X         */
  1573. X        if(    ((ptr->flag & M_INUSE) == 0)
  1574. X            && ((detail == DETAIL_NONE) || (list_type != LIST_ALL)) )
  1575. X        {
  1576. X            continue;
  1577. X        }
  1578. X        /*
  1579. X         * else if we are only listing a range of items, check to see
  1580. X         * if this item is in the correct range.  if not, skip it
  1581. X          */
  1582. X        else if(   (list_type == LIST_SOME)
  1583. X            && (    (ptr->hist_id < histid1)
  1584. X                 || (ptr->hist_id >= histid2)) )
  1585. X        {
  1586. X            continue;
  1587. X        }
  1588. X
  1589. X        /*
  1590. X         * fill in the string with blanks
  1591. X         */
  1592. X        for(i=0; i < (sizeof(DETAIL_HDR_3)+sizeof(NORMAL_HDR_3)); i++)
  1593. X        {
  1594. X            buffer[i] = ' ';
  1595. X        }
  1596. X
  1597. X        /*
  1598. X          * handle detail output
  1599. X         */
  1600. X        if( detail != DETAIL_NONE )
  1601. X        {
  1602. X            VOIDCAST tostring(buffer,
  1603. X                    (long)ptr,8,B_HEX,'0');
  1604. X            VOIDCAST tostring(buffer+9,
  1605. X                    (long)ptr->next,8,B_HEX,'0');
  1606. X            VOIDCAST tostring(buffer+18,
  1607. X                    (long)ptr->prev,8,B_HEX,'0');
  1608. X            VOIDCAST tostring(buffer+27,
  1609. X                    (long)ptr->freenext,8,B_HEX,'0');
  1610. X            VOIDCAST tostring(buffer+36,
  1611. X                    (long)ptr->freeprev,8,B_HEX,'0');
  1612. X            VOIDCAST tostring(buffer+45,
  1613. X                    (long)ptr->flag,10,B_HEX,'0');
  1614. X            VOIDCAST tostring(buffer+56,
  1615. X                    (long)ptr->s.size,8,B_DEC,' ');
  1616. X            VOIDCAST tostring(buffer+65,
  1617. X                    (long)ptr->s.size,8,B_HEX,'0');
  1618. X            buffer[64] = '(';
  1619. X            buffer[74] = ')';
  1620. X        }
  1621. X
  1622. X        /*
  1623. X         * and now add in the normal stuff
  1624. X         */
  1625. X         VOIDCAST tostring(buffer+detail,
  1626. X                (long) ptr->data, 8, B_HEX, '0');
  1627. X
  1628. X        /*
  1629. X         * if a file has been specified
  1630. X         */
  1631. X        if( (ptr->file != NULL)     && (ptr->file[0] != EOS) )
  1632. X        {
  1633. X
  1634. X            for(i=0; (i < FILE_LEN) && (ptr->file[i] != EOS); i++)
  1635. X            {
  1636. X                buffer[detail+9+i] = ptr->file[i];
  1637. X            }
  1638. X
  1639. X            VOIDCAST tostring(buffer+detail+30,
  1640. X                        (long)ptr->line,7,B_DEC, ' ');
  1641. X        }
  1642. X        else
  1643. X        {
  1644. X            for(i=0; i < (sizeof("unknown")-1); i++)
  1645. X            {
  1646. X                buffer[detail+9+i] = "unknown"[i];
  1647. X            }
  1648. X        }
  1649. X            
  1650. X        /*
  1651. X         * determine name of function to use 
  1652. X         */
  1653. X        switch( GETTYPE(ptr) )
  1654. X        {
  1655. X            case M_T_MALLOC:
  1656. X                func = "malloc";
  1657. X                break;
  1658. X    
  1659. X            case M_T_REALLOC:
  1660. X                func = "realloc";
  1661. X                break;
  1662. X    
  1663. X            case M_T_CALLOC:
  1664. X                func = "calloc";
  1665. X                break;
  1666. X
  1667. X            default:
  1668. X                func = "unknown";
  1669. X                break;
  1670. X        }
  1671. X
  1672. X        /*
  1673. X         * copy the function name into the string.
  1674. X         */
  1675. X        for( i=0; func[i] != EOS; i++)
  1676. X        {
  1677. X            buffer[detail+38+i] = func[i];
  1678. X        }
  1679. X
  1680. X        /*
  1681. X         * add the call number
  1682. X         */
  1683. X        buffer[detail+38+ i++] = '(';
  1684. X        i += tostring(buffer+detail+38+i,(long)ptr->id,0,B_DEC,' ');
  1685. X        buffer[detail+38+i] = ')';
  1686. X    
  1687. X        /*
  1688. X         * display the length of the segment
  1689. X         */
  1690. X        VOIDCAST tostring(buffer+detail+53,
  1691. X                (long)ptr->r_size,7,B_DEC,' ');
  1692. X
  1693. X        /* 
  1694. X         * display the first seven bytes of data
  1695. X         */
  1696. X        for( i=0; (i < NUM_BYTES) && (i < ptr->r_size); i++)
  1697. X        {
  1698. X            VOIDCAST tostring(buffer+detail + 61 + (i * 2),
  1699. X                    (long)ptr->data[i], 2, B_HEX, '0');
  1700. X        }
  1701. X
  1702. X        buffer[detail + sizeof(NORMAL_HDR_3)] = '\n';
  1703. X        WRITEOUT(fd,buffer,detail+sizeof(NORMAL_HDR_3)+1);
  1704. X    }
  1705. X
  1706. X    if( detail != DETAIL_NONE )
  1707. X    {
  1708. X        WRITEOUT(fd,"Malloc start:      ",19);
  1709. X        VOIDCAST tostring(buffer, (long) &malloc_start, 8, B_HEX, '0');
  1710. X        buffer[8] = '\n';
  1711. X        WRITEOUT(fd,buffer,9);
  1712. X
  1713. X        WRITEOUT(fd,"Malloc end:        ", 19);
  1714. X        VOIDCAST tostring(buffer, (long) malloc_end, 8, B_HEX, '0');
  1715. X        buffer[8] = '\n';
  1716. X        WRITEOUT(fd,buffer,9);
  1717. X
  1718. X        WRITEOUT(fd,"Malloc data start: ", 19);
  1719. X        VOIDCAST tostring(buffer,(long) malloc_data_start,8,B_HEX,'0');
  1720. X        buffer[8] = '\n';
  1721. X        WRITEOUT(fd,buffer,9);
  1722. X
  1723. X        WRITEOUT(fd,"Malloc data end:   ", 19);
  1724. X        VOIDCAST tostring(buffer,(long) malloc_data_end, 8, B_HEX, '0');
  1725. X        buffer[8] = '\n';
  1726. X        WRITEOUT(fd,buffer,9);
  1727. X
  1728. X        WRITEOUT(fd,"Malloc free list:  ", 19);
  1729. X        VOIDCAST tostring(buffer, (long) malloc_freelist, 8,B_HEX,'0');
  1730. X        buffer[8] = '\n';
  1731. X        WRITEOUT(fd,buffer,9);
  1732. X
  1733. X        for( ptr=malloc_freelist->freenext; ptr != NULL; ptr = ptr->freenext)
  1734. X        {
  1735. X            WRITEOUT(fd,"                -> ", 19);
  1736. X            VOIDCAST tostring(buffer, (long) ptr, 8, B_HEX, '0');
  1737. X            buffer[8] = '\n';
  1738. X            WRITEOUT(fd,buffer,9);
  1739. X        }
  1740. X
  1741. X    }
  1742. X
  1743. X    WRITEOUT(fd,"\n",1);
  1744. X    
  1745. X} /* malloc_dump(... */
  1746. X
  1747. X
  1748. X/*
  1749. X * $Log: dump.c,v $
  1750. X * Revision 1.9  1992/01/10  17:28:03  cpcahil
  1751. X * Added support for overriding void datatype
  1752. X *
  1753. X * Revision 1.8  1991/12/04  09:23:36  cpcahil
  1754. X * several performance enhancements including addition of free list
  1755. X *
  1756. X * Revision 1.7  91/11/25  14:41:52  cpcahil
  1757. X * Final changes in preparation for patch 4 release
  1758. X * 
  1759. X * Revision 1.6  91/11/24  00:49:25  cpcahil
  1760. X * first cut at patch 4
  1761. X * 
  1762. X * Revision 1.5  90/08/29  21:22:37  cpcahil
  1763. X * miscellaneous lint fixes
  1764. X * 
  1765. X * Revision 1.4  90/05/11  00:13:08  cpcahil
  1766. X * added copyright statment
  1767. X * 
  1768. X * Revision 1.3  90/02/24  21:50:07  cpcahil
  1769. X * lots of lint fixes
  1770. X * 
  1771. X * Revision 1.2  90/02/24  17:27:48  cpcahil
  1772. X * changed $header to $Id to remove full path from rcs id string
  1773. X * 
  1774. X * Revision 1.1  90/02/22  23:17:43  cpcahil
  1775. X * Initial revision
  1776. X * 
  1777. X */
  1778. END_OF_FILE
  1779. if test 9467 -ne `wc -c <'dump.c'`; then
  1780.     echo shar: \"'dump.c'\" unpacked with wrong size!
  1781. fi
  1782. # end of 'dump.c'
  1783. fi
  1784. if test -f 'leak.c' -a "${1}" != "-c" ; then 
  1785.   echo shar: Will not clobber existing file \"'leak.c'\"
  1786. else
  1787. echo shar: Extracting \"'leak.c'\" \(3013 characters\)
  1788. sed "s/^X//" >'leak.c' <<'END_OF_FILE'
  1789. X
  1790. X/*
  1791. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  1792. X * You may copy, distribute, and use this software as long as this
  1793. X * copyright statement is not removed.
  1794. X */
  1795. X
  1796. X#ifndef lint
  1797. Xstatic
  1798. Xchar rcs_hdr[] = "$Id: leak.c,v 1.4 1992/01/10 17:28:03 cpcahil Exp $";
  1799. X#endif
  1800. X
  1801. X#include <stdio.h>
  1802. X
  1803. X#include "mallocint.h"
  1804. X
  1805. X/*
  1806. X * Function:    malloc_size()
  1807. X *
  1808. X * Purpose:    to determine the amount of memory in use
  1809. X *
  1810. X * Arguments:    histidptr - pointer to hist id area
  1811. X *
  1812. X * Returns:    Number of bytes currently in use
  1813. X *
  1814. X * Narrative:    make sure the malloc chain is ok
  1815. X *        for each element in the malloc chain
  1816. X *            if it is in use
  1817. X *                add size to total size
  1818. X *         if hist id is wanted
  1819. X *                  set it
  1820. X *        return total in-use size
  1821. X *        
  1822. X */
  1823. X
  1824. Xunsigned long
  1825. Xmalloc_size(histptr)
  1826. X    unsigned long        * histptr;
  1827. X{
  1828. X    return( DBmalloc_size((char *)NULL,0,histptr) );
  1829. X}
  1830. X
  1831. Xunsigned long
  1832. XDBmalloc_size(file,line,histptr)
  1833. X    const char        * file;
  1834. X    int               line;
  1835. X    unsigned long        * histptr;
  1836. X{
  1837. X    unsigned long          size = 0;
  1838. X    struct mlist        * ptr;
  1839. X
  1840. X    MALLOC_INIT();
  1841. X
  1842. X    /*
  1843. X     * make sure the chain is ok (otherwise we will have a problem
  1844. X     * parsing through it
  1845. X     */
  1846. X    VOIDCAST DBFmalloc_chain_check("malloc_size",file,line,1);
  1847. X
  1848. X    /*
  1849. X     * for each element in the malloc chain
  1850. X     */
  1851. X    for(ptr = &malloc_start; ptr; ptr = ptr->next)
  1852. X    {
  1853. X        /*
  1854. X         * if the element is in use
  1855. X         */
  1856. X        if( (ptr->flag&M_INUSE) == M_INUSE)
  1857. X        {
  1858. X            /* 
  1859. X             * add its requested size into the total size
  1860. X             */
  1861. X            size += ptr->r_size;
  1862. X        }
  1863. X    }
  1864. X
  1865. X    /*
  1866. X     * if the hist id is desired, give it to em.
  1867. X     */
  1868. X    if( histptr != NULL )
  1869. X    {
  1870. X        *histptr = malloc_hist_id;
  1871. X    }
  1872. X
  1873. X    /*
  1874. X     * return the size
  1875. X     */
  1876. X    return(size);
  1877. X
  1878. X} /* malloc_size(... */
  1879. X
  1880. X
  1881. X/*
  1882. X * $Log: leak.c,v $
  1883. X * Revision 1.4  1992/01/10  17:28:03  cpcahil
  1884. X * Added support for overriding void datatype
  1885. X *
  1886. X * Revision 1.3  1991/12/02  19:10:09  cpcahil
  1887. X * changes for patch release 5
  1888. X *
  1889. X * Revision 1.2  91/11/25  14:41:54  cpcahil
  1890. X * Final changes in preparation for patch 4 release
  1891. X * 
  1892. X * Revision 1.1  91/11/24  00:49:26  cpcahil
  1893. X * first cut at patch 4
  1894. X * 
  1895. X * Revision 1.9  91/11/20  11:54:11  cpcahil
  1896. X * interim checkin
  1897. X * 
  1898. X * Revision 1.8  90/08/29  21:22:52  cpcahil
  1899. X * miscellaneous lint fixes
  1900. X * 
  1901. X * Revision 1.7  90/05/11  00:13:10  cpcahil
  1902. X * added copyright statment
  1903. X * 
  1904. X * Revision 1.6  90/02/25  11:01:20  cpcahil
  1905. X * added support for malloc chain checking.
  1906. X * 
  1907. X * Revision 1.5  90/02/24  21:50:31  cpcahil
  1908. X * lots of lint fixes
  1909. X * 
  1910. X * Revision 1.4  90/02/24  17:29:39  cpcahil
  1911. X * changed $Header to $Id so full path wouldnt be included as part of rcs 
  1912. X * id string
  1913. X * 
  1914. X * Revision 1.3  90/02/24  17:20:00  cpcahil
  1915. X * attempt to get rid of full path in rcs header.
  1916. X * 
  1917. X * Revision 1.2  90/02/24  15:14:20  cpcahil
  1918. X * 1. added function header 
  1919. X * 2. changed calls to malloc_warning to conform to new usage
  1920. X * 3. added setting of malloc_errno
  1921. X *  4. broke up bad pointer determination so that errno's would be more
  1922. X *    descriptive
  1923. X * 
  1924. X * Revision 1.1  90/02/22  23:17:43  cpcahil
  1925. X * Initial revision
  1926. X * 
  1927. X */
  1928. END_OF_FILE
  1929. if test 3013 -ne `wc -c <'leak.c'`; then
  1930.     echo shar: \"'leak.c'\" unpacked with wrong size!
  1931. fi
  1932. # end of 'leak.c'
  1933. fi
  1934. if test -f 'patchlevel' -a "${1}" != "-c" ; then 
  1935.   echo shar: Will not clobber existing file \"'patchlevel'\"
  1936. else
  1937. echo shar: Extracting \"'patchlevel'\" \(14 characters\)
  1938. sed "s/^X//" >'patchlevel' <<'END_OF_FILE'
  1939. XPatchlevel: 7
  1940. END_OF_FILE
  1941. if test 14 -ne `wc -c <'patchlevel'`; then
  1942.     echo shar: \"'patchlevel'\" unpacked with wrong size!
  1943. fi
  1944. # end of 'patchlevel'
  1945. fi
  1946. if test -f 'tostring.h' -a "${1}" != "-c" ; then 
  1947.   echo shar: Will not clobber existing file \"'tostring.h'\"
  1948. else
  1949. echo shar: Extracting \"'tostring.h'\" \(601 characters\)
  1950. sed "s/^X//" >'tostring.h' <<'END_OF_FILE'
  1951. X/*
  1952. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  1953. X * You may copy, distribute, and use this software as long as this
  1954. X * copyright statement is not removed.
  1955. X */
  1956. X/*
  1957. X * $Id: tostring.h,v 1.3 1991/11/25 14:42:07 cpcahil Exp $
  1958. X */
  1959. X#define B_BIN     2
  1960. X#define B_DEC    10
  1961. X#define B_HEX    16
  1962. X#define B_OCTAL     8
  1963. X
  1964. X/* 
  1965. X * $Log: tostring.h,v $
  1966. X * Revision 1.3  1991/11/25  14:42:07  cpcahil
  1967. X * Final changes in preparation for patch 4 release
  1968. X *
  1969. X * Revision 1.2  90/05/11  00:13:11  cpcahil
  1970. X * added copyright statment
  1971. X * 
  1972. X * Revision 1.1  90/02/23  07:09:05  cpcahil
  1973. X * Initial revision
  1974. X * 
  1975. X */
  1976. END_OF_FILE
  1977. if test 601 -ne `wc -c <'tostring.h'`; then
  1978.     echo shar: \"'tostring.h'\" unpacked with wrong size!
  1979. fi
  1980. # end of 'tostring.h'
  1981. fi
  1982. echo shar: End of archive 1 \(of 5\).
  1983. cp /dev/null ark1isdone
  1984. MISSING=""
  1985. for I in 1 2 3 4 5 ; do
  1986.     if test ! -f ark${I}isdone ; then
  1987.     MISSING="${MISSING} ${I}"
  1988.     fi
  1989. done
  1990. if test "${MISSING}" = "" ; then
  1991.     echo You have unpacked all 5 archives.
  1992.     rm -f ark[1-9]isdone
  1993. else
  1994.     echo You still need to unpack the following archives:
  1995.     echo "        " ${MISSING}
  1996. fi
  1997. ##  End of shell archive.
  1998. exit 0
  1999.  
  2000. exit 0 # Just in case...
  2001.