From 6d8f508fe9bed97a12d8f2a8dd01a413d7a60560 Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Mon, 26 Nov 2001 03:04:46 +0000 Subject: 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. --- libpam/pam_malloc.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'libpam/pam_malloc.c') 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 for + * This suite was written by Andrew Morgan for * Linux-PAM. */ @@ -35,6 +35,7 @@ #undef free #undef realloc #undef exit +#undef strdup #include #include @@ -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 */ -- cgit v1.2.3