From 0a74421157a410df80298b140936fe96e59e8e9d Mon Sep 17 00:00:00 2001 From: Scott Zager Date: Sat, 18 Jul 2026 19:57:19 -0400 Subject: [PATCH] fix: check realloc return value in generateAircraftJson If realloc fails due to OOM, the code would dereference NULL. Now saves the old buffer pointer and frees it on failure, returning NULL to the caller. Fixes #305 --- net_io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net_io.c b/net_io.c index 8abd51086..92a119263 100644 --- a/net_io.c +++ b/net_io.c @@ -1862,8 +1862,15 @@ char *generateAircraftJson(const char *url_path, int *len) { if ((p + 10) >= end) { // +10 to leave some space for the final line // overran the buffer int used = line_start - buf; + char *newbuf; buflen *= 2; - buf = (char *) realloc(buf, buflen); + newbuf = (char *) realloc(buf, buflen); + if (!newbuf) { + free(buf); + *len = 0; + return NULL; + } + buf = newbuf; p = buf+used; end = buf + buflen; goto retry;