home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / leak / patch02 / Patch02
Text File  |  1994-03-21  |  6KB  |  274 lines

  1. *** ../leak/Makefile    Mon Mar 21 17:27:30 1994
  2. --- Makefile    Mon Jan 10 10:49:40 1994
  3. ***************
  4. *** 10,18 ****
  5.   
  6.   test: leaktest leakdump
  7.       @echo Running leaktest
  8. !     @leaktest
  9.       @echo Running leakdump
  10. !     @leakdump
  11.   
  12.   clean:
  13. !     -rm -f *.o leaktest leakdump *.dir *.pag
  14. --- 10,18 ----
  15.   
  16.   test: leaktest leakdump
  17.       @echo Running leaktest
  18. !     @./leaktest
  19.       @echo Running leakdump
  20. !     @./leakdump
  21.   
  22.   clean:
  23. !     -rm -f *.o leaktest leakdump filedbm* memdbm*
  24. *** ../leak/README    Mon Mar 21 17:27:30 1994
  25. --- README    Mon Jan 10 10:49:40 1994
  26. ***************
  27. *** 5,10 ****
  28. --- 5,12 ----
  29.   ``make'' to compile leak and run a test program.  To install leak,
  30.   just put leak.h and leak.o in appropriate places.
  31.   
  32. + If you use gdbm, you should use -DUSE_GDBM.
  33.   Here's what I get when making leak:
  34.   
  35.   % make
  36. *** ../leak/leak.c    Mon Mar 21 17:27:31 1994
  37. --- leak.c    Mon Jan 10 10:57:15 1994
  38. ***************
  39. *** 22,28 ****
  40. --- 22,42 ----
  41.   #include <string.h>
  42.   #include <unistd.h>
  43.   #include <fcntl.h>
  44. + #ifdef USE_GDBM
  45. + #include <gdbm.h>
  46. + #define dbm_delete            gdbm_delete
  47. + #define dbm_fetch            gdbm_fetch
  48. + #define dbm_firstkey            gdbm_firstkey
  49. + #define dbm_nextkey(dbmfile)        gdbm_nextkey(dbmfile, key)
  50. + #define dbm_open(file, perm, mode)    gdbm_open(file, 0, perm, mode, NULL)
  51. + #define dbm_store            gdbm_store
  52. + #define DBM_INSERT            GDBM_INSERT
  53. + #define DBM_REPLACE            GDBM_REPLACE
  54. + typedef GDBM_FILE    dbmfile_t;
  55. + #else
  56.   #include <ndbm.h>
  57. + typedef DBM        *dbmfile_t;
  58. + #endif
  59.   #include "leak.h"
  60.   
  61.   #undef malloc
  62. ***************
  63. *** 29,34 ****
  64. --- 43,49 ----
  65.   #undef realloc
  66.   #undef free
  67.   #undef calloc
  68. + #undef strdup
  69.   
  70.   #define FILE_DBMFILENAME    "filedbm"
  71.   #define MEMORY_DBMFILENAME    "memdbm"
  72. ***************
  73. *** 37,46 ****
  74.   
  75.   typedef char    *DPTR;
  76.   
  77. ! static DBM    *filedbm = NULL;
  78. ! static DBM    *memdbm = NULL;
  79. ! static int    nextfile = -1;
  80. ! static int    dbms_zapped = 0;
  81.   
  82.   struct memdata {
  83.       size_t    size;
  84. --- 52,61 ----
  85.   
  86.   typedef char    *DPTR;
  87.   
  88. ! static dbmfile_t    filedbm = NULL;
  89. ! static dbmfile_t    memdbm = NULL;
  90. ! static int        nextfile = -1;
  91. ! static int        dbms_zapped = 0;
  92.   
  93.   struct memdata {
  94.       size_t    size;
  95. ***************
  96. *** 49,55 ****
  97.   };
  98.   
  99.   static void
  100. ! opendbmfile(DBM **dbmp, /*const*/ char *file)
  101.   {
  102.       if (*dbmp == NULL && (*dbmp = dbm_open(file, O_RDWR | O_CREAT,
  103.         S_IRUSR | S_IWUSR)) == NULL) {
  104. --- 64,70 ----
  105.   };
  106.   
  107.   static void
  108. ! opendbmfile(dbmfile_t *dbmp, /*const*/ char *file)
  109.   {
  110.       if (*dbmp == NULL && (*dbmp = dbm_open(file, O_RDWR | O_CREAT,
  111.         S_IRUSR | S_IWUSR)) == NULL) {
  112. ***************
  113. *** 108,115 ****
  114. --- 123,134 ----
  115.   {
  116.       if (filedbm)
  117.           (void)dbm_close(filedbm);
  118. + #ifdef USE_GDBM
  119. +     (void)remove(FILE_DBMFILENAME);
  120. + #else
  121.       (void)remove(FILE_DBMFILENAME ".dir");
  122.       (void)remove(FILE_DBMFILENAME ".pag");
  123. + #endif
  124.       filedbm = NULL;
  125.   }
  126.   
  127. ***************
  128. *** 118,125 ****
  129. --- 137,148 ----
  130.   {
  131.       if (memdbm)
  132.           (void)dbm_close(memdbm);
  133. + #ifdef USE_GDBM
  134. +     (void)remove(MEMORY_DBMFILENAME);
  135. + #else
  136.       (void)remove(MEMORY_DBMFILENAME ".dir");
  137.       (void)remove(MEMORY_DBMFILENAME ".pag");
  138. + #endif
  139.       memdbm = NULL;
  140.   }
  141.   
  142. ***************
  143. *** 158,165 ****
  144.   void
  145.   leak_delete(const void *p, const char *file, int line)
  146.   {
  147. !     struct memdata    md;
  148. !     datum        key, data;
  149.   
  150.       if (!dbms_zapped) {
  151.           leak_clear();
  152. --- 181,187 ----
  153.   void
  154.   leak_delete(const void *p, const char *file, int line)
  155.   {
  156. !     datum    key;
  157.   
  158.       if (!dbms_zapped) {
  159.           leak_clear();
  160. ***************
  161. *** 215,221 ****
  162.           md = *(struct memdata *)data.dptr;
  163.           addr = *(void **)key.dptr;
  164.   #ifndef sun
  165. !         printf("%08p\t%d\t%d\t%s\n", addr,
  166.   #else
  167.           printf("%08x\t%d\t%d\t%s\n", (int)addr,
  168.   #endif
  169. --- 237,243 ----
  170.           md = *(struct memdata *)data.dptr;
  171.           addr = *(void **)key.dptr;
  172.   #ifndef sun
  173. !         printf("%8p\t%d\t%d\t%s\n", addr,
  174.   #else
  175.           printf("%08x\t%d\t%d\t%s\n", (int)addr,
  176.   #endif
  177. ***************
  178. *** 274,279 ****
  179. --- 296,320 ----
  180.   
  181.       if (leak_logging && ptr)
  182.           leak_insert(ptr, s * t, file, line, DBM_INSERT);
  183. +     return ptr;
  184. + }
  185. + char *
  186. + leak_strdup(const char *s, const char *file, int line)
  187. + {
  188. +     size_t    size = strlen(s) + 1;
  189. + #ifdef HAS_STRDUP
  190. +     char    *ptr = strdup(s);
  191. + #else
  192. +     char    *ptr = malloc(size);
  193. +     if (ptr)
  194. +         strcpy(ptr, s);
  195. + #endif
  196. +     if (leak_logging && ptr)
  197. +         leak_insert(ptr, size, file, line, DBM_INSERT);
  198.   
  199.       return ptr;
  200.   }
  201. *** ../leak/leak.h    Mon Mar 21 17:27:31 1994
  202. --- leak.h    Mon Jan 10 10:52:01 1994
  203. ***************
  204. *** 28,37 ****
  205. --- 28,45 ----
  206.   extern void    *leak_realloc(void *, size_t, const char *, int);
  207.   extern void    leak_free(void *, const char *, int);
  208.   extern void    *leak_calloc(size_t, size_t, const char *, int);
  209. + extern char    *leak_strdup(const char *, const char *, int);
  210.   
  211. + #undef malloc
  212. + #undef realloc
  213. + #undef free
  214. + #undef calloc
  215. + #undef strdup
  216.   #define malloc(s)    leak_malloc(s, __FILE__, __LINE__)
  217.   #define realloc(p, s)    leak_realloc(p, s, __FILE__, __LINE__)
  218.   #define free(p)        leak_free(p, __FILE__, __LINE__)
  219.   #define calloc(s, t)    leak_calloc(s, t, __FILE__, __LINE__)
  220. + #define strdup(s)    leak_strdup(s, __FILE__, __LINE__)
  221.   
  222.   #endif /* H_LEAK */
  223. *** ../leak/leaktest.c    Mon Mar 21 17:27:32 1994
  224. --- leaktest.c    Mon Jan 10 11:00:21 1994
  225. ***************
  226. *** 1,5 ****
  227. --- 1,6 ----
  228.   #include <stdio.h>
  229.   #include <stdlib.h>
  230. + #include <string.h>
  231.   #include <limits.h>
  232.   #include "leak.h"
  233.   
  234. ***************
  235. *** 22,27 ****
  236. --- 23,29 ----
  237.       p = calloc(40, sizeof(int));
  238.       q = realloc(p, 0);
  239.       p = malloc(3);
  240. +     q = strdup("Hello world\n");
  241.   
  242.       exit(0);
  243.   }
  244. *** /dev/null    Mon Mar 21 16:59:19 1994
  245. --- patchlevel.h    Mon Jan 10 10:49:40 1994
  246. ***************
  247. *** 0 ****
  248. --- 1,19 ----
  249. + /*
  250. +  *                 Author:  Christopher G. Phillips
  251. +  *              Copyright (C) 1993 All Rights Reserved
  252. +  *
  253. +  *                              NOTICE
  254. +  *
  255. +  * Permission to use, copy, modify, and distribute this software and
  256. +  * its documentation for any purpose and without fee is hereby granted
  257. +  * provided that the above copyright notice appear in all copies and
  258. +  * that both the copyright notice and this permission notice appear in
  259. +  * supporting documentation.
  260. +  *
  261. +  * The author makes no representations about the suitability of this
  262. +  * software for any purpose.  This software is provided ``as is''
  263. +  * without express or implied warranty.
  264. +  */
  265. + #define VERSION        1
  266. + #define PATCHLEVEL    2
  267.