aboutsummaryrefslogtreecommitdiffstats
path: root/man3/malloc_hook.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/malloc_hook.3')
-rw-r--r--man3/malloc_hook.322
1 files changed, 11 insertions, 11 deletions
diff --git a/man3/malloc_hook.3 b/man3/malloc_hook.3
index 83b213cd56..e524d59397 100644
--- a/man3/malloc_hook.3
+++ b/man3/malloc_hook.3
@@ -105,45 +105,45 @@ Here is a short example of how to use these variables.
.EX
#include <stdio.h>
#include <malloc.h>
-
+\&
/* Prototypes for our hooks */
static void my_init_hook(void);
static void *my_malloc_hook(size_t, const void *);
-
+\&
/* Variables to save original hooks */
static void *(*old_malloc_hook)(size_t, const void *);
-
+\&
/* Override initializing hook from the C library */
void (*__malloc_initialize_hook)(void) = my_init_hook;
-
+\&
static void
my_init_hook(void)
{
old_malloc_hook = __malloc_hook;
__malloc_hook = my_malloc_hook;
}
-
+\&
static void *
my_malloc_hook(size_t size, const void *caller)
{
void *result;
-
+\&
/* Restore all old hooks */
__malloc_hook = old_malloc_hook;
-
+\&
/* Call recursively */
result = malloc(size);
-
+\&
/* Save underlying hooks */
old_malloc_hook = __malloc_hook;
-
+\&
/* printf() might call malloc(), so protect it too */
printf("malloc(%zu) called from %p returns %p\en",
size, caller, result);
-
+\&
/* Restore our own hooks */
__malloc_hook = my_malloc_hook;
-
+\&
return result;
}
.EE