Skip to content

Commit d4b65dc

Browse files
committed
check null
1 parent 59f1b4c commit d4b65dc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

common/mqtt_list.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* @LastEditTime: 2020-04-27 23:28:12
66
* @Description: the following code references TencentOS tiny, please keep the author information and source code according to the license.
77
*/
8+
#include <stddef.h>
9+
#include "mqtt_list.h"
810

9-
# include "mqtt_list.h"
1011

1112
static void _mqtt_list_add(mqtt_list_t *node, mqtt_list_t *prev, mqtt_list_t *next)
1213
{
@@ -43,9 +44,13 @@ void mqtt_list_add_tail(mqtt_list_t *node, mqtt_list_t *list)
4344
_mqtt_list_add(node, list->prev, list);
4445
}
4546

46-
void mqtt_list_del(mqtt_list_t *entry)
47+
void mqtt_list_del(mqtt_list_t* entry)
4748
{
48-
_mqtt_list_del(entry->prev, entry->next);
49+
if (entry == NULL) return;
50+
if (entry->prev == NULL || entry->next == NULL) return;
51+
_mqtt_list_del(entry->prev, entry->next);
52+
entry->prev = NULL;
53+
entry->next = NULL;
4954
}
5055

5156
void mqtt_list_del_init(mqtt_list_t *entry)

mqttclient/mqttclient.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ static int mqtt_is_topic_equals(const char *topic_filter, const char *topic)
228228
return 0;
229229
}
230230

231+
// topic_filter: The filter string used in subscription (may contain +/#), e.g. a/+/c or foo/#
232+
// topic_name: The actual topic received (should not contain wildcards), e.g. a/b/c or foo/bar
231233
static char mqtt_topic_is_matched(const char* topic_filter, MQTTString* topic_name)
232234
{
233235
const char* filter = topic_filter;
@@ -465,8 +467,14 @@ static message_handlers_t *mqtt_msg_handler_create(const char* topic_filter, mqt
465467
static void mqtt_msg_handler_destory(message_handlers_t *msg_handler)
466468
{
467469
if (NULL != &msg_handler->list) {
470+
471+
if (msg_handler->list.prev == NULL || msg_handler->list.next == NULL) return;
472+
468473
mqtt_list_del(&msg_handler->list);
474+
msg_handler->list.prev == NULL;
475+
msg_handler->list.next == NULL;
469476
platform_memory_free(msg_handler);
477+
msg_handler = NULL;
470478
}
471479
}
472480

0 commit comments

Comments
 (0)