diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-03-03 22:49:15 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-03-03 22:49:15 +0000 |
commit | b7633e2e67c66fd33f16918070f9565d4fa03c35 (patch) | |
tree | 60acf700673695539b507180cdffc10869cd6d71 /src/or/buffers.c | |
parent | 3e452fed5446f3e744bf7ea321f6b24e01c97578 (diff) | |
download | tor-b7633e2e67c66fd33f16918070f9565d4fa03c35.tar.gz tor-b7633e2e67c66fd33f16918070f9565d4fa03c35.zip |
Try to find out early if buffers get trashed or double-freed.
svn:r1225
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 40d6b04d87..d4c3dd7875 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -6,7 +6,9 @@ #include "or.h" +#define BUFFER_MAGIC 0xB0FFF312u struct buf_t { + uint32_t magic; /* for debugging */ char *mem; size_t len; size_t datalen; @@ -118,6 +120,7 @@ int find_on_inbuf(char *string, int string_len, buf_t *buf) { buf_t *buf_new_with_capacity(size_t size) { buf_t *buf; buf = (buf_t*)tor_malloc(sizeof(buf_t)); + buf->magic = BUFFER_MAGIC; buf->mem = (char *)tor_malloc(size); buf->len = size; buf->datalen = 0; @@ -153,9 +156,10 @@ const char *_buf_peek_raw_buffer(const buf_t *buf) } void buf_free(buf_t *buf) { - assert(buf && buf->mem); - free(buf->mem); - free(buf); + assert_buf_ok(buf); + buf->magic = 0xDEADBEEF; + tor_free(buf->mem); + tor_free(buf); } /* read from socket s, writing onto end of buf. @@ -576,6 +580,14 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { } } +void assert_buf_ok(buf_t *buf) +{ + assert(buf); + assert(buf->magic == BUFFER_MAGIC); + assert(buf->mem); + assert(buf->datalen <= buf->len); +} + /* Local Variables: mode:c |