diff --git a/src/loop.c b/src/loop.c index 2fee9ac7..05a1cf6f 100644 --- a/src/loop.c +++ b/src/loop.c @@ -498,10 +498,11 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li } context = NULL; HASH_FIND(hh_sock, db->contexts_by_sock, &(ev.data.fd), sizeof(mosq_sock_t), context); - if(!context) { + if(context){ + context->events = EPOLLIN; + }else{ log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll accepting: no context"); } - context->events = EPOLLIN; } } break; diff --git a/src/subs.c b/src/subs.c index 1abff30d..57e0dddd 100644 --- a/src/subs.c +++ b/src/subs.c @@ -216,8 +216,8 @@ static struct sub__token *sub__topic_append(struct sub__token **tail, struct sub static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics) { struct sub__token *new_topic, *tail = NULL; - int len; - int start, stop, tlen; + size_t len; + size_t start, stop, tlen; int i; char *topic; int count = 0; @@ -225,13 +225,16 @@ static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics) assert(subtopic); assert(topics); + len = strlen(subtopic); + if(len == 0){ + return 1; + } + if(subtopic[0] != '$'){ new_topic = sub__topic_append(&tail, topics, ""); if(!new_topic) goto cleanup; } - len = strlen(subtopic); - if(subtopic[0] == '/'){ new_topic = sub__topic_append(&tail, topics, ""); if(!new_topic) goto cleanup; @@ -268,7 +271,11 @@ static int sub__topic_tokenise(const char *subtopic, struct sub__token **topics) goto cleanup; } - return MOSQ_ERR_SUCCESS; + if(*topics != NULL){ + return MOSQ_ERR_SUCCESS; + }else{ + return 1; + } cleanup: tail = *topics;