diff --git a/src/database.c b/src/database.c index 2a32b82c..4d70b73d 100644 --- a/src/database.c +++ b/src/database.c @@ -157,7 +157,7 @@ static void subhier_clean(struct mosquitto_db *db, struct mosquitto__subhier **s leaf = nextleaf; } if(peer->retained){ - db__msg_store_deref(db, &peer->retained); + db__msg_store_ref_dec(db, &peer->retained); } subhier_clean(db, &peer->children); mosquitto__free(peer->topic); @@ -232,7 +232,12 @@ void db__msg_store_clean(struct mosquitto_db *db) } } -void db__msg_store_deref(struct mosquitto_db *db, struct mosquitto_msg_store **store) +void db__msg_store_ref_inc(struct mosquitto_msg_store *store) +{ + store->ref_count++; +} + +void db__msg_store_ref_dec(struct mosquitto_db *db, struct mosquitto_msg_store **store) { (*store)->ref_count--; if((*store)->ref_count == 0){ @@ -271,7 +276,7 @@ static void db__message_remove(struct mosquitto_db *db, struct mosquitto_msg_dat msg_data->msg_count12--; msg_data->msg_bytes12 -= item->store->payloadlen; } - db__msg_store_deref(db, &item->store); + db__msg_store_ref_dec(db, &item->store); } mosquitto_property_free_all(&item->properties); @@ -450,7 +455,7 @@ int db__message_insert(struct mosquitto_db *db, struct mosquitto *context, uint1 msg->prev = NULL; msg->next = NULL; msg->store = stored; - msg->store->ref_count++; + db__msg_store_ref_inc(msg->store); msg->mid = mid; msg->timestamp = mosquitto_time(); msg->direction = dir; @@ -543,7 +548,7 @@ void db__messages_delete_list(struct mosquitto_db *db, struct mosquitto_client_m DL_FOREACH_SAFE(*head, tail, tmp){ DL_DELETE(*head, tail); - db__msg_store_deref(db, &tail->store); + db__msg_store_ref_dec(db, &tail->store); mosquitto_property_free_all(&tail->properties); mosquitto__free(tail); } diff --git a/src/handle_connect.c b/src/handle_connect.c index 7fc160e9..1bd35ace 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -92,7 +92,7 @@ void connection_check_acl(struct mosquitto_db *db, struct mosquitto *context, st msg_tail->store->qos, msg_tail->store->retain, MOSQ_ACL_READ) != MOSQ_ERR_SUCCESS){ DL_DELETE((*head), msg_tail); - db__msg_store_deref(db, &msg_tail->store); + db__msg_store_ref_dec(db, &msg_tail->store); mosquitto_property_free_all(&msg_tail->properties); mosquitto__free(msg_tail); } diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 478aa0f6..540dbcbe 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -619,7 +619,8 @@ int db__message_store(struct mosquitto_db *db, const struct mosquitto *source, u int db__message_store_find(struct mosquitto *context, uint16_t mid, struct mosquitto_msg_store **stored); void db__msg_store_add(struct mosquitto_db *db, struct mosquitto_msg_store *store); void db__msg_store_remove(struct mosquitto_db *db, struct mosquitto_msg_store *store); -void db__msg_store_deref(struct mosquitto_db *db, struct mosquitto_msg_store **store); +void db__msg_store_ref_inc(struct mosquitto_msg_store *store); +void db__msg_store_ref_dec(struct mosquitto_db *db, struct mosquitto_msg_store **store); void db__msg_store_clean(struct mosquitto_db *db); void db__msg_store_compact(struct mosquitto_db *db); int db__message_reconnect_reset(struct mosquitto_db *db, struct mosquitto *context); diff --git a/src/persist_read.c b/src/persist_read.c index 1ae2f7a6..48437e46 100644 --- a/src/persist_read.c +++ b/src/persist_read.c @@ -138,7 +138,7 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_ return 1; } cmsg->store = load->store; - cmsg->store->ref_count++; + db__msg_store_ref_inc(cmsg->store); context = persist__find_or_add_context(db, chunk->client_id, 0); if(!context){ diff --git a/src/subs.c b/src/subs.c index 11093819..91d34266 100644 --- a/src/subs.c +++ b/src/subs.c @@ -146,14 +146,14 @@ static int subs__process(struct mosquitto_db *db, struct mosquitto__subhier *hie } #endif if(hier->retained){ - db__msg_store_deref(db, &hier->retained); + db__msg_store_ref_dec(db, &hier->retained); #ifdef WITH_SYS_TREE db->retained_count--; #endif } if(stored->payloadlen){ hier->retained = stored; - hier->retained->ref_count++; + db__msg_store_ref_inc(hier->retained); #ifdef WITH_SYS_TREE db->retained_count++; #endif @@ -803,7 +803,7 @@ int sub__messages_queue(struct mosquitto_db *db, const char *source_id, const ch clients - this is required because websockets client calls db__message_write(), which could remove the message if ref_count==0. */ - (*stored)->ref_count++; + db__msg_store_ref_inc(*stored); HASH_FIND(hh, db->subs, tokens->topic, tokens->topic_len, subhier); if(subhier){ @@ -818,7 +818,7 @@ int sub__messages_queue(struct mosquitto_db *db, const char *source_id, const ch sub__topic_tokens_free(tokens); /* Remove our reference and free if needed. */ - db__msg_store_deref(db, stored); + db__msg_store_ref_dec(db, stored); return rc; } @@ -981,7 +981,7 @@ static int retain__process(struct mosquitto_db *db, struct mosquitto__subhier *b struct mosquitto_msg_store *retained; if(branch->retained->message_expiry_time > 0 && now > branch->retained->message_expiry_time){ - db__msg_store_deref(db, &branch->retained); + db__msg_store_ref_dec(db, &branch->retained); branch->retained = NULL; #ifdef WITH_SYS_TREE db->retained_count--;