diff options
author | Sebastian Hahn <sebastian@torproject.org> | 2009-09-28 16:37:01 +0200 |
---|---|---|
committer | Sebastian Hahn <sebastian@torproject.org> | 2009-12-12 03:29:44 +0100 |
commit | 3807db001d71c51e53c1897ae067671f5b771f2f (patch) | |
tree | 6c6f648f072d24e7bbf554de12519b27cd9ef888 /src/common | |
parent | 4afdb79051f7b1caba49877fb57be60bda9d4514 (diff) | |
download | tor-3807db001d71c51e53c1897ae067671f5b771f2f.tar tor-3807db001d71c51e53c1897ae067671f5b771f2f.tar.gz |
*_free functions now accept NULL
Some *_free functions threw asserts when passed NULL. Now all of them
accept NULL as input and perform no action when called that way.
This gains us consistence for our free functions, and allows some
code simplifications where an explicit null check is no longer necessary.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/aes.c | 3 | ||||
-rw-r--r-- | src/common/compat.c | 8 | ||||
-rw-r--r-- | src/common/container.c | 10 | ||||
-rw-r--r-- | src/common/crypto.c | 11 | ||||
-rw-r--r-- | src/common/log.c | 2 | ||||
-rw-r--r-- | src/common/memarea.c | 6 | ||||
-rw-r--r-- | src/common/torgzip.c | 3 | ||||
-rw-r--r-- | src/common/tortls.c | 4 |
8 files changed, 35 insertions, 12 deletions
diff --git a/src/common/aes.c b/src/common/aes.c index e07665635..451c31f02 100644 --- a/src/common/aes.c +++ b/src/common/aes.c @@ -263,7 +263,8 @@ aes_set_key(aes_cnt_cipher_t *cipher, const char *key, int key_bits) void aes_free_cipher(aes_cnt_cipher_t *cipher) { - tor_assert(cipher); + if (!cipher) + return; #ifdef USE_OPENSSL_EVP EVP_CIPHER_CTX_cleanup(&cipher->key); #endif diff --git a/src/common/compat.c b/src/common/compat.c index dbd3197a8..87dedc5b5 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -2044,6 +2044,8 @@ tor_mutex_new(void) void tor_mutex_free(tor_mutex_t *m) { + if (!m) + return; tor_mutex_uninit(m); tor_free(m); } @@ -2071,7 +2073,8 @@ tor_cond_new(void) void tor_cond_free(tor_cond_t *cond) { - tor_assert(cond); + if (!cond) + return; if (pthread_cond_destroy(&cond->cond)) { log_warn(LD_GENERAL,"Error freeing condition: %s", strerror(errno)); return; @@ -2128,7 +2131,8 @@ tor_cond_new(void) void tor_cond_free(tor_cond_t *cond) { - tor_assert(cond); + if (!cond) + return; DeleteCriticalSection(&cond->mutex); /* XXXX notify? */ smartlist_free(cond->events); diff --git a/src/common/container.c b/src/common/container.c index f3540f74d..7690b4c0b 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -44,7 +44,8 @@ smartlist_create(void) void smartlist_free(smartlist_t *sl) { - tor_assert(sl != NULL); + if (!sl) + return; tor_free(sl->list); tor_free(sl); } @@ -1187,6 +1188,9 @@ void strmap_free(strmap_t *map, void (*free_val)(void*)) { strmap_entry_t **ent, **next, *this; + if (!map) + return; + for (ent = HT_START(strmap_impl, &map->head); ent != NULL; ent = next) { this = *ent; next = HT_NEXT_RMV(strmap_impl, &map->head, ent); @@ -1208,6 +1212,8 @@ void digestmap_free(digestmap_t *map, void (*free_val)(void*)) { digestmap_entry_t **ent, **next, *this; + if (!map) + return; for (ent = HT_START(digestmap_impl, &map->head); ent != NULL; ent = next) { this = *ent; next = HT_NEXT_RMV(digestmap_impl, &map->head, ent); @@ -1323,6 +1329,8 @@ digestset_new(int max_elements) void digestset_free(digestset_t *set) { + if (!set) + return; bitarray_free(set->ba); tor_free(set); } diff --git a/src/common/crypto.c b/src/common/crypto.c index 4c880f6b6..4d17a8f21 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -400,7 +400,8 @@ crypto_new_pk_env(void) void crypto_free_pk_env(crypto_pk_env_t *env) { - tor_assert(env); + if (!env) + return; if (--env->refs > 0) return; @@ -463,7 +464,8 @@ crypto_new_cipher_env(void) void crypto_free_cipher_env(crypto_cipher_env_t *env) { - tor_assert(env); + if (!env) + return; tor_assert(env->cipher); aes_free_cipher(env->cipher); @@ -1528,6 +1530,8 @@ crypto_new_digest256_env(digest_algorithm_t algorithm) void crypto_free_digest_env(crypto_digest_env_t *digest) { + if (!digest) + return; memset(digest, 0, sizeof(crypto_digest_env_t)); tor_free(digest); } @@ -1899,7 +1903,8 @@ crypto_expand_key_material(const char *key_in, size_t key_in_len, void crypto_dh_free(crypto_dh_env_t *dh) { - tor_assert(dh); + if (!dh) + return; tor_assert(dh->dh); DH_free(dh->dh); tor_free(dh); diff --git a/src/common/log.c b/src/common/log.c index 9912080af..5b5b9e086 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -426,6 +426,8 @@ _log_err(log_domain_mask_t domain, const char *format, ...) static void log_free(logfile_t *victim) { + if (!victim) + return; tor_free(victim->severities); tor_free(victim->filename); tor_free(victim); diff --git a/src/common/memarea.c b/src/common/memarea.c index e7f672064..661bd85da 100644 --- a/src/common/memarea.c +++ b/src/common/memarea.c @@ -121,7 +121,7 @@ alloc_chunk(size_t sz, int freelist_ok) /** Release <b>chunk</b> from a memarea, either by adding it to the freelist * or by freeing it if the freelist is already too big. */ static void -chunk_free(memarea_chunk_t *chunk) +chunk_free_unchecked(memarea_chunk_t *chunk) { CHECK_SENTINEL(chunk); if (freelist_len < MAX_FREELIST_LEN) { @@ -151,7 +151,7 @@ memarea_drop_all(memarea_t *area) memarea_chunk_t *chunk, *next; for (chunk = area->first; chunk; chunk = next) { next = chunk->next_chunk; - chunk_free(chunk); + chunk_free_unchecked(chunk); } area->first = NULL; /*fail fast on */ tor_free(area); @@ -167,7 +167,7 @@ memarea_clear(memarea_t *area) if (area->first->next_chunk) { for (chunk = area->first->next_chunk; chunk; chunk = next) { next = chunk->next_chunk; - chunk_free(chunk); + chunk_free_unchecked(chunk); } area->first->next_chunk = NULL; } diff --git a/src/common/torgzip.c b/src/common/torgzip.c index 762f2e71b..13e0c7fb7 100644 --- a/src/common/torgzip.c +++ b/src/common/torgzip.c @@ -423,7 +423,8 @@ tor_zlib_process(tor_zlib_state_t *state, void tor_zlib_free(tor_zlib_state_t *state) { - tor_assert(state); + if (!state) + return; if (state->compress) deflateEnd(&state->stream); diff --git a/src/common/tortls.c b/src/common/tortls.c index 71d0bd6be..0fde61771 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -986,7 +986,9 @@ void tor_tls_free(tor_tls_t *tls) { tor_tls_t *removed; - tor_assert(tls && tls->ssl); + if (!tls) + return; + tor_assert(tls->ssl); removed = HT_REMOVE(tlsmap, &tlsmap_root, tls); if (!removed) { log_warn(LD_BUG, "Freeing a TLS that was not in the ssl->tls map."); |