summary refs log tree commit diff
path: root/bin/edi
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-11-21 17:46:47 -0500
committerJune McEnroe <june@causal.agency>2018-11-21 17:47:42 -0500
commitc66387f23f50bf803f75892b01d73465230ce0dd (patch)
tree232c8b74a13da6e8a680bec6947ad8bce7182080 /bin/edi
parentTrack hot slice in tables (diff)
downloadsrc-c66387f23f50bf803f75892b01d73465230ce0dd.tar.gz
src-c66387f23f50bf803f75892b01d73465230ce0dd.zip
Free buffer block if empty when allocating new block
Diffstat (limited to '')
-rw-r--r--bin/edi/buffer.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/bin/edi/buffer.c b/bin/edi/buffer.c
index 5ece2e51..e15ae20d 100644
--- a/bin/edi/buffer.c
+++ b/bin/edi/buffer.c
@@ -74,6 +74,10 @@ void bufferDelete(struct Buffer *buf) {
 
 wchar_t *bufferDest(struct Buffer *buf, size_t len) {
 	if (buf->len + len > buf->cap) {
+		if (!buf->len) {
+			buf->block = buf->block->prev;
+			free(buf->block);
+		}
 		while (len > buf->cap) buf->cap *= 2;
 		buf->block = blockAlloc(buf->block, buf->cap);
 		buf->len = 0;