diff options
author | Andrew G. Morgan <morgan@kernel.org> | 2001-11-26 03:04:46 +0000 |
---|---|---|
committer | Andrew G. Morgan <morgan@kernel.org> | 2001-11-26 03:04:46 +0000 |
commit | 6d8f508fe9bed97a12d8f2a8dd01a413d7a60560 (patch) | |
tree | 68937571edf317260b842d2e5d169c9de3abe786 /libpam/pam_malloc.c | |
parent | d0ae8d409e9e7de2c714197251c4c005fe7d7ad4 (diff) | |
download | pam-6d8f508fe9bed97a12d8f2a8dd01a413d7a60560.tar.gz pam-6d8f508fe9bed97a12d8f2a8dd01a413d7a60560.tar.bz2 pam-6d8f508fe9bed97a12d8f2a8dd01a413d7a60560.zip |
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/pam_malloc.c')
-rw-r--r-- | libpam/pam_malloc.c | 30 |
1 files changed, 26 insertions, 4 deletions
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 */ |