diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-09-19 22:36:48 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-09-19 22:36:48 +0000 |
commit | 2d4950c8373676b9b5ae0a3c8013e780b5c18e19 (patch) | |
tree | 88a609b1bd0590b32168a6d503aea7c5e4c8a838 /src | |
parent | 7b0ec744bc8afa691873f97cfb6a3b7822376d7b (diff) | |
download | tor-2d4950c8373676b9b5ae0a3c8013e780b5c18e19.tar.gz tor-2d4950c8373676b9b5ae0a3c8013e780b5c18e19.zip |
Malloc and friends are critical-path: Thus, add an it-wont-happen branch prediction for NULL returns, and skip the malloc(0) check on platforms where malloc(0) returns a pointer.
svn:r8431
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/common/util.c b/src/common/util.c index 264bd0b74f..d4a939b14f 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -106,13 +106,15 @@ _tor_malloc(size_t size DMALLOC_PARAMS) { void *result; +#ifndef MALLOC_ZERO_WORKS /* Some libcs don't do the right thing on size==0. Override them. */ if (size==0) { size=1; } +#endif result = dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0); - if (!result) { + if (PREDICT(result == NULL, 0)) { log_err(LD_MM,"Out of memory. Dying."); /* If these functions die within a worker process, they won't call * spawn_exit, but that's ok, since the parent will run out of memory soon @@ -144,7 +146,7 @@ _tor_realloc(void *ptr, size_t size DMALLOC_PARAMS) void *result; result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0); - if (!result) { + if (PREDICT(result == NULL, 0)) { log_err(LD_MM,"Out of memory. Dying."); exit(1); } @@ -162,7 +164,7 @@ _tor_strdup(const char *s DMALLOC_PARAMS) tor_assert(s); dup = dmalloc_strdup(file, line, s, 0); - if (!dup) { + if (PREDICT(dup == NULL, 0)) { log_err(LD_MM,"Out of memory. Dying."); exit(1); } |