Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Drop unused Malloc redirection.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kilobyte committed Aug 25, 2020
1 parent 5bd6294 commit b1cc3eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
23 changes: 0 additions & 23 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
19 changes: 4 additions & 15 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit b1cc3eb

Please sign in to comment.