From aaf73d10199c268e864f1e223bc7d74e0b7371dc Mon Sep 17 00:00:00 2001 From: Rigo Mate Date: Sat, 16 Nov 2024 18:01:06 +0100 Subject: [PATCH 1/2] fix memory leaks --- src/json_helper.c | 5 ++++- src/tonie_audio_playlist.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/json_helper.c b/src/json_helper.c index 0aad41f6..8358d76d 100644 --- a/src/json_helper.c +++ b/src/json_helper.c @@ -53,7 +53,10 @@ cJSON *jsonAddByteArrayToObject(cJSON *const object, const char *const name, uin sprintf(&string[i * 2], "%02hhx", bytes[i]); } - return cJSON_AddStringToObject(object, name, string); + // temporary object is needed, so we can free string, because of lack of RAII + cJSON *tmpObject = cJSON_AddStringToObject(object, name, string); + osFreeMem(string); + return tmpObject; } bool_t jsonGetBool(cJSON *jsonElement, char *name) diff --git a/src/tonie_audio_playlist.c b/src/tonie_audio_playlist.c index 59cee21a..f2be7f21 100644 --- a/src/tonie_audio_playlist.c +++ b/src/tonie_audio_playlist.c @@ -189,6 +189,8 @@ error_t tap_generate_taf(tonie_audio_playlist_t *tap, size_t *current_source, bo char source[99][PATH_LEN]; if (tap->filesCount == 0) { + osFreeMem(tmp_taf); + freeTonieInfo(tonieInfo); return ERROR_INVALID_FILE; } From 62661a5de9dc61d057af22797f8f0e18d6055539 Mon Sep 17 00:00:00 2001 From: Rigo Mate Date: Sun, 17 Nov 2024 00:05:05 +0100 Subject: [PATCH 2/2] fix 2 more leaks --- src/handler_api.c | 2 ++ src/main.c | 1 + 2 files changed, 3 insertions(+) diff --git a/src/handler_api.c b/src/handler_api.c index ffab5cd2..3a341f5d 100644 --- a/src/handler_api.c +++ b/src/handler_api.c @@ -739,6 +739,7 @@ error_t handleApiFileIndex(HttpConnection *connection, const char_t *uri, const if (queryPrepare(queryString, &rootPath, overlay, sizeof(overlay), &client_ctx->settings) != NO_ERROR) { + osFreeMem(jsonString); return ERROR_FAILURE; } @@ -881,6 +882,7 @@ error_t handleApiFileIndex(HttpConnection *connection, const char_t *uri, const } osFreeMem(pathAbsolute); + osFreeMem(jsonString); jsonString = cJSON_PrintUnformatted(json); cJSON_Delete(json); } while (0); diff --git a/src/main.c b/src/main.c index f367b18d..2ae023de 100644 --- a/src/main.c +++ b/src/main.c @@ -222,6 +222,7 @@ void set_settings(const char *option) { TRACE_ERROR("Invalid config-set option format. Expected name=value.\r\n"); } + osFreeMem(data); } void exit_cleanup(int exit_code)