From aeb1e364c424913417841e999be9ba9968c088b4 Mon Sep 17 00:00:00 2001 From: Nikita Rushmanov Date: Tue, 3 May 2022 13:33:16 -0700 Subject: [PATCH] Fix memory leak in Nanoleaf Controller --- Controllers/NanoleafController/NanoleafController.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Controllers/NanoleafController/NanoleafController.cpp b/Controllers/NanoleafController/NanoleafController.cpp index cbcec22d..b48ee30c 100644 --- a/Controllers/NanoleafController/NanoleafController.cpp +++ b/Controllers/NanoleafController/NanoleafController.cpp @@ -192,6 +192,8 @@ void NanoleafController::UpdateLEDs(std::vector& colors) } external_control_socket.udp_write((char*)message, (size * 7) + 1); + + free(message); } else if((model == NANOLEAF_CANVAS_MODEL) || (model == NANOLEAF_SHAPES_MODEL)) @@ -230,6 +232,8 @@ void NanoleafController::UpdateLEDs(std::vector& colors) } external_control_socket.udp_write((char *)message, (size * 8) + 2); + + free(message); } } @@ -252,7 +256,7 @@ void NanoleafController::StartExternalControl() json response; if((APIRequest("PUT", location, "/api/v1/"+auth_token+"/effects", &request, &response) / 100) == 2) - { + { external_control_socket.udp_client(response["streamControlIpAddr"].get().c_str(), std::to_string(response["streamControlPort"].get()).c_str()); selectedEffect = NANOLEAF_DIRECT_MODE_EFFECT_NAME;