From 8097ec24f9184a939facfc92edcf1a6870671d0c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 3 Apr 2019 11:23:31 +0100 Subject: [PATCH] Fix some property leaks. --- src/context.c | 20 +------------------- src/database.c | 2 ++ src/handle_publish.c | 7 ++++++- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/context.c b/src/context.c index 7bbe7541..8e526d71 100644 --- a/src/context.c +++ b/src/context.c @@ -102,7 +102,6 @@ struct mosquitto *context__init(struct mosquitto_db *db, mosq_sock_t sock) void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool do_free) { struct mosquitto__packet *packet; - struct mosquitto_client_msg *msg, *next; #ifdef WITH_BRIDGE int i; #endif @@ -179,24 +178,7 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d mosquitto__free(packet); } if(do_free || context->clean_start){ - msg = context->inflight_msgs; - while(msg){ - next = msg->next; - db__msg_store_deref(db, &msg->store); - mosquitto__free(msg); - msg = next; - } - context->inflight_msgs = NULL; - context->last_inflight_msg = NULL; - msg = context->queued_msgs; - while(msg){ - next = msg->next; - db__msg_store_deref(db, &msg->store); - mosquitto__free(msg); - msg = next; - } - context->queued_msgs = NULL; - context->last_queued_msg = NULL; + db__messages_delete(db, context); } #if defined(WITH_BROKER) && defined(__GLIBC__) && defined(WITH_ADNS) if(context->adns){ diff --git a/src/database.c b/src/database.c index ea7fd078..c380d8ef 100644 --- a/src/database.c +++ b/src/database.c @@ -569,6 +569,7 @@ int db__messages_delete(struct mosquitto_db *db, struct mosquitto *context) while(tail){ db__msg_store_deref(db, &tail->store); next = tail->next; + mosquitto_property_free_all(&tail->properties); mosquitto__free(tail); tail = next; } @@ -579,6 +580,7 @@ int db__messages_delete(struct mosquitto_db *db, struct mosquitto *context) while(tail){ db__msg_store_deref(db, &tail->store); next = tail->next; + mosquitto_property_free_all(&tail->properties); mosquitto__free(tail); tail = next; } diff --git a/src/handle_publish.c b/src/handle_publish.c index babef977..20f341f1 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -161,16 +161,21 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context) mosquitto_property_free_all(&properties); if(topic_alias == 0 || topic_alias > context->listener->max_topic_alias){ + mosquitto__free(topic); send__disconnect(context, MQTT_RC_TOPIC_ALIAS_INVALID, NULL); return MOSQ_ERR_PROTOCOL; }else if(topic_alias > 0){ if(topic){ rc = alias__add(context, topic, topic_alias); - if(rc) return rc; + if(rc){ + mosquitto__free(topic); + return rc; + } }else{ rc = alias__find(context, &topic, topic_alias); if(rc){ send__disconnect(context, MQTT_RC_TOPIC_ALIAS_INVALID, NULL); + mosquitto__free(topic); return rc; } }