diff --git a/src/subs.c b/src/subs.c index 9778d165..d3215f58 100644 --- a/src/subs.c +++ b/src/subs.c @@ -276,13 +276,6 @@ static int _sub_add(struct mosquitto_db *db, struct mosquitto *context, int qos, leaf->next = NULL; leaf->context = context; leaf->qos = qos; - if(last_leaf){ - last_leaf->next = leaf; - leaf->prev = last_leaf; - }else{ - subhier->subs = leaf; - leaf->prev = NULL; - } if(context->subs){ for(i=0; isub_count; i++){ if(!context->subs[i]){ @@ -309,6 +302,13 @@ static int _sub_add(struct mosquitto_db *db, struct mosquitto *context, int qos, } context->subs[0] = subhier; } + if(last_leaf){ + last_leaf->next = leaf; + leaf->prev = last_leaf; + }else{ + subhier->subs = leaf; + leaf->prev = NULL; + } #ifdef WITH_SYS_TREE db->subscription_count++; #endif