summaryrefslogtreecommitdiff
path: root/libpam/pam_malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpam/pam_malloc.c')
-rw-r--r--libpam/pam_malloc.c30
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 */