diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-20 10:19:56 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-20 10:21:34 -0400 |
commit | 9fa73003fca5e884c0c663c2035ce6e60994c339 (patch) | |
tree | 4bebae718e21b5ded3eaddb8f673998b0e09c25c /src/common | |
parent | e4e949e901400c8516a2db8d2fd508b1e7bb842e (diff) | |
download | tor-9fa73003fca5e884c0c663c2035ce6e60994c339.tar.gz tor-9fa73003fca5e884c0c663c2035ce6e60994c339.zip |
Remove dmalloc support; closes #26426
Dmalloc hasn't seen a release in over a decade, and there are much
better tools to use these days.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 13 | ||||
-rw-r--r-- | src/common/crypto.h | 4 | ||||
-rw-r--r-- | src/common/util.c | 73 | ||||
-rw-r--r-- | src/common/util.h | 61 |
4 files changed, 34 insertions, 117 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 14129086eb..57eb9c64c9 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -506,16 +506,3 @@ crypto_global_cleanup(void) } /** @} */ - -#ifdef USE_DMALLOC -/** Tell the crypto library to use Tor's allocation functions rather than - * calling libc's allocation functions directly. Return 0 on success, -1 - * on failure. */ -int -crypto_use_tor_alloc_functions(void) -{ - int r = CRYPTO_set_mem_ex_functions(tor_malloc_, tor_realloc_, tor_free_); - return r ? 0 : -1; -} -#endif /* defined(USE_DMALLOC) */ - diff --git a/src/common/crypto.h b/src/common/crypto.h index 1a88a3d2f6..e7d86eaf01 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -40,9 +40,6 @@ int crypto_early_init(void) ATTR_WUR; int crypto_global_init(int hardwareAccel, const char *accelName, const char *accelPath) ATTR_WUR; -#ifdef USE_DMALLOC -int crypto_use_tor_alloc_functions(void); -#endif void crypto_thread_cleanup(void); int crypto_global_cleanup(void); @@ -77,4 +74,3 @@ int crypto_cipher_decrypt_with_iv(const char *key, void crypto_add_spaces_to_fp(char *out, size_t outlen, const char *in); #endif /* !defined(TOR_CRYPTO_H) */ - diff --git a/src/common/util.c b/src/common/util.c index b3fdc8a43a..5bf70c6b5d 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -103,35 +103,13 @@ /* ===== * Memory management * ===== */ -#ifdef USE_DMALLOC - #undef strndup - #include <dmalloc.h> - /* Macro to pass the extra dmalloc args to another function. */ - #define DMALLOC_FN_ARGS , file, line - - #if defined(HAVE_DMALLOC_STRDUP) - /* the dmalloc_strdup should be fine as defined */ - #elif defined(HAVE_DMALLOC_STRNDUP) - #define dmalloc_strdup(file, line, string, xalloc_b) \ - dmalloc_strndup(file, line, (string), -1, xalloc_b) - #else - #error "No dmalloc_strdup or equivalent" -#endif /* defined(HAVE_DMALLOC_STRDUP) || ... */ - -#else /* !(defined(USE_DMALLOC)) */ - - #define DMALLOC_FN_ARGS -#endif /* defined(USE_DMALLOC) */ /** Allocate a chunk of <b>size</b> bytes of memory, and return a pointer to * result. On error, log and terminate the process. (Same as malloc(size), * but never returns NULL.) - * - * <b>file</b> and <b>line</b> are used if dmalloc is enabled, and - * ignored otherwise. */ void * -tor_malloc_(size_t size DMALLOC_PARAMS) +tor_malloc_(size_t size) { void *result; @@ -144,11 +122,7 @@ tor_malloc_(size_t size DMALLOC_PARAMS) } #endif /* !defined(MALLOC_ZERO_WORKS) */ -#ifdef USE_DMALLOC - result = dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0); -#else result = raw_malloc(size); -#endif if (PREDICT_UNLIKELY(result == NULL)) { /* LCOV_EXCL_START */ @@ -167,7 +141,7 @@ tor_malloc_(size_t size DMALLOC_PARAMS) * the process on error. (Same as calloc(size,1), but never returns NULL.) */ void * -tor_malloc_zero_(size_t size DMALLOC_PARAMS) +tor_malloc_zero_(size_t size) { /* You may ask yourself, "wouldn't it be smart to use calloc instead of * malloc+memset? Perhaps libc's calloc knows some nifty optimization trick @@ -175,7 +149,7 @@ tor_malloc_zero_(size_t size DMALLOC_PARAMS) * we're allocating something very big (it knows if it just got the memory * from the OS in a pre-zeroed state). We don't want to use tor_malloc_zero * for big stuff, so we don't bother with calloc. */ - void *result = tor_malloc_(size DMALLOC_FN_ARGS); + void *result = tor_malloc_(size); memset(result, 0, size); return result; } @@ -211,10 +185,10 @@ size_mul_check(const size_t x, const size_t y) * and a compile-time constant. */ void * -tor_calloc_(size_t nmemb, size_t size DMALLOC_PARAMS) +tor_calloc_(size_t nmemb, size_t size) { tor_assert(size_mul_check(nmemb, size)); - return tor_malloc_zero_((nmemb * size) DMALLOC_FN_ARGS); + return tor_malloc_zero_((nmemb * size)); } /** Change the size of the memory block pointed to by <b>ptr</b> to <b>size</b> @@ -222,7 +196,7 @@ tor_calloc_(size_t nmemb, size_t size DMALLOC_PARAMS) * terminate. (Like realloc(ptr,size), but never returns NULL.) */ void * -tor_realloc_(void *ptr, size_t size DMALLOC_PARAMS) +tor_realloc_(void *ptr, size_t size) { void *result; @@ -235,11 +209,7 @@ tor_realloc_(void *ptr, size_t size DMALLOC_PARAMS) } #endif /* !defined(MALLOC_ZERO_WORKS) */ -#ifdef USE_DMALLOC - result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0); -#else result = raw_realloc(ptr, size); -#endif if (PREDICT_UNLIKELY(result == NULL)) { /* LCOV_EXCL_START */ @@ -255,13 +225,13 @@ tor_realloc_(void *ptr, size_t size DMALLOC_PARAMS) * overflow. Unlike other allocation functions, return NULL on overflow. */ void * -tor_reallocarray_(void *ptr, size_t sz1, size_t sz2 DMALLOC_PARAMS) +tor_reallocarray_(void *ptr, size_t sz1, size_t sz2) { /* XXXX we can make this return 0, but we would need to check all the * reallocarray users. */ tor_assert(size_mul_check(sz1, sz2)); - return tor_realloc(ptr, (sz1 * sz2) DMALLOC_FN_ARGS); + return tor_realloc(ptr, (sz1 * sz2)); } /** Return a newly allocated copy of the NUL-terminated string s. On @@ -269,16 +239,13 @@ tor_reallocarray_(void *ptr, size_t sz1, size_t sz2 DMALLOC_PARAMS) * NULL.) */ char * -tor_strdup_(const char *s DMALLOC_PARAMS) +tor_strdup_(const char *s) { char *duplicate; tor_assert(s); -#ifdef USE_DMALLOC - duplicate = dmalloc_strdup(file, line, s, 0); -#else duplicate = raw_strdup(s); -#endif + if (PREDICT_UNLIKELY(duplicate == NULL)) { /* LCOV_EXCL_START */ log_err(LD_MM,"Out of memory on strdup(). Dying."); @@ -295,12 +262,12 @@ tor_strdup_(const char *s DMALLOC_PARAMS) * NULL.) */ char * -tor_strndup_(const char *s, size_t n DMALLOC_PARAMS) +tor_strndup_(const char *s, size_t n) { char *duplicate; tor_assert(s); tor_assert(n < SIZE_T_CEILING); - duplicate = tor_malloc_((n+1) DMALLOC_FN_ARGS); + duplicate = tor_malloc_((n+1)); /* Performance note: Ordinarily we prefer strlcpy to strncpy. But * this function gets called a whole lot, and platform strncpy is * much faster than strlcpy when strlen(s) is much longer than n. @@ -313,12 +280,12 @@ tor_strndup_(const char *s, size_t n DMALLOC_PARAMS) /** Allocate a chunk of <b>len</b> bytes, with the same contents as the * <b>len</b> bytes starting at <b>mem</b>. */ void * -tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS) +tor_memdup_(const void *mem, size_t len) { char *duplicate; tor_assert(len < SIZE_T_CEILING); tor_assert(mem); - duplicate = tor_malloc_(len DMALLOC_FN_ARGS); + duplicate = tor_malloc_(len); memcpy(duplicate, mem, len); return duplicate; } @@ -326,12 +293,12 @@ tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS) /** As tor_memdup(), but add an extra 0 byte at the end of the resulting * memory. */ void * -tor_memdup_nulterm_(const void *mem, size_t len DMALLOC_PARAMS) +tor_memdup_nulterm_(const void *mem, size_t len) { char *duplicate; tor_assert(len < SIZE_T_CEILING+1); tor_assert(mem); - duplicate = tor_malloc_(len+1 DMALLOC_FN_ARGS); + duplicate = tor_malloc_(len+1); memcpy(duplicate, mem, len); duplicate[len] = '\0'; return duplicate; @@ -365,13 +332,6 @@ tor_log_mallinfo(int severity) #else /* !(defined(HAVE_MALLINFO)) */ (void)severity; #endif /* defined(HAVE_MALLINFO) */ -#ifdef USE_DMALLOC - dmalloc_log_changed(0, /* Since the program started. */ - 1, /* Log info about non-freed pointers. */ - 0, /* Do not log info about freed pointers. */ - 0 /* Do not log individual pointers. */ - ); -#endif /* defined(USE_DMALLOC) */ } ENABLE_GCC_WARNING(aggregate-return) @@ -5375,4 +5335,3 @@ tor_ntohll(uint64_t a) { return tor_htonll(a); } - diff --git a/src/common/util.h b/src/common/util.h index dcfa55f8fe..7921357ac5 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -34,45 +34,22 @@ #define O_NOFOLLOW 0 #endif -/* If we're building with dmalloc, we want all of our memory allocation - * functions to take an extra file/line pair of arguments. If not, not. - * We define DMALLOC_PARAMS to the extra parameters to insert in the - * function prototypes, and DMALLOC_ARGS to the extra arguments to add - * to calls. */ -#ifdef USE_DMALLOC -#define DMALLOC_PARAMS , const char *file, const int line -#define DMALLOC_ARGS , SHORT_FILE__, __LINE__ -#else -#define DMALLOC_PARAMS -#define DMALLOC_ARGS -#endif /* defined(USE_DMALLOC) */ - /* Memory management */ -void *tor_malloc_(size_t size DMALLOC_PARAMS) ATTR_MALLOC; -void *tor_malloc_zero_(size_t size DMALLOC_PARAMS) ATTR_MALLOC; -void *tor_calloc_(size_t nmemb, size_t size DMALLOC_PARAMS) ATTR_MALLOC; -void *tor_realloc_(void *ptr, size_t size DMALLOC_PARAMS); -void *tor_reallocarray_(void *ptr, size_t size1, size_t size2 DMALLOC_PARAMS); -char *tor_strdup_(const char *s DMALLOC_PARAMS) ATTR_MALLOC ATTR_NONNULL((1)); -char *tor_strndup_(const char *s, size_t n DMALLOC_PARAMS) +void *tor_malloc_(size_t size) ATTR_MALLOC; +void *tor_malloc_zero_(size_t size) ATTR_MALLOC; +void *tor_calloc_(size_t nmemb, size_t size) ATTR_MALLOC; +void *tor_realloc_(void *ptr, size_t size); +void *tor_reallocarray_(void *ptr, size_t size1, size_t size2); +char *tor_strdup_(const char *s) ATTR_MALLOC ATTR_NONNULL((1)); +char *tor_strndup_(const char *s, size_t n) ATTR_MALLOC ATTR_NONNULL((1)); -void *tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS) +void *tor_memdup_(const void *mem, size_t len) ATTR_MALLOC ATTR_NONNULL((1)); -void *tor_memdup_nulterm_(const void *mem, size_t len DMALLOC_PARAMS) +void *tor_memdup_nulterm_(const void *mem, size_t len) ATTR_MALLOC ATTR_NONNULL((1)); void tor_free_(void *mem); uint64_t tor_htonll(uint64_t a); uint64_t tor_ntohll(uint64_t a); -#ifdef USE_DMALLOC -extern int dmalloc_free(const char *file, const int line, void *pnt, - const int func_id); -#define tor_free(p) STMT_BEGIN \ - if (PREDICT_LIKELY((p)!=NULL)) { \ - dmalloc_free(SHORT_FILE__, __LINE__, (p), 0); \ - (p)=NULL; \ - } \ - STMT_END -#else /* !(defined(USE_DMALLOC)) */ /** Release memory allocated by tor_malloc, tor_realloc, tor_strdup, * etc. Unlike the free() function, the tor_free() macro sets the * pointer value to NULL after freeing it. @@ -97,18 +74,17 @@ extern int dmalloc_free(const char *file, const int line, void *pnt, (p)=NULL; \ STMT_END #endif -#endif /* defined(USE_DMALLOC) */ -#define tor_malloc(size) tor_malloc_(size DMALLOC_ARGS) -#define tor_malloc_zero(size) tor_malloc_zero_(size DMALLOC_ARGS) -#define tor_calloc(nmemb,size) tor_calloc_(nmemb, size DMALLOC_ARGS) -#define tor_realloc(ptr, size) tor_realloc_(ptr, size DMALLOC_ARGS) +#define tor_malloc(size) tor_malloc_(size) +#define tor_malloc_zero(size) tor_malloc_zero_(size) +#define tor_calloc(nmemb,size) tor_calloc_(nmemb, size) +#define tor_realloc(ptr, size) tor_realloc_(ptr, size) #define tor_reallocarray(ptr, sz1, sz2) \ - tor_reallocarray_((ptr), (sz1), (sz2) DMALLOC_ARGS) -#define tor_strdup(s) tor_strdup_(s DMALLOC_ARGS) -#define tor_strndup(s, n) tor_strndup_(s, n DMALLOC_ARGS) -#define tor_memdup(s, n) tor_memdup_(s, n DMALLOC_ARGS) -#define tor_memdup_nulterm(s, n) tor_memdup_nulterm_(s, n DMALLOC_ARGS) + tor_reallocarray_((ptr), (sz1), (sz2)) +#define tor_strdup(s) tor_strdup_(s) +#define tor_strndup(s, n) tor_strndup_(s, n) +#define tor_memdup(s, n) tor_memdup_(s, n) +#define tor_memdup_nulterm(s, n) tor_memdup_nulterm_(s, n) /* Aliases for the underlying system malloc/realloc/free. Only use * them to indicate "I really want the underlying system function, I know @@ -569,4 +545,3 @@ int size_mul_check(const size_t x, const size_t y); #define ARRAY_LENGTH(x) ((sizeof(x)) / sizeof(x[0])) #endif /* !defined(TOR_UTIL_H) */ - |