From 4905496eedbc946bac2f811ee35d30ee18fd8282 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 27 Jan 2023 19:02:46 -0500 Subject: [PATCH] Fix all memory leaks caused by json_array_append() and json_object_set(). --- src/app/RackWidget.cpp | 4 ++-- src/engine/Module.cpp | 2 +- src/library.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 3d379d1d..fc933318 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -485,7 +485,7 @@ static PasteJsonResult RackWidget_pasteJson(RackWidget* that, json_t* rootJ, his if (inputModuleIdIt == newModules.end()) continue; inputModuleId = inputModuleIdIt->second->module->id; - json_object_set(cableJ, "inputModuleId", json_integer(inputModuleId)); + json_object_set_new(cableJ, "inputModuleId", json_integer(inputModuleId)); json_t* outputModuleIdJ = json_object_get(cableJ, "outputModuleId"); if (!outputModuleIdJ) @@ -495,7 +495,7 @@ static PasteJsonResult RackWidget_pasteJson(RackWidget* that, json_t* rootJ, his if (outputModuleIdIt == newModules.end()) continue; outputModuleId = outputModuleIdIt->second->module->id; - json_object_set(cableJ, "outputModuleId", json_integer(outputModuleId)); + json_object_set_new(cableJ, "outputModuleId", json_integer(outputModuleId)); // Create Cable engine::Cable* cable = new engine::Cable; diff --git a/src/engine/Module.cpp b/src/engine/Module.cpp index d944cdd7..d83a5b75 100644 --- a/src/engine/Module.cpp +++ b/src/engine/Module.cpp @@ -217,7 +217,7 @@ json_t* Module::paramsToJson() { json_object_set_new(paramJ, "id", json_integer(paramId)); - json_array_append(rootJ, paramJ); + json_array_append_new(rootJ, paramJ); } return rootJ; } diff --git a/src/library.cpp b/src/library.cpp index d1c9958d..b621d8e7 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -66,7 +66,7 @@ void checkAppUpdate() { std::string versionUrl = API_URL + "/version"; json_t* reqJ = json_object(); - json_object_set(reqJ, "edition", json_string(APP_EDITION.c_str())); + json_object_set_new(reqJ, "edition", json_string(APP_EDITION.c_str())); DEFER({json_decref(reqJ);}); json_t* resJ = network::requestJson(network::METHOD_GET, versionUrl, reqJ); @@ -115,8 +115,8 @@ void logIn(std::string email, std::string password) { loginStatus = "Logging in..."; json_t* reqJ = json_object(); - json_object_set(reqJ, "email", json_string(email.c_str())); - json_object_set(reqJ, "password", json_string(password.c_str())); + json_object_set_new(reqJ, "email", json_string(email.c_str())); + json_object_set_new(reqJ, "password", json_string(password.c_str())); std::string url = API_URL + "/token"; json_t* resJ = network::requestJson(network::METHOD_POST, url, reqJ); json_decref(reqJ); @@ -196,7 +196,7 @@ void checkUpdates() { // Get library manifests std::string manifestsUrl = API_URL + "/library/manifests"; json_t* manifestsReq = json_object(); - json_object_set(manifestsReq, "version", json_string(APP_VERSION_MAJOR.c_str())); + json_object_set_new(manifestsReq, "version", json_string(APP_VERSION_MAJOR.c_str())); json_t* manifestsResJ = network::requestJson(network::METHOD_GET, manifestsUrl, manifestsReq); json_decref(manifestsReq); if (!manifestsResJ) {