From dec455488c7c24727d45ddc8f1de13c93ec8558e Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on ChromeOS)" <rob@synchro.net> Date: Sat, 27 May 2023 12:46:25 -0700 Subject: [PATCH] Fix memory leak on destruction when all received messages were not read --- src/sbbs3/js_mqtt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sbbs3/js_mqtt.c b/src/sbbs3/js_mqtt.c index b7812ea366..0efc7a7544 100644 --- a/src/sbbs3/js_mqtt.c +++ b/src/sbbs3/js_mqtt.c @@ -35,6 +35,7 @@ typedef struct static void js_finalize_mqtt(JSContext* cx, JSObject* obj) { private_t* p; + struct mosquitto_message* msg; if((p = (private_t*)JS_GetPrivate(cx,obj)) == NULL) return; @@ -44,6 +45,8 @@ static void js_finalize_mqtt(JSContext* cx, JSObject* obj) mosquitto_loop_stop(p->handle, /* force: */true); mosquitto_destroy(p->handle); } + while((msg = msgQueueRead(&p->q, /* timeout: */0)) != NULL) + mosquitto_message_free(&msg); msgQueueFree(&p->q); free(p); -- GitLab