From 031decbb82f34313a2403e8852ce630b573eb177 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 10 Sep 2023 11:50:45 -0400 Subject: Fix potential realloc leaks --- src/writer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 07edc7f4..2a6d7c31 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1266,9 +1266,12 @@ size_t serd_chunk_sink(const void* buf, size_t len, void* stream) { SerdChunk* chunk = (SerdChunk*)stream; - chunk->buf = (uint8_t*)realloc((uint8_t*)chunk->buf, chunk->len + len); - memcpy((uint8_t*)chunk->buf + chunk->len, buf, len); - chunk->len += len; + uint8_t* new_buf = (uint8_t*)realloc((uint8_t*)chunk->buf, chunk->len + len); + if (new_buf) { + memcpy(new_buf + chunk->len, buf, len); + chunk->buf = new_buf; + chunk->len += len; + } return len; } -- cgit v1.2.1