diff options
author | June McEnroe <june@causal.agency> | 2019-10-30 22:51:38 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-10-30 22:51:38 -0400 |
commit | b45dc512186c922ddd359508dcef96b25a62620f (patch) | |
tree | 1261ef5e9c16df8abe2f081a23747238fe3dc82d | |
parent | Add option for ring size (diff) | |
download | pounce-b45dc512186c922ddd359508dcef96b25a62620f.tar.gz pounce-b45dc512186c922ddd359508dcef96b25a62620f.zip |
Preserve consumers ptr in realloc failure
-rw-r--r-- | ring.c | 6 |
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]; |