summaryrefslogtreecommitdiff
path: root/src/or/buffers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-01-12 12:26:45 -0500
committerNick Mathewson <nickm@torproject.org>2014-02-12 12:38:20 -0500
commitfd28754dd3dce0e00304825d531348414c0a354b (patch)
tree1b03a3d937444aa16732fdb8d6f9266706c6bd10 /src/or/buffers.c
parent79515917449c7e0d92f16db0d1e5af4a0370bbab (diff)
downloadtor-fd28754dd3dce0e00304825d531348414c0a354b.tar.gz
tor-fd28754dd3dce0e00304825d531348414c0a354b.zip
Actually release buffer freelists when handling OOM conditions.
Otherwise freeing buffers won't help for a little while.
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r--src/or/buffers.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 856c9b6060..352e60a979 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -276,12 +276,14 @@ preferred_chunk_size(size_t target)
}
/** Remove from the freelists most chunks that have not been used since the
- * last call to buf_shrink_freelists(). */
-void
+ * last call to buf_shrink_freelists(). Return the amount of memory
+ * freed. */
+size_t
buf_shrink_freelists(int free_all)
{
#ifdef ENABLE_BUF_FREELISTS
int i;
+ size_t total_freed = 0;
disable_control_logging();
for (i = 0; freelists[i].alloc_size; ++i) {
int slack = freelists[i].slack;
@@ -315,6 +317,7 @@ buf_shrink_freelists(int free_all)
chunk_t *next = chunk->next;
tor_assert(total_bytes_allocated_in_chunks >= CHUNK_ALLOC_SIZE(chunk->memlen));
total_bytes_allocated_in_chunks -= CHUNK_ALLOC_SIZE(chunk->memlen);
+ total_freed += CHUNK_ALLOC_SIZE(chunk->memlen);
tor_free(chunk);
chunk = next;
--n_to_free;
@@ -343,8 +346,10 @@ buf_shrink_freelists(int free_all)
}
done:
enable_control_logging();
+ return total_freed;
#else
(void) free_all;
+ return 0;
#endif
}