From c85e735955e7d8403e2b9784c32bf855c51754d7 Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on ChromeOS)" <rob@synchro.net> Date: Wed, 31 May 2023 18:07:17 -0700 Subject: [PATCH] Report (via exception) more potential failures in MQTT constructor --- src/sbbs3/js_mqtt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sbbs3/js_mqtt.c b/src/sbbs3/js_mqtt.c index cdae1c80e7..d4a54d0a2c 100644 --- a/src/sbbs3/js_mqtt.c +++ b/src/sbbs3/js_mqtt.c @@ -707,13 +707,23 @@ static JSBool js_mqtt_constructor(JSContext* cx, uintN argc, jsval *arglist) p->cfg = scfg->mqtt; p->handle = mosquitto_new(client_id, /* clean_session: */true, /* userdata: */p); free(client_id); + if(p->handle == NULL) { + JS_ReportError(cx, "mosquitto_new failure (errno=%d)", errno); + free(p); + return JS_FALSE; + } if(!JS_SetPrivate(cx, obj, p)) { JS_ReportError(cx,"JS_SetPrivate failed"); free(p); return JS_FALSE; } mosquitto_message_callback_set(p->handle, mqtt_message_received); - mosquitto_loop_start(p->handle); + int result = mosquitto_loop_start(p->handle); + if(result != MOSQ_ERR_SUCCESS) { + JS_ReportError(cx, "mosquitto_loop_start error %d", result); + free(p); + return JS_FALSE; + } #ifdef BUILD_JSDOCS js_DescribeSyncObject(cx,obj,"Class used for MQTT communications",320); -- GitLab