Skip to content

Commit 82ba4dc

Browse files
committed
Fix memory leaks in mqtt_lease and mqtt_release API
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent b97158d commit 82ba4dc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mqttclient/mqttclient.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,10 @@ mqtt_client_t *mqtt_lease(void)
12261226
memset(c, 0, sizeof(mqtt_client_t));
12271227

12281228
rc = mqtt_init(c);
1229-
if (MQTT_SUCCESS_ERROR != rc)
1229+
if (MQTT_SUCCESS_ERROR != rc) {
1230+
platform_memory_free(c);
12301231
return NULL;
1232+
}
12311233

12321234
return c;
12331235
}
@@ -1266,10 +1268,15 @@ int mqtt_release(mqtt_client_t* c)
12661268
c->mqtt_write_buf = NULL;
12671269
}
12681270

1271+
if (NULL != c->mqtt_will_options) {
1272+
platform_memory_free(c->mqtt_will_options);
1273+
c->mqtt_will_options = NULL;
1274+
}
1275+
12691276
platform_mutex_destroy(&c->mqtt_write_lock);
12701277
platform_mutex_destroy(&c->mqtt_global_lock);
12711278

1272-
memset(c, 0, sizeof(mqtt_client_t));
1279+
platform_memory_free(c);
12731280

12741281
RETURN_ERROR(MQTT_SUCCESS_ERROR);
12751282
}

0 commit comments

Comments
 (0)