From b1cc3eb32321639d56d7dbbe338e40347fe0e89b Mon Sep 17 00:00:00 2001 From: Adam Borowski Date: Tue, 25 Aug 2020 12:01:18 +0200 Subject: [PATCH] Drop unused Malloc redirection. In the only place where we actually do redirect malloc, it's done a different way. Thus, this piece of code merely complicates analysis, and makes the speed (negligibly) slower. I'm leaving it as #defines, in case we'd want to redirect in the future. --- src/util.c | 23 ----------------------- src/util.h | 19 ++++--------------- 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/util.c b/src/util.c index 2bec3e83..ab3117f3 100644 --- a/src/util.c +++ b/src/util.c @@ -52,14 +52,6 @@ unsigned long long Pagesize; /* allocation/mmap granularity */ unsigned long long Mmap_align; -/* - * our versions of malloc & friends start off pointing to the libc versions - */ -Malloc_func Malloc = malloc; -Free_func Free = free; -Realloc_func Realloc = realloc; -Strdup_func Strdup = strdup; - /* * Zalloc -- allocate zeroed memory */ @@ -224,21 +216,6 @@ util_checksum_seq(const void *addr, size_t len, uint64_t csum) return (uint64_t)hi32 << 32 | lo32; } -/* - * util_set_alloc_funcs -- allow one to override malloc, etc. - */ -void -util_set_alloc_funcs(void *(*malloc_func)(size_t size), - void (*free_func)(void *ptr), - void *(*realloc_func)(void *ptr, size_t size), - char *(*strdup_func)(const char *s)) -{ - Malloc = (malloc_func == NULL) ? malloc : malloc_func; - Free = (free_func == NULL) ? free : free_func; - Realloc = (realloc_func == NULL) ? realloc : realloc_func; - Strdup = (strdup_func == NULL) ? strdup : strdup_func; -} - /* * util_fgets -- fgets wrapper with conversion CRLF to LF */ diff --git a/src/util.h b/src/util.h index 3789830a..32d8dac0 100644 --- a/src/util.h +++ b/src/util.h @@ -76,15 +76,10 @@ extern unsigned long long Mmap_align; /* * overridable names for malloc & friends used by this library */ -typedef void *(*Malloc_func)(size_t size); -typedef void (*Free_func)(void *ptr); -typedef void *(*Realloc_func)(void *ptr, size_t size); -typedef char *(*Strdup_func)(const char *s); - -extern Malloc_func Malloc; -extern Free_func Free; -extern Realloc_func Realloc; -extern Strdup_func Strdup; +#define Malloc malloc +#define Free free +#define Realloc realloc +#define Strdup strdup extern void *Zalloc(size_t sz); void util_init(void); @@ -118,12 +113,6 @@ int util_toUTF8_buff(const wchar_t *in, char *out, size_t out_size); #define UTIL_MAX_ERR_MSG 128 void util_strerror(int errnum, char *buff, size_t bufflen); -void util_set_alloc_funcs( - void *(*malloc_func)(size_t size), - void (*free_func)(void *ptr), - void *(*realloc_func)(void *ptr, size_t size), - char *(*strdup_func)(const char *s)); - /* * Macro calculates number of elements in given table */