summaryrefslogtreecommitdiff
path: root/libdm/mm
diff options
context:
space:
mode:
authorAlasdair G Kergon <agk@redhat.com>2015-07-22 23:03:32 +0100
committerAlasdair G Kergon <agk@redhat.com>2015-07-22 23:11:48 +0100
commit1612c570b6412b68349b055ba3a6dab1796b8f35 (patch)
tree0d65283bf155546500054b2018d7af3ca8243561 /libdm/mm
parentb92e5026957c5ca72e6e88304feaf7527ca80af1 (diff)
downloadlvm2-1612c570b6412b68349b055ba3a6dab1796b8f35.tar.gz
libdm: Use wrappers for all malloc functions.
Move the DEBUG_MEM decision inside libdevmapper.so instead of exposing it in libdevmapper.h which causes failures if the binary and library were compiled with opposite debugging settings.
Diffstat (limited to 'libdm/mm')
-rw-r--r--libdm/mm/dbg_malloc.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/libdm/mm/dbg_malloc.c b/libdm/mm/dbg_malloc.c
index e26f05eef..ac714807f 100644
--- a/libdm/mm/dbg_malloc.c
+++ b/libdm/mm/dbg_malloc.c
@@ -22,6 +22,22 @@
#include <assert.h>
#include <stdarg.h>
+void *dm_malloc_aux(size_t s, const char *file, int line)
+ __attribute__((__malloc__)) __attribute__((__warn_unused_result__));
+void *dm_malloc_aux_debug(size_t s, const char *file, int line)
+ __attribute__((__malloc__)) __attribute__((__warn_unused_result__));
+void *dm_zalloc_aux(size_t s, const char *file, int line)
+ __attribute__((__malloc__)) __attribute__((__warn_unused_result__));
+void *dm_zalloc_aux_debug(size_t s, const char *file, int line)
+ __attribute__((__malloc__)) __attribute__((__warn_unused_result__));
+void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line)
+ __attribute__((__warn_unused_result__));
+void dm_free_aux(void *p);
+char *dm_strdup_aux(const char *str, const char *file, int line)
+ __attribute__((__warn_unused_result__));
+int dm_dump_memory_debug(void);
+void dm_bounds_check_debug(void);
+
char *dm_strdup_aux(const char *str, const char *file, int line)
{
char *ret;
@@ -279,3 +295,82 @@ void *dm_zalloc_aux(size_t s, const char *file, int line)
return ptr;
}
+
+#ifdef DEBUG_MEM
+
+void *dm_malloc_wrapper(size_t s, const char *file, int line)
+{
+ return dm_malloc_aux_debug(s, file, line);
+}
+
+void *dm_zalloc_wrapper(size_t s, const char *file, int line)
+{
+ return dm_zalloc_aux_debug(s, file, line);
+}
+
+char *dm_strdup_wrapper(const char *str, const char *file, int line)
+{
+ return dm_strdup_aux(str, file, line);
+}
+
+void dm_free_wrapper(void *ptr)
+{
+ dm_free_aux(ptr);
+}
+
+void *dm_realloc_wrapper(void *p, unsigned int s, const char *file, int line)
+{
+ return dm_realloc_aux(p, s, file, line);
+}
+
+int dm_dump_memory_wrapper(void)
+{
+ return dm_dump_memory_debug();
+}
+
+void dm_bounds_check_wrapper(void)
+{
+ dm_bounds_check_debug();
+}
+
+#else /* !DEBUG_MEM */
+
+void *dm_malloc_wrapper(size_t s, const char *file, int line)
+{
+ return dm_malloc_aux(s, file, line);
+}
+
+void *dm_zalloc_wrapper(size_t s, const char *file, int line)
+{
+ return dm_zalloc_aux(s, file, line);
+}
+
+char *dm_strdup_wrapper(const char *str,
+ const char *file __attribute__((unused)),
+ int line __attribute__((unused)))
+{
+ return strdup(str);
+}
+
+void dm_free_wrapper(void *ptr)
+{
+ free(ptr);
+}
+
+void *dm_realloc_wrapper(void *p, unsigned int s,
+ const char *file __attribute__((unused)),
+ int line __attribute__((unused)))
+{
+ return realloc(p, s);
+}
+
+int dm_dump_memory_wrapper(void)
+{
+ return 1;
+}
+
+void dm_bounds_check_wrapper(void)
+{
+}
+
+#endif /* DEBUG_MEM */