home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume27
/
leak
/
patch02
/
Patch02
Wrap
Text File
|
1994-03-21
|
6KB
|
274 lines
*** ../leak/Makefile Mon Mar 21 17:27:30 1994
--- Makefile Mon Jan 10 10:49:40 1994
***************
*** 10,18 ****
test: leaktest leakdump
@echo Running leaktest
! @leaktest
@echo Running leakdump
! @leakdump
clean:
! -rm -f *.o leaktest leakdump *.dir *.pag
--- 10,18 ----
test: leaktest leakdump
@echo Running leaktest
! @./leaktest
@echo Running leakdump
! @./leakdump
clean:
! -rm -f *.o leaktest leakdump filedbm* memdbm*
*** ../leak/README Mon Mar 21 17:27:30 1994
--- README Mon Jan 10 10:49:40 1994
***************
*** 5,10 ****
--- 5,12 ----
``make'' to compile leak and run a test program. To install leak,
just put leak.h and leak.o in appropriate places.
+ If you use gdbm, you should use -DUSE_GDBM.
+
Here's what I get when making leak:
% make
*** ../leak/leak.c Mon Mar 21 17:27:31 1994
--- leak.c Mon Jan 10 10:57:15 1994
***************
*** 22,28 ****
--- 22,42 ----
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+ #ifdef USE_GDBM
+ #include <gdbm.h>
+ #define dbm_delete gdbm_delete
+ #define dbm_fetch gdbm_fetch
+ #define dbm_firstkey gdbm_firstkey
+ #define dbm_nextkey(dbmfile) gdbm_nextkey(dbmfile, key)
+ #define dbm_open(file, perm, mode) gdbm_open(file, 0, perm, mode, NULL)
+ #define dbm_store gdbm_store
+ #define DBM_INSERT GDBM_INSERT
+ #define DBM_REPLACE GDBM_REPLACE
+ typedef GDBM_FILE dbmfile_t;
+ #else
#include <ndbm.h>
+ typedef DBM *dbmfile_t;
+ #endif
#include "leak.h"
#undef malloc
***************
*** 29,34 ****
--- 43,49 ----
#undef realloc
#undef free
#undef calloc
+ #undef strdup
#define FILE_DBMFILENAME "filedbm"
#define MEMORY_DBMFILENAME "memdbm"
***************
*** 37,46 ****
typedef char *DPTR;
! static DBM *filedbm = NULL;
! static DBM *memdbm = NULL;
! static int nextfile = -1;
! static int dbms_zapped = 0;
struct memdata {
size_t size;
--- 52,61 ----
typedef char *DPTR;
! static dbmfile_t filedbm = NULL;
! static dbmfile_t memdbm = NULL;
! static int nextfile = -1;
! static int dbms_zapped = 0;
struct memdata {
size_t size;
***************
*** 49,55 ****
};
static void
! opendbmfile(DBM **dbmp, /*const*/ char *file)
{
if (*dbmp == NULL && (*dbmp = dbm_open(file, O_RDWR | O_CREAT,
S_IRUSR | S_IWUSR)) == NULL) {
--- 64,70 ----
};
static void
! opendbmfile(dbmfile_t *dbmp, /*const*/ char *file)
{
if (*dbmp == NULL && (*dbmp = dbm_open(file, O_RDWR | O_CREAT,
S_IRUSR | S_IWUSR)) == NULL) {
***************
*** 108,115 ****
--- 123,134 ----
{
if (filedbm)
(void)dbm_close(filedbm);
+ #ifdef USE_GDBM
+ (void)remove(FILE_DBMFILENAME);
+ #else
(void)remove(FILE_DBMFILENAME ".dir");
(void)remove(FILE_DBMFILENAME ".pag");
+ #endif
filedbm = NULL;
}
***************
*** 118,125 ****
--- 137,148 ----
{
if (memdbm)
(void)dbm_close(memdbm);
+ #ifdef USE_GDBM
+ (void)remove(MEMORY_DBMFILENAME);
+ #else
(void)remove(MEMORY_DBMFILENAME ".dir");
(void)remove(MEMORY_DBMFILENAME ".pag");
+ #endif
memdbm = NULL;
}
***************
*** 158,165 ****
void
leak_delete(const void *p, const char *file, int line)
{
! struct memdata md;
! datum key, data;
if (!dbms_zapped) {
leak_clear();
--- 181,187 ----
void
leak_delete(const void *p, const char *file, int line)
{
! datum key;
if (!dbms_zapped) {
leak_clear();
***************
*** 215,221 ****
md = *(struct memdata *)data.dptr;
addr = *(void **)key.dptr;
#ifndef sun
! printf("%08p\t%d\t%d\t%s\n", addr,
#else
printf("%08x\t%d\t%d\t%s\n", (int)addr,
#endif
--- 237,243 ----
md = *(struct memdata *)data.dptr;
addr = *(void **)key.dptr;
#ifndef sun
! printf("%8p\t%d\t%d\t%s\n", addr,
#else
printf("%08x\t%d\t%d\t%s\n", (int)addr,
#endif
***************
*** 274,279 ****
--- 296,320 ----
if (leak_logging && ptr)
leak_insert(ptr, s * t, file, line, DBM_INSERT);
+
+ return ptr;
+ }
+
+ char *
+ leak_strdup(const char *s, const char *file, int line)
+ {
+ size_t size = strlen(s) + 1;
+ #ifdef HAS_STRDUP
+ char *ptr = strdup(s);
+ #else
+ char *ptr = malloc(size);
+
+ if (ptr)
+ strcpy(ptr, s);
+ #endif
+
+ if (leak_logging && ptr)
+ leak_insert(ptr, size, file, line, DBM_INSERT);
return ptr;
}
*** ../leak/leak.h Mon Mar 21 17:27:31 1994
--- leak.h Mon Jan 10 10:52:01 1994
***************
*** 28,37 ****
--- 28,45 ----
extern void *leak_realloc(void *, size_t, const char *, int);
extern void leak_free(void *, const char *, int);
extern void *leak_calloc(size_t, size_t, const char *, int);
+ extern char *leak_strdup(const char *, const char *, int);
+ #undef malloc
+ #undef realloc
+ #undef free
+ #undef calloc
+ #undef strdup
+
#define malloc(s) leak_malloc(s, __FILE__, __LINE__)
#define realloc(p, s) leak_realloc(p, s, __FILE__, __LINE__)
#define free(p) leak_free(p, __FILE__, __LINE__)
#define calloc(s, t) leak_calloc(s, t, __FILE__, __LINE__)
+ #define strdup(s) leak_strdup(s, __FILE__, __LINE__)
#endif /* H_LEAK */
*** ../leak/leaktest.c Mon Mar 21 17:27:32 1994
--- leaktest.c Mon Jan 10 11:00:21 1994
***************
*** 1,5 ****
--- 1,6 ----
#include <stdio.h>
#include <stdlib.h>
+ #include <string.h>
#include <limits.h>
#include "leak.h"
***************
*** 22,27 ****
--- 23,29 ----
p = calloc(40, sizeof(int));
q = realloc(p, 0);
p = malloc(3);
+ q = strdup("Hello world\n");
exit(0);
}
*** /dev/null Mon Mar 21 16:59:19 1994
--- patchlevel.h Mon Jan 10 10:49:40 1994
***************
*** 0 ****
--- 1,19 ----
+ /*
+ * Author: Christopher G. Phillips
+ * Copyright (C) 1993 All Rights Reserved
+ *
+ * NOTICE
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose and without fee is hereby granted
+ * provided that the above copyright notice appear in all copies and
+ * that both the copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * The author makes no representations about the suitability of this
+ * software for any purpose. This software is provided ``as is''
+ * without express or implied warranty.
+ */
+
+ #define VERSION 1
+ #define PATCHLEVEL 2