summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-30 22:51:38 -0400
committerJune McEnroe <june@causal.agency>2019-10-30 22:51:38 -0400
commitb45dc512186c922ddd359508dcef96b25a62620f (patch)
tree1261ef5e9c16df8abe2f081a23747238fe3dc82d
parentAdd option for ring size (diff)
downloadpounce-b45dc512186c922ddd359508dcef96b25a62620f.tar.gz
pounce-b45dc512186c922ddd359508dcef96b25a62620f.zip
Preserve consumers ptr in realloc failure
-rw-r--r--ring.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ring.c b/ring.c
index 620f490..5fb9daa 100644
--- a/ring.c
+++ b/ring.c
@@ -67,11 +67,11 @@ size_t ringConsumer(const char *name) {
 
 	if (consumers.len == consumers.cap) {
 		consumers.cap = (consumers.cap ? consumers.cap * 2 : 8);
-		// FIXME: Keep old pointer around for saving when exiting for error.
-		consumers.ptr = realloc(
+		void *ptr = realloc(
 			consumers.ptr, sizeof(*consumers.ptr) * consumers.cap
 		);
-		if (!consumers.ptr) err(EX_OSERR, "realloc");
+		if (!ptr) err(EX_OSERR, "realloc");
+		consumers.ptr = ptr;
 	}
 
 	struct Consumer *consumer = &consumers.ptr[consumers.len];