summaryrefslogtreecommitdiff
path: root/src/or/buffers.c
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2009-09-28 16:37:01 +0200
committerSebastian Hahn <sebastian@torproject.org>2009-12-12 03:29:44 +0100
commit3807db001d71c51e53c1897ae067671f5b771f2f (patch)
tree6c6f648f072d24e7bbf554de12519b27cd9ef888 /src/or/buffers.c
parent4afdb79051f7b1caba49877fb57be60bda9d4514 (diff)
downloadtor-3807db001d71c51e53c1897ae067671f5b771f2f.tar.gz
tor-3807db001d71c51e53c1897ae067671f5b771f2f.zip
*_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/or/buffers.c')
-rw-r--r--src/or/buffers.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 1a1b2077cc..7c40e47cca 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -147,10 +147,13 @@ get_freelist(size_t alloc)
/** Deallocate a chunk or put it on a freelist */
static void
-chunk_free(chunk_t *chunk)
+chunk_free_unchecked(chunk_t *chunk)
{
- size_t alloc = CHUNK_ALLOC_SIZE(chunk->memlen);
- chunk_freelist_t *freelist = get_freelist(alloc);
+ size_t alloc;
+ chunk_freelist_t *freelist;
+
+ alloc = CHUNK_ALLOC_SIZE(chunk->memlen);
+ freelist = get_freelist(alloc);
if (freelist && freelist->cur_length < freelist->max_length) {
chunk->next = freelist->head;
freelist->head = chunk;
@@ -195,7 +198,7 @@ chunk_new_with_alloc_size(size_t alloc)
}
#else
static void
-chunk_free(chunk_t *chunk)
+chunk_free_unchecked(chunk_t *chunk)
{
tor_free(chunk);
}
@@ -403,7 +406,7 @@ buf_pullup(buf_t *buf, size_t bytes, int nulterminate)
dest->next = src->next;
if (buf->tail == src)
buf->tail = dest;
- chunk_free(src);
+ chunk_free_unchecked(src);
} else {
memcpy(CHUNK_WRITE_PTR(dest), src->data, n);
dest->datalen += n;
@@ -449,7 +452,7 @@ buf_remove_from_front(buf_t *buf, size_t n)
buf->head = victim->next;
if (buf->tail == victim)
buf->tail = NULL;
- chunk_free(victim);
+ chunk_free_unchecked(victim);
}
}
check();
@@ -483,7 +486,7 @@ buf_clear(buf_t *buf)
buf->datalen = 0;
for (chunk = buf->head; chunk; chunk = next) {
next = chunk->next;
- chunk_free(chunk);
+ chunk_free_unchecked(chunk);
}
buf->head = buf->tail = NULL;
}
@@ -522,6 +525,8 @@ buf_slack(const buf_t *buf)
void
buf_free(buf_t *buf)
{
+ if (!buf)
+ return;
buf_clear(buf);
buf->magic = 0xdeadbeef;
tor_free(buf);