aboutsummaryrefslogtreecommitdiffstats
path: root/man3/malloc_hook.3
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-05-03 00:48:14 +0200
committerAlejandro Colomar <alx@kernel.org>2023-05-03 00:48:22 +0200
commitfe5dba139dc089eae4061fdc17f087e71f48b198 (patch)
tree54af56b1b0138bde9a21e99372ab68ce4d64564a /man3/malloc_hook.3
parent5a0d9ed151e6449d978fabdd654cacc17b20a235 (diff)
downloadman-pages-fe5dba139dc089eae4061fdc17f087e71f48b198.tar.gz
man*/, man.ignore.grep: srcfix; warn about blank lines
- Use the dummy character to avoid warnings in examples. - Re-enable the warning. Suggested-by: "G. Branden Robinson" <g.branden.robinson@gmail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
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