home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume27 / leak / patch01 < prev    next >
Encoding:
Text File  |  1993-11-18  |  16.8 KB  |  705 lines

  1. Newsgroups: comp.sources.unix
  2. From: pefv700@hermes.chpc.utexas.edu (Christopher Phillips)
  3. Subject: v27i086: leak - quick and dirty code to find memory leaks, Patch01
  4. Sender: unix-sources-moderator@gw.home.vix.com
  5. Approved: vixie@gw.home.vix.com
  6.  
  7. Submitted-By: pefv700@hermes.chpc.utexas.edu (Christopher Phillips)
  8. Posting-Number: Volume 27, Issue 86
  9. Archive-Name: leak/patch01
  10.  
  11. This is patch01 for leak.  It includes several changes:
  12.  
  13. - A manual page
  14. - External names now start with leak_
  15. - Logging can be disabled with the external variable leak_logging
  16. - The #define's got pretty long when adding leak_logging, so they
  17.   now just call new functions
  18. - Functions are available to clear and dump the memory database
  19.   are included
  20. - The insertion function now uses the mode argument
  21. - The logging of reallocs now knows that size = 0 means to free
  22. - With GNU's dbm, int2file clobbers things such that the addresses
  23.   printed are wrong -- thanks to Hal Peterson of Cray for reporting this
  24. - LDFLAGS and LIBS have been added to the Makefile for flexibility
  25.  
  26. Just cd to the source directory and type "patch -p0 < THIS_FILE".
  27.  
  28. Chris
  29.  
  30.  
  31. #! /bin/sh
  32. # This is a shell archive.  Remove anything before this line, then unpack
  33. # it by saving it into a file and typing "sh file".  To overwrite existing
  34. # files, type "sh file -c".  You can also feed this as standard input via
  35. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  36. # will see the following message at the end:
  37. #        "End of shell archive."
  38. # Contents:  patch01
  39. # Wrapped by pefv700@hermes on Wed Nov 10 14:07:23 1993
  40. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  41. if test -f 'patch01' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'patch01'\"
  43. else
  44. echo shar: Extracting \"'patch01'\" \(14525 characters\)
  45. sed "s/^X//" >'patch01' <<'END_OF_FILE'
  46. X*** ../leak.old/Makefile    Wed Nov 10 13:55:52 1993
  47. X--- Makefile    Wed Nov 10 13:34:12 1993
  48. X***************
  49. X*** 1,10 ****
  50. X  all: test leaktest leakdump
  51. X  
  52. X  leaktest: leaktest.o leak.o
  53. X!     $(CC) -o $@ leaktest.o leak.o
  54. X  
  55. X  leakdump: leakdump.o leak.o
  56. X!     $(CC) -o $@ leakdump.o leak.o
  57. X  
  58. X  test: leaktest leakdump
  59. X      @echo Running leaktest
  60. X--- 1,12 ----
  61. X  all: test leaktest leakdump
  62. X  
  63. X  leaktest: leaktest.o leak.o
  64. X!     $(CC) $(LDFLAGS) -o $@ leaktest.o leak.o $(LIBS)
  65. X  
  66. X  leakdump: leakdump.o leak.o
  67. X!     $(CC) $(LDFLAGS) -o $@ leakdump.o leak.o $(LIBS)
  68. X! 
  69. X! leak.o leaktest.o leakdump.o: leak.h
  70. X  
  71. X  test: leaktest leakdump
  72. X      @echo Running leaktest
  73. X*** ../leak.old/README    Wed Nov 10 13:55:52 1993
  74. X--- README    Wed Nov 10 13:33:52 1993
  75. X***************
  76. X*** 1,25 ****
  77. X- 
  78. X  LEAK - Quick and dirty code to find memory leaks
  79. X-        (Requires ANSI C and ndbm)
  80. X  
  81. X! What leak does:
  82. X  
  83. X!     * Logs all malloc/realloc/free calls to dbm files
  84. X!       with filename and line number
  85. X!     * Complains about reallocing/freeing addresses not
  86. X!       the result of a prior malloc/realloc
  87. X!     * Dumps unfreed addresses upon request
  88. X  
  89. X- How to use leak:
  90. X- 
  91. X-     * #include "leak.h" in all source files that call
  92. X-       malloc/realloc/free
  93. X-     * recompile
  94. X-     * run program
  95. X-     * run leakdump
  96. X- 
  97. X- That's all there is to it.  For example:
  98. X- 
  99. X  % make
  100. X  cc -c leaktest.c -o leaktest.o
  101. X  cc -c leak.c -o leak.o
  102. X--- 1,12 ----
  103. X  LEAK - Quick and dirty code to find memory leaks
  104. X  
  105. X! You shouldn't have any problems compiling and using leak as long
  106. X! as you have an ANSI C compiler and the ndbm library.  Just type
  107. X! ``make'' to compile leak and run a test program.  To install leak,
  108. X! just put leak.h and leak.o in appropriate places.
  109. X  
  110. X! Here's what I get when making leak:
  111. X  
  112. X  % make
  113. X  cc -c leaktest.c -o leaktest.o
  114. X  cc -c leak.c -o leak.o
  115. X***************
  116. X*** 31,53 ****
  117. X  Nonfreed blocks:
  118. X  Address         Size    Line    File
  119. X  ------------------------------------
  120. X! 140004110       40      16      leaktest.c
  121. X  %
  122. X- 
  123. X- Notes:
  124. X-     * The dbm files are not automatically deleted
  125. X-     * When using libraries that use malloc/realloc/free
  126. X-       but for which you don't have source, don't have leak
  127. X-       log the use of this memory.  For example, if libMRF.a
  128. X-       mallocs memory that you should free, don't have leak
  129. X-       log the free or it will complain.
  130. X-     * If you have library functions whose main function
  131. X-       is to call malloc/realloc, it is usually more relevant
  132. X-       to know which function called the library function.
  133. X-       Unfortunately, determining that information is
  134. X-       platform-specific.
  135. X-     * All malloced/realloced memory should be explicitly
  136. X-       freed or it will show up in the dump.
  137. X  
  138. X  
  139. X  Chris
  140. X--- 18,25 ----
  141. X  Nonfreed blocks:
  142. X  Address         Size    Line    File
  143. X  ------------------------------------
  144. X! 140006010       3       24      leaktest.c
  145. X  %
  146. X  
  147. X  
  148. X  Chris
  149. X*** /dev/null    Wed Nov 10 13:56:29 1993
  150. X--- leak.3    Wed Nov 10 13:33:52 1993
  151. X***************
  152. X*** 0 ****
  153. X--- 1,112 ----
  154. X+ .\" leak.3
  155. X+ .TH LEAK 3 "October 25, 1993"
  156. X+ .SH NAME
  157. X+ leak_logging, leak_clear, leak_dump \- memory leak detection
  158. X+ .SH SYNOPSIS
  159. X+ .LP
  160. X+ .nf
  161. X+ .ft B
  162. X+ #include "leak.h"
  163. X+ .ft
  164. X+ .fi
  165. X+ .LP
  166. X+ .nf
  167. X+ .ft B
  168. X+ extern int    leak_logging;
  169. X+ .ft
  170. X+ .fi
  171. X+ .LP
  172. X+ .nf
  173. X+ .ft B
  174. X+ extern void    leak_clear(void);
  175. X+ .ft
  176. X+ .fi
  177. X+ .LP
  178. X+ .nf
  179. X+ .ft B
  180. X+ extern void    leak_dump(void);
  181. X+ .ft
  182. X+ .fi
  183. X+ .SH DESCRIPTION
  184. X+ .LP
  185. X+ This package provides a ``quick-and-dirty'' method for detecting
  186. X+ memory leaks in ANSI C source files.
  187. X+ Calls to the dynamic memory allocation functions
  188. X+ .BR malloc(\|) ,
  189. X+ .BR realloc(\|) ,
  190. X+ .BR calloc(\|) ,
  191. X+ and
  192. X+ .BR free(\|)
  193. X+ are logged using the
  194. X+ .BR ndbm (3)
  195. X+ database library.
  196. X+ .LP
  197. X+ To use the package, source files which contain dynamic memory
  198. X+ allocation routine calls should
  199. X+ .ft B
  200. X+ #include "leak.h"
  201. X+ .ft
  202. X+ and be recompiled.
  203. X+ The object file
  204. X+ .B leak.o
  205. X+ must be linked into the executable program. 
  206. X+ .LP
  207. X+ Two
  208. X+ .B ndbm
  209. X+ databases are use by
  210. X+ .BR leak .
  211. X+ The first manages filenames and uses the prefix
  212. X+ .IR filedbm
  213. X+ while the second stores memory addresses and sizes and uses the prefix
  214. X+ .IR memdbm .
  215. X+ The databases are created if necessary and the memory address database
  216. X+ is cleared when the first logging occurs.
  217. X+ .LP
  218. X+ Memory addresses in the database can be printed to standard output
  219. X+ using
  220. X+ .BR leak_dump(\|)
  221. X+ while the database can be cleared using
  222. X+ .BR leak_clear(\|) .
  223. X+ The external variable
  224. X+ .IR leak_logging
  225. X+ can be set to zero to disable logging and nonzero to enable logging.
  226. X+ Logging is enabled upon program invocation.
  227. X+ .SH NOTES
  228. X+ .LP
  229. X+ The
  230. X+ .BR #define
  231. X+ facility of ANSI C is used to ``trap'' calls to 
  232. X+ memory allocation functions.
  233. X+ Therefore, when using libraries that manage dynamic memory
  234. X+ but for which you don't have source, don't have
  235. X+ .B leak
  236. X+ log the use of this memory.
  237. X+ For example, if a library function returns dynamic
  238. X+ memory that you should free, don't log the call to 
  239. X+ .BR free (\|)
  240. X+ or
  241. X+ .B leak
  242. X+ will complain.
  243. X+ Also, if you have a library function whose main purpose
  244. X+ is to manage dynamic memory, it is usually more
  245. X+ relevant to know which function called the library
  246. X+ function.  Unfortunately, determining that information
  247. X+ is platform-specific.
  248. X+ .LP
  249. X+ All dynamically allocated memory that is logged should be
  250. X+ explicitly freed or it will show up in the dump.
  251. X+ .SH SEE ALSO
  252. X+ .BR calloc (3),
  253. X+ .BR free (3),
  254. X+ .BR malloc (3),
  255. X+ .BR realloc (3).
  256. X+ .SH DIAGNOSTICS
  257. X+ .LP
  258. X+ .B leak
  259. X+ will complain to standard error if an attempt is made to free an
  260. X+ address that is not present in the memory address database.
  261. X+ .SH AUTHOR
  262. X+ .LP
  263. X+ .nf
  264. X+ Christopher G. Phillips
  265. X+ pefv700@utpe.pe.utexas.edu
  266. X*** ../leak.old/leak.c    Wed Nov 10 13:55:52 1993
  267. X--- leak.c    Wed Nov 10 13:34:12 1993
  268. X***************
  269. X*** 22,33 ****
  270. X  #include <string.h>
  271. X  #include <unistd.h>
  272. X  #include <fcntl.h>
  273. X  #include "leak.h"
  274. X  
  275. X  #define FILE_DBMFILENAME    "filedbm"
  276. X  #define MEMORY_DBMFILENAME    "memdbm"
  277. X  
  278. X! void    *_ptr;
  279. X  
  280. X  typedef char    *DPTR;
  281. X  
  282. X--- 22,39 ----
  283. X  #include <string.h>
  284. X  #include <unistd.h>
  285. X  #include <fcntl.h>
  286. X+ #include <ndbm.h>
  287. X  #include "leak.h"
  288. X  
  289. X+ #undef malloc
  290. X+ #undef realloc
  291. X+ #undef free
  292. X+ #undef calloc
  293. X+ 
  294. X  #define FILE_DBMFILENAME    "filedbm"
  295. X  #define MEMORY_DBMFILENAME    "memdbm"
  296. X  
  297. X! int    leak_logging = 1;
  298. X  
  299. X  typedef char    *DPTR;
  300. X  
  301. X***************
  302. X*** 34,39 ****
  303. X--- 40,46 ----
  304. X  static DBM    *filedbm = NULL;
  305. X  static DBM    *memdbm = NULL;
  306. X  static int    nextfile = -1;
  307. X+ static int    dbms_zapped = 0;
  308. X  
  309. X  struct memdata {
  310. X      size_t    size;
  311. X***************
  312. X*** 42,52 ****
  313. X  };
  314. X  
  315. X  static void
  316. X! opendbmfiles(mode_t mode)
  317. X  {
  318. X!     if (filedbm == NULL && (filedbm = dbm_open(FILE_DBMFILENAME, mode,
  319. X!       S_IRUSR | S_IWUSR)) == NULL
  320. X!       || memdbm == NULL && (memdbm = dbm_open(MEMORY_DBMFILENAME, mode,
  321. X        S_IRUSR | S_IWUSR)) == NULL) {
  322. X          perror("dbm_open");
  323. X          exit(1);
  324. X--- 49,57 ----
  325. X  };
  326. X  
  327. X  static void
  328. X! opendbmfile(DBM **dbmp, /*const*/ char *file)
  329. X  {
  330. X!     if (*dbmp == NULL && (*dbmp = dbm_open(file, O_RDWR | O_CREAT,
  331. X        S_IRUSR | S_IWUSR)) == NULL) {
  332. X          perror("dbm_open");
  333. X          exit(1);
  334. X***************
  335. X*** 98,111 ****
  336. X      return "???";
  337. X  }
  338. X  
  339. X  void
  340. X! _dbinsert(void *p, size_t size, const char *file, int line, int mode)
  341. X  {
  342. X      struct memdata    md;
  343. X      datum        key, data;
  344. X  
  345. X!     if (!filedbm || !memdbm)
  346. X!         opendbmfiles(O_RDWR | O_CREAT | O_TRUNC);
  347. X  
  348. X      md.file = file2int(file);
  349. X  
  350. X--- 103,144 ----
  351. X      return "???";
  352. X  }
  353. X  
  354. X+ static void
  355. X+ leak_fclear(void)
  356. X+ {
  357. X+     if (filedbm)
  358. X+         (void)dbm_close(filedbm);
  359. X+     (void)remove(FILE_DBMFILENAME ".dir");
  360. X+     (void)remove(FILE_DBMFILENAME ".pag");
  361. X+     filedbm = NULL;
  362. X+ }
  363. X+ 
  364. X  void
  365. X! leak_clear(void)
  366. X  {
  367. X+     if (memdbm)
  368. X+         (void)dbm_close(memdbm);
  369. X+     (void)remove(MEMORY_DBMFILENAME ".dir");
  370. X+     (void)remove(MEMORY_DBMFILENAME ".pag");
  371. X+     memdbm = NULL;
  372. X+ }
  373. X+ 
  374. X+ void
  375. X+ leak_insert(const void *p, size_t size, const char *file, int line, int mode)
  376. X+ {
  377. X      struct memdata    md;
  378. X      datum        key, data;
  379. X  
  380. X!     if (!dbms_zapped) {
  381. X!         leak_clear();
  382. X!         leak_fclear();
  383. X!         dbms_zapped = 1;
  384. X!     }
  385. X!         
  386. X!     if (!filedbm)
  387. X!         opendbmfile(&filedbm, FILE_DBMFILENAME);
  388. X!     if (!memdbm)
  389. X!         opendbmfile(&memdbm, MEMORY_DBMFILENAME);
  390. X  
  391. X      md.file = file2int(file);
  392. X  
  393. X***************
  394. X*** 116,122 ****
  395. X      data.dptr = (DPTR)&md;
  396. X      data.dsize = sizeof md;
  397. X  
  398. X!     if (dbm_store(memdbm, key, data, DBM_INSERT) == -1) {
  399. X          perror("dbm_store");
  400. X          exit(1);
  401. X      }
  402. X--- 149,155 ----
  403. X      data.dptr = (DPTR)&md;
  404. X      data.dsize = sizeof md;
  405. X  
  406. X!     if (dbm_store(memdbm, key, data, mode) == -1) {
  407. X          perror("dbm_store");
  408. X          exit(1);
  409. X      }
  410. X***************
  411. X*** 123,157 ****
  412. X  }
  413. X  
  414. X  void
  415. X! _dbdelete(void *p, const char *file, int line)
  416. X  {
  417. X      struct memdata    md;
  418. X      datum        key, data;
  419. X  
  420. X      key.dptr = (DPTR)&p;
  421. X      key.dsize = sizeof p;
  422. X  
  423. X!     if (memdbm == NULL) {
  424. X!         fprintf(stderr, "free before malloc from \"%s\", line %d\n",
  425. X!           file, line);
  426. X!         exit(1);
  427. X!     } else if (dbm_delete(memdbm, key) == -1) {
  428. X          fprintf(stderr,
  429. X            "free unmalloced pointer %p from \"%s\", line %d\n", p, file,
  430. X            line);
  431. X-         exit(1);
  432. X      }
  433. X  }
  434. X  
  435. X  void
  436. X! _dbdump(mode_t mode)
  437. X  {
  438. X!     struct memdata    *mdp;
  439. X      datum        key, data;
  440. X      int        do_title = 1;
  441. X  
  442. X!     if (!filedbm || !memdbm)
  443. X!         opendbmfiles(mode);
  444. X  
  445. X      for (key = dbm_firstkey(memdbm); key.dptr; key = dbm_nextkey(memdbm)) {
  446. X          data = dbm_fetch(memdbm, key);
  447. X--- 156,196 ----
  448. X  }
  449. X  
  450. X  void
  451. X! leak_delete(const void *p, const char *file, int line)
  452. X  {
  453. X      struct memdata    md;
  454. X      datum        key, data;
  455. X  
  456. X+     if (!dbms_zapped) {
  457. X+         leak_clear();
  458. X+         leak_fclear();
  459. X+         dbms_zapped = 1;
  460. X+     }
  461. X+ 
  462. X      key.dptr = (DPTR)&p;
  463. X      key.dsize = sizeof p;
  464. X  
  465. X!     if (!memdbm)
  466. X!         opendbmfile(&memdbm, MEMORY_DBMFILENAME);
  467. X!     if (dbm_delete(memdbm, key) == -1) {
  468. X          fprintf(stderr,
  469. X            "free unmalloced pointer %p from \"%s\", line %d\n", p, file,
  470. X            line);
  471. X      }
  472. X  }
  473. X  
  474. X  void
  475. X! leak_dump(void)
  476. X  {
  477. X!     struct memdata    md;
  478. X      datum        key, data;
  479. X+     void        *addr;
  480. X      int        do_title = 1;
  481. X  
  482. X!     if (!filedbm)
  483. X!         opendbmfile(&filedbm, FILE_DBMFILENAME);
  484. X!     if (!memdbm)
  485. X!         opendbmfile(&memdbm, MEMORY_DBMFILENAME);
  486. X  
  487. X      for (key = dbm_firstkey(memdbm); key.dptr; key = dbm_nextkey(memdbm)) {
  488. X          data = dbm_fetch(memdbm, key);
  489. X***************
  490. X*** 169,196 ****
  491. X              putchar('\n');
  492. X              do_title = 0;
  493. X          }
  494. X!         mdp = (struct memdata *)data.dptr;
  495. X  #ifndef sun
  496. X!         printf("%08p\t%d\t%d\t%s\n", *(void **)key.dptr,
  497. X  #else
  498. X!         printf("%08x\t%d\t%d\t%s\n", (int)*(void **)key.dptr,
  499. X  #endif
  500. X!           mdp->size, mdp->line, int2file(mdp->file));
  501. X      }
  502. X  }
  503. X  
  504. X! #if 0
  505. X  void
  506. X! exit(int status)
  507. X  {
  508. X!     _dbdump(O_RDONLY);
  509. X!     (void)dbm_close(memdbm);
  510. X!     (void)dbm_close(filedbm);
  511. X!     (void)remove("memdbm.dir");
  512. X!     (void)remove("memdbm.pag");
  513. X!     (void)remove("filedbm.dir");
  514. X!     (void)remove("filedbm.pag");
  515. X!     fflush(NULL);
  516. X!     _exit(status);
  517. X  }
  518. X! #endif
  519. X--- 208,279 ----
  520. X              putchar('\n');
  521. X              do_title = 0;
  522. X          }
  523. X!         /*
  524. X!          * Copy the key and data
  525. X!          * because they may be overwritten in int2file.
  526. X!          */
  527. X!         md = *(struct memdata *)data.dptr;
  528. X!         addr = *(void **)key.dptr;
  529. X  #ifndef sun
  530. X!         printf("%08p\t%d\t%d\t%s\n", addr,
  531. X  #else
  532. X!         printf("%08x\t%d\t%d\t%s\n", (int)addr,
  533. X  #endif
  534. X!           md.size, md.line, int2file(md.file));
  535. X      }
  536. X  }
  537. X  
  538. X! void *
  539. X! leak_malloc(size_t size, const char *file, int line)
  540. X! {
  541. X!     void    *ptr = malloc(size);
  542. X! 
  543. X!     if (leak_logging && ptr)
  544. X!         leak_insert(ptr, size, file, line, DBM_INSERT);
  545. X! 
  546. X!     return ptr;
  547. X! }
  548. X! 
  549. X! void *
  550. X! leak_realloc(void *oldptr, size_t size, const char *file, int line)
  551. X! {
  552. X!     void    *newptr = realloc(oldptr, size);
  553. X! 
  554. X!     if (leak_logging) {
  555. X!         if (!size && oldptr)
  556. X!             leak_delete(oldptr, file, line);
  557. X!         else if (newptr) {
  558. X!             if (newptr == oldptr)
  559. X!                 leak_insert(newptr, size, file, line,
  560. X!                   DBM_REPLACE);
  561. X!             else {
  562. X!                 if (oldptr)
  563. X!                     leak_delete(oldptr, file, line);
  564. X!                 leak_insert(newptr, size, file, line,
  565. X!                   DBM_INSERT);
  566. X!             }
  567. X!         }
  568. X!     }
  569. X! 
  570. X!     return newptr;
  571. X! }
  572. X! 
  573. X  void
  574. X! leak_free(void *ptr, const char *file, int line)
  575. X  {
  576. X!     free(ptr);
  577. X! 
  578. X!     if (leak_logging && ptr)
  579. X!         leak_delete(ptr, file, line);
  580. X  }
  581. X! 
  582. X! void *
  583. X! leak_calloc(size_t s, size_t t, const char *file, int line)
  584. X! {
  585. X!     void    *ptr = calloc(s, t);
  586. X! 
  587. X!     if (leak_logging && ptr)
  588. X!         leak_insert(ptr, s * t, file, line, DBM_INSERT);
  589. X! 
  590. X!     return ptr;
  591. X! }
  592. X*** ../leak.old/leak.h    Wed Nov 10 13:55:52 1993
  593. X--- leak.h    Wed Nov 10 13:33:53 1993
  594. X***************
  595. X*** 19,43 ****
  596. X  #define H_LEAK
  597. X  
  598. X  #include <sys/types.h>
  599. X- #include <stdlib.h>
  600. X- #include <ndbm.h>
  601. X  
  602. X! extern void    *_ptr;
  603. X! extern void    _dbinsert(void *, size_t, const char *, int, int);
  604. X! extern void    _dbdelete(void *, const char *, int);
  605. X  
  606. X! #define malloc(s) \
  607. X!   (_ptr = malloc(s), _dbinsert(_ptr, s, __FILE__, __LINE__, DBM_INSERT), _ptr)
  608. X  
  609. X! #define realloc(p, s) \
  610. X!     ((_ptr = realloc(p, s)), \
  611. X!     ((_ptr && _ptr == p) \
  612. X!       ? _dbinsert(_ptr, s, __FILE__, __LINE__, DBM_REPLACE), 0 : 0), \
  613. X!     (_ptr ? \
  614. X!      (p ? _dbdelete(p, __FILE__, __LINE__), 0 : 0), \
  615. X!     _dbinsert(_ptr, s, __FILE__, __LINE__, DBM_INSERT), 0 : 0), \
  616. X!     _ptr)
  617. X! 
  618. X! #define free(p)        (p ? _dbdelete(p, __FILE__, __LINE__), 0 : 0), free(p)
  619. X  
  620. X  #endif /* H_LEAK */
  621. X--- 19,37 ----
  622. X  #define H_LEAK
  623. X  
  624. X  #include <sys/types.h>
  625. X  
  626. X! extern int    leak_logging;
  627. X! extern void    leak_dump(void);
  628. X! extern void    leak_clear(void);
  629. X  
  630. X! extern void    *leak_malloc(size_t, const char *, int);
  631. X! extern void    *leak_realloc(void *, size_t, const char *, int);
  632. X! extern void    leak_free(void *, const char *, int);
  633. X! extern void    *leak_calloc(size_t, size_t, const char *, int);
  634. X  
  635. X! #define malloc(s)    leak_malloc(s, __FILE__, __LINE__)
  636. X! #define realloc(p, s)    leak_realloc(p, s, __FILE__, __LINE__)
  637. X! #define free(p)        leak_free(p, __FILE__, __LINE__)
  638. X! #define calloc(s, t)    leak_calloc(s, t, __FILE__, __LINE__)
  639. X  
  640. X  #endif /* H_LEAK */
  641. X*** ../leak.old/leakdump.c    Wed Nov 10 13:55:53 1993
  642. X--- leakdump.c    Wed Nov 10 13:33:54 1993
  643. X***************
  644. X*** 17,29 ****
  645. X  
  646. X  #include <stdio.h>
  647. X  #include <stdlib.h>
  648. X- #include <fcntl.h>
  649. X  #include "leak.h"
  650. X  
  651. X  int
  652. X  main(void)
  653. X  {
  654. X!     _dbdump(O_RDONLY);
  655. X  
  656. X      exit(0);
  657. X  }
  658. X--- 17,28 ----
  659. X  
  660. X  #include <stdio.h>
  661. X  #include <stdlib.h>
  662. X  #include "leak.h"
  663. X  
  664. X  int
  665. X  main(void)
  666. X  {
  667. X!     leak_dump();
  668. X  
  669. X      exit(0);
  670. X  }
  671. X*** ../leak.old/leaktest.c    Wed Nov 10 13:55:53 1993
  672. X--- leaktest.c    Wed Nov 10 13:33:55 1993
  673. X***************
  674. X*** 14,20 ****
  675. X          free(p);
  676. X      else
  677. X          free(q);
  678. X!     p = malloc(40);
  679. X  
  680. X      exit(0);
  681. X  }
  682. X--- 14,27 ----
  683. X          free(p);
  684. X      else
  685. X          free(q);
  686. X! 
  687. X!     leak_logging = 0;
  688. X!     p = malloc(100);
  689. X!     leak_logging = 1;
  690. X! 
  691. X!     p = calloc(40, sizeof(int));
  692. X!     q = realloc(p, 0);
  693. X!     p = malloc(3);
  694. X  
  695. X      exit(0);
  696. X  }
  697. END_OF_FILE
  698. if test 14525 -ne `wc -c <'patch01'`; then
  699.     echo shar: \"'patch01'\" unpacked with wrong size!
  700. fi
  701. # end of 'patch01'
  702. fi
  703. echo shar: End of shell archive.
  704. exit 0
  705.