diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-01-03 13:56:46 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-02-12 12:37:41 -0500 |
commit | 79515917449c7e0d92f16db0d1e5af4a0370bbab (patch) | |
tree | fc2417cba34c41bf7e620eac38afe75003d22529 /src | |
parent | 647248729fa65f0e51d062e2af8f4e8b38592bf5 (diff) | |
download | tor-79515917449c7e0d92f16db0d1e5af4a0370bbab.tar.gz tor-79515917449c7e0d92f16db0d1e5af4a0370bbab.zip |
Fix bugs in bug10169 bugfix memory tracking
The chunk_grow() and chunk_copy() functions weren't adjusting the
memory totals properly.
Bugfix not on any released Tor version.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/buffers.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 71b61b1890..856c9b6060 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -245,12 +245,13 @@ static INLINE chunk_t * chunk_grow(chunk_t *chunk, size_t sz) { off_t offset; + size_t memlen_orig = chunk->memlen; tor_assert(sz > chunk->memlen); offset = chunk->data - chunk->mem; chunk = tor_realloc(chunk, CHUNK_ALLOC_SIZE(sz)); chunk->memlen = sz; chunk->data = chunk->mem + offset; - total_bytes_allocated_in_chunks += (sz - chunk->memlen); + total_bytes_allocated_in_chunks += CHUNK_ALLOC_SIZE(sz) - CHUNK_ALLOC_SIZE(memlen_orig); return chunk; } @@ -331,10 +332,11 @@ buf_shrink_freelists(int free_all) } // tor_assert(!n_to_free); freelists[i].cur_length = new_length; + tor_assert(orig_n_to_skip == new_length); log_info(LD_MM, "Cleaned freelist for %d-byte chunks: original " - "length %d, kept %d, dropped %d.", + "length %d, kept %d, dropped %d. New length is %d", (int)freelists[i].alloc_size, orig_length, - orig_n_to_skip, orig_n_to_free); + orig_n_to_skip, orig_n_to_free, new_length); } freelists[i].lowest_length = freelists[i].cur_length; assert_freelist_ok(&freelists[i]); @@ -580,6 +582,7 @@ static chunk_t * chunk_copy(const chunk_t *in_chunk) { chunk_t *newch = tor_memdup(in_chunk, CHUNK_ALLOC_SIZE(in_chunk->memlen)); + total_bytes_allocated_in_chunks += CHUNK_ALLOC_SIZE(in_chunk->memlen); newch->next = NULL; if (in_chunk->data) { off_t offset = in_chunk->data - in_chunk->mem; |