Bug 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r?njn
Until now, the malloc implementation functions would call the
replace-malloc functions if they exist, and fallback to the real
allocator in no such function exists. Instead of doing this, we now
fill the empty slots in the malloc_table_t with the real allocator
functions.
--- a/memory/build/replace_malloc.c
+++ b/memory/build/replace_malloc.c
@@ -124,16 +124,22 @@ replace_malloc_init_funcs()
# define MALLOC_FUNCS (MALLOC_FUNCS_INIT | MALLOC_FUNCS_BRIDGE)
# include "malloc_decls.h"
#endif
#define MALLOC_DECL(name, ...) \
replace_malloc_table.name = REPLACE_MALLOC_GET_FUNC(handle, name);
#include "malloc_decls.h"
}
+
+#define MALLOC_DECL(name, ...) \
+ if (!replace_malloc_table.name) { \
+ replace_malloc_table.name = je_ ## name; \
+ }
+#include "malloc_decls.h"
}
/*
* Below is the malloc implementation overriding jemalloc and calling the
* replacement functions if they exist.
*/
static int replace_malloc_initialized = 0;
@@ -169,21 +175,17 @@ init()
#define ARGS2(t1, t2) ARGS1(t1), arg2
#define ARGS3(t1, t2, t3) ARGS2(t1, t2), arg3
#define GENERIC_MALLOC_DECL_HELPER(name, return, return_type, ...) \
return_type name ## _impl(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) \
{ \
if (MOZ_UNLIKELY(!replace_malloc_initialized)) \
init(); \
- if (MOZ_LIKELY(!replace_malloc_table.name)) { \
- return je_ ## name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
- } else { \
- return replace_malloc_table.name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
- } \
+ return replace_malloc_table.name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
}
#define GENERIC_MALLOC_DECL(name, return_type, ...) \
GENERIC_MALLOC_DECL_HELPER(name, return, return_type, ##__VA_ARGS__)
#define GENERIC_MALLOC_DECL_VOID(name, ...) \
GENERIC_MALLOC_DECL_HELPER(name, , void, ##__VA_ARGS__)
#define MALLOC_DECL(...) MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (__VA_ARGS__))