mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
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.
This commit is contained in:
parent
b92e502695
commit
1612c570b6
@ -1,5 +1,6 @@
|
||||
Version 1.02.103 -
|
||||
================================
|
||||
Introduce libdevmapper wrappers for all malloc-related functions.
|
||||
|
||||
Version 1.02.102 - 7th July 2015
|
||||
================================
|
||||
|
@ -1,3 +1,12 @@
|
||||
dm_bounds_check_debug
|
||||
dm_dump_memory_debug
|
||||
dm_free_aux
|
||||
dm_log
|
||||
dm_log_with_errno
|
||||
dm_malloc_aux
|
||||
dm_malloc_aux_debug
|
||||
dm_realloc_aux
|
||||
dm_strdup_aux
|
||||
dm_task_get_info_with_deferred_remove
|
||||
dm_zalloc_aux
|
||||
dm_zalloc_aux_debug
|
||||
|
7
libdm/.exported_symbols.DM_1_02_103
Normal file
7
libdm/.exported_symbols.DM_1_02_103
Normal file
@ -0,0 +1,7 @@
|
||||
dm_bounds_check_wrapper
|
||||
dm_dump_memory_wrapper
|
||||
dm_free_wrapper
|
||||
dm_malloc_wrapper
|
||||
dm_realloc_wrapper
|
||||
dm_strdup_wrapper
|
||||
dm_zalloc_wrapper
|
@ -962,44 +962,28 @@ uint32_t dm_tree_get_cookie(struct dm_tree_node *node);
|
||||
* Memory management
|
||||
*******************/
|
||||
|
||||
void *dm_malloc_aux(size_t s, const char *file, int line)
|
||||
/*
|
||||
* Never use these functions directly - use the macros following instead.
|
||||
*/
|
||||
void *dm_malloc_wrapper(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__((__warn_unused_result__));
|
||||
void *dm_zalloc_aux(size_t s, const char *file, int line)
|
||||
void *dm_zalloc_wrapper(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)
|
||||
void *dm_realloc_wrapper(void *p, unsigned int s, const char *file, int line)
|
||||
__attribute__((__warn_unused_result__));
|
||||
char *dm_strdup_aux(const char *str, const char *file, int line)
|
||||
__attribute__((__malloc__)) __attribute__((__warn_unused_result__));
|
||||
void dm_free_aux(void *p);
|
||||
void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line)
|
||||
void dm_free_wrapper(void *ptr);
|
||||
char *dm_strdup_wrapper(const char *s, const char *file, int line)
|
||||
__attribute__((__warn_unused_result__));
|
||||
int dm_dump_memory_debug(void);
|
||||
void dm_bounds_check_debug(void);
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
|
||||
# define dm_malloc(s) dm_malloc_aux_debug((s), __FILE__, __LINE__)
|
||||
# define dm_zalloc(s) dm_zalloc_aux_debug((s), __FILE__, __LINE__)
|
||||
# define dm_strdup(s) dm_strdup_aux((s), __FILE__, __LINE__)
|
||||
# define dm_free(p) dm_free_aux(p)
|
||||
# define dm_realloc(p, s) dm_realloc_aux(p, s, __FILE__, __LINE__)
|
||||
# define dm_dump_memory() dm_dump_memory_debug()
|
||||
# define dm_bounds_check() dm_bounds_check_debug()
|
||||
|
||||
#else
|
||||
|
||||
# define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__)
|
||||
# define dm_zalloc(s) dm_zalloc_aux((s), __FILE__, __LINE__)
|
||||
# define dm_strdup(s) strdup(s)
|
||||
# define dm_free(p) free(p)
|
||||
# define dm_realloc(p, s) realloc(p, s)
|
||||
# define dm_dump_memory() {}
|
||||
# define dm_bounds_check() {}
|
||||
|
||||
#endif
|
||||
int dm_dump_memory_wrapper(void);
|
||||
void dm_bounds_check_wrapper(void);
|
||||
|
||||
#define dm_malloc(s) dm_malloc_wrapper((s), __FILE__, __LINE__)
|
||||
#define dm_zalloc(s) dm_zalloc_wrapper((s), __FILE__, __LINE__)
|
||||
#define dm_strdup(s) dm_strdup_wrapper((s), __FILE__, __LINE__)
|
||||
#define dm_free(p) dm_free_wrapper(p)
|
||||
#define dm_realloc(p, s) dm_realloc_wrapper((p), (s), __FILE__, __LINE__)
|
||||
#define dm_dump_memory() dm_dump_memory_wrapper()
|
||||
#define dm_bounds_check() dm_bounds_check_wrapper()
|
||||
|
||||
/*
|
||||
* The pool allocator is useful when you are going to allocate
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user