summaryrefslogtreecommitdiff
path: root/libpam
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2001-11-26 03:04:46 +0000
committerAndrew G. Morgan <morgan@kernel.org>2001-11-26 03:04:46 +0000
commit6d8f508fe9bed97a12d8f2a8dd01a413d7a60560 (patch)
tree68937571edf317260b842d2e5d169c9de3abe786 /libpam
parentd0ae8d409e9e7de2c714197251c4c005fe7d7ad4 (diff)
Relevant BUGIDs: 485454
Purpose of commit: revive feature Commit summary: --------------- malloc et al. debugging was not supported by the new autoconf setup, this commit rectifies that. It also adds a couple of header file inclusions that seem to be needed with recent glibc headers.
Diffstat (limited to 'libpam')
-rw-r--r--libpam/Makefile2
-rw-r--r--libpam/include/security/pam_malloc.h18
-rw-r--r--libpam/pam_delay.c1
-rw-r--r--libpam/pam_malloc.c30
4 files changed, 38 insertions, 13 deletions
diff --git a/libpam/Makefile b/libpam/Makefile
index 80fbf957..61958527 100644
--- a/libpam/Makefile
+++ b/libpam/Makefile
@@ -44,7 +44,7 @@ else
MODULES =
endif
-ifdef MEMORY_DEBUG
+ifdef WITH_MEMORY_DEBUG
EXTRAS += pam_malloc.o
endif
diff --git a/libpam/include/security/pam_malloc.h b/libpam/include/security/pam_malloc.h
index 62777ca8..cc95d7de 100644
--- a/libpam/include/security/pam_malloc.h
+++ b/libpam/include/security/pam_malloc.h
@@ -23,20 +23,22 @@
/* #define valloc(s) pam_valloc(s,__FILE__,__FUNCTION__,__LINE__) */
/* #define alloca(s) pam_alloca(s,__FILE__,__FUNCTION__,__LINE__) */
#define exit(i) pam_exit(i,__FILE__,__FUNCTION__,__LINE__)
+#define strdup(s) pam_strdup(s,__FILE__,__FUNCTION__,__LINE__)
/* these are the prototypes for the wrapper functions */
#include <sys/types.h>
-extern void *pam_malloc(size_t s,const char *,const char *,const int);
-extern void *pam_calloc(size_t n,size_t s,const char *,const char *,const int);
-extern void pam_free(void *x,const char *,const char *,const int);
+extern void *pam_malloc(size_t s,const char *,const char *, int);
+extern void *pam_calloc(size_t n,size_t s,const char *,const char *, int);
+extern void pam_free(void *x,const char *,const char *, int);
extern void *pam_memalign(size_t a,size_t s
- ,const char *,const char *,const int);
-extern void *pam_realloc(void *x,size_t s,const char *,const char *,const int);
-extern void *pam_valloc(size_t s,const char *,const char *,const int);
-extern void *pam_alloca(size_t s,const char *,const char *,const int);
-extern void pam_exit(int i,const char *,const char *,const int);
+ ,const char *,const char *, int);
+extern void *pam_realloc(void *x,size_t s,const char *,const char *, int);
+extern void *pam_valloc(size_t s,const char *,const char *, int);
+extern void *pam_alloca(size_t s,const char *,const char *, int);
+extern void pam_exit(int i,const char *,const char *, int);
+extern char *pam_strdup(const char *,const char *,const char *, int);
/* these are the flags used to turn on and off diagnostics */
diff --git a/libpam/pam_delay.c b/libpam/pam_delay.c
index 553bf72b..d38d47bc 100644
--- a/libpam/pam_delay.c
+++ b/libpam/pam_delay.c
@@ -14,6 +14,7 @@
*/
#include <unistd.h>
+#include <time.h>
#include "pam_private.h"
/* **********************************************************************
diff --git a/libpam/pam_malloc.c b/libpam/pam_malloc.c
index c24ded68..540dceef 100644
--- a/libpam/pam_malloc.c
+++ b/libpam/pam_malloc.c
@@ -5,7 +5,7 @@
/*
* This pair of files helps to locate memory leaks. It is a wrapper for
* the malloc family of calls. (Actutally, it currently only deals
- * with calloc, malloc, realloc, free and exit)
+ * with calloc, malloc, realloc, free, strdup and exit)
*
* To use these functions the header "pam_malloc.h" must be included
* in all parts of the code (that use the malloc functions) and this
@@ -16,7 +16,7 @@
*
* It is a debugging tool and should be turned off in released code.
*
- * This suite was written by Andrew Morgan <morgan@parc.power.net> for
+ * This suite was written by Andrew Morgan <morgan@kernel.org> for
* Linux-PAM.
*/
@@ -35,6 +35,7 @@
#undef free
#undef realloc
#undef exit
+#undef strdup
#include <stdio.h>
#include <stdlib.h>
@@ -128,7 +129,7 @@ struct reference {
static void _dump(const char *say, const struct reference *ref)
{
- _pam_output_debug(" <%s: %p (#%d of %d) req. by %s(); %s line %d>\n"
+ _pam_output_debug(" <%s: %p (#%d of %d) req. by %s(); %s line %d>"
, say
, ref->ptr,ref->nelements,ref->size
, ref->function,ref->file,ref->line);
@@ -311,7 +312,8 @@ void pam_free(void *ptr
{
_fn("free");
- if (on(PAM_MALLOC_FUNC)) err(("request to free %p", ptr));
+ if (on(PAM_MALLOC_FUNC))
+ err(("request (%s:%s():%d) to free %p", file, fn, line, ptr));
if (ptr == NULL) {
if (on(PAM_MALLOC_NULL)) err(("passed NULL pointer"));
@@ -392,4 +394,24 @@ void pam_exit(int i
exit(i);
}
+char *pam_strdup(const char *orig,
+ const char *file, const char *fn, const int line)
+{
+ char *new;
+
+ _fn("strdup");
+
+ if (on(PAM_MALLOC_FUNC)) err(("request for dup of [%s]", orig));
+
+ new = strdup(orig);
+ if (new == NULL) {
+ if (on(PAM_MALLOC_FAIL)) err(("returned NULL"));
+ } else {
+ if (on(PAM_MALLOC_REQUEST)) err(("request dup of [%s]", orig));
+ add_new_ref(new, 1, strlen(new)+1);
+ }
+
+ return new;
+}
+
/* end of file */