diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-30 20:47:58 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-30 20:47:58 +0000 |
commit | de198d800b42218a424d44179ea2881d6dfbf975 (patch) | |
tree | 8c1de7020eb5a5d0df125ad4619255f41304d501 /src/or/buffers.c | |
parent | 364fd1ccdffe4a8f6c46137366e4c673b26b453c (diff) | |
download | tor-de198d800b42218a424d44179ea2881d6dfbf975.tar.gz tor-de198d800b42218a424d44179ea2881d6dfbf975.zip |
Never call free() on tor_malloc()d memory. This is unlikely to be our current leak, but it may help dmalloc work.
svn:r5168
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index a3b33a707b..e3b5c75ca2 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -83,14 +83,15 @@ buf_normalize(buf_t *buf) if (buf->cur + buf->datalen <= buf->mem+buf->len) { return; } else { - char *newmem; + char *newmem, *oldmem; size_t sz = (buf->mem+buf->len)-buf->cur; log_fn(LOG_WARN, "Unexpected non-normalized buffer."); newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(buf->len))); SET_GUARDS(newmem, buf->len); memcpy(newmem, buf->cur, sz); memcpy(newmem+sz, buf->mem, buf->datalen-sz); - free(RAW_MEM(buf->mem)); + oldmem = RAW_MEM(buf->mem); + tor_free(oldmem); /* Can't use tor_free directly. */ buf->mem = buf->cur = newmem; check(); } @@ -196,11 +197,11 @@ buf_resize(buf_t *buf, size_t new_capacity) !buf->datalen && buf->len >= 1<<16) { /* don't realloc; free and malloc */ - char *newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(new_capacity))); + char *oldmem, *newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(new_capacity))); SET_GUARDS(newmem, new_capacity); - free(RAW_MEM(buf->mem)); + oldmem = RAW_MEM(buf->mem); + tor_free(oldmem); buf->mem = buf->cur = newmem; - } else { buf->mem = GUARDED_MEM(tor_realloc(RAW_MEM(buf->mem), ALLOC_LEN(new_capacity))); @@ -371,9 +372,11 @@ _buf_peek_raw_buffer(const buf_t *buf) void buf_free(buf_t *buf) { + char *oldmem; assert_buf_ok(buf); buf->magic = 0xDEADBEEF; - free(RAW_MEM(buf->mem)); + oldmem = RAW_MEM(buf->mem); + tor_free(oldmem); buf_total_alloc -= buf->len; buf_total_used -= buf->datalen; tor_free(buf); |