Consistent ref counting inc and dec functions.
This commit is contained in:
parent
bd34d8c9cd
commit
f974b91084
@ -157,7 +157,7 @@ static void subhier_clean(struct mosquitto_db *db, struct mosquitto__subhier **s
|
|||||||
leaf = nextleaf;
|
leaf = nextleaf;
|
||||||
}
|
}
|
||||||
if(peer->retained){
|
if(peer->retained){
|
||||||
db__msg_store_deref(db, &peer->retained);
|
db__msg_store_ref_dec(db, &peer->retained);
|
||||||
}
|
}
|
||||||
subhier_clean(db, &peer->children);
|
subhier_clean(db, &peer->children);
|
||||||
mosquitto__free(peer->topic);
|
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--;
|
(*store)->ref_count--;
|
||||||
if((*store)->ref_count == 0){
|
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_count12--;
|
||||||
msg_data->msg_bytes12 -= item->store->payloadlen;
|
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);
|
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->prev = NULL;
|
||||||
msg->next = NULL;
|
msg->next = NULL;
|
||||||
msg->store = stored;
|
msg->store = stored;
|
||||||
msg->store->ref_count++;
|
db__msg_store_ref_inc(msg->store);
|
||||||
msg->mid = mid;
|
msg->mid = mid;
|
||||||
msg->timestamp = mosquitto_time();
|
msg->timestamp = mosquitto_time();
|
||||||
msg->direction = dir;
|
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_FOREACH_SAFE(*head, tail, tmp){
|
||||||
DL_DELETE(*head, tail);
|
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_property_free_all(&tail->properties);
|
||||||
mosquitto__free(tail);
|
mosquitto__free(tail);
|
||||||
}
|
}
|
||||||
|
@ -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){
|
msg_tail->store->qos, msg_tail->store->retain, MOSQ_ACL_READ) != MOSQ_ERR_SUCCESS){
|
||||||
|
|
||||||
DL_DELETE((*head), msg_tail);
|
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_property_free_all(&msg_tail->properties);
|
||||||
mosquitto__free(msg_tail);
|
mosquitto__free(msg_tail);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
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_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_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_clean(struct mosquitto_db *db);
|
||||||
void db__msg_store_compact(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);
|
int db__message_reconnect_reset(struct mosquitto_db *db, struct mosquitto *context);
|
||||||
|
@ -138,7 +138,7 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
cmsg->store = load->store;
|
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);
|
context = persist__find_or_add_context(db, chunk->client_id, 0);
|
||||||
if(!context){
|
if(!context){
|
||||||
|
10
src/subs.c
10
src/subs.c
@ -146,14 +146,14 @@ static int subs__process(struct mosquitto_db *db, struct mosquitto__subhier *hie
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(hier->retained){
|
if(hier->retained){
|
||||||
db__msg_store_deref(db, &hier->retained);
|
db__msg_store_ref_dec(db, &hier->retained);
|
||||||
#ifdef WITH_SYS_TREE
|
#ifdef WITH_SYS_TREE
|
||||||
db->retained_count--;
|
db->retained_count--;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if(stored->payloadlen){
|
if(stored->payloadlen){
|
||||||
hier->retained = stored;
|
hier->retained = stored;
|
||||||
hier->retained->ref_count++;
|
db__msg_store_ref_inc(hier->retained);
|
||||||
#ifdef WITH_SYS_TREE
|
#ifdef WITH_SYS_TREE
|
||||||
db->retained_count++;
|
db->retained_count++;
|
||||||
#endif
|
#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
|
clients - this is required because websockets client calls
|
||||||
db__message_write(), which could remove the message if ref_count==0.
|
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);
|
HASH_FIND(hh, db->subs, tokens->topic, tokens->topic_len, subhier);
|
||||||
if(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);
|
sub__topic_tokens_free(tokens);
|
||||||
|
|
||||||
/* Remove our reference and free if needed. */
|
/* Remove our reference and free if needed. */
|
||||||
db__msg_store_deref(db, stored);
|
db__msg_store_ref_dec(db, stored);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -981,7 +981,7 @@ static int retain__process(struct mosquitto_db *db, struct mosquitto__subhier *b
|
|||||||
struct mosquitto_msg_store *retained;
|
struct mosquitto_msg_store *retained;
|
||||||
|
|
||||||
if(branch->retained->message_expiry_time > 0 && now > branch->retained->message_expiry_time){
|
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;
|
branch->retained = NULL;
|
||||||
#ifdef WITH_SYS_TREE
|
#ifdef WITH_SYS_TREE
|
||||||
db->retained_count--;
|
db->retained_count--;
|
||||||
|
Loading…
Reference in New Issue
Block a user