Fix unref'd messages being saved to the persistence file.

This was leaving dangling messages that were never freed.

Closes #389. Thanks to pjchx.
pull/1182/head
Roger A. Light 7 years ago
parent f9f3fdbfe3
commit 321e566af6

@ -8,6 +8,8 @@ Broker:
- Fix include_dir not sorting config files before loading. This was partially
fixed in 1.5 previously.
- Improve documentation around the `include_dir` option. Closes #1154.
- Fix case where old unreferenced msg_store messages were being saved to the
persistence file, bloating its size unnecessarily. Closes #389.
Library:
- Fix `mosquitto_topic_matches_sub()` not returning MOSQ_ERR_INVAL for

@ -235,6 +235,21 @@ void db__msg_store_deref(struct mosquitto_db *db, struct mosquitto_msg_store **s
}
void db__msg_store_compact(struct mosquitto_db *db)
{
struct mosquitto_msg_store *store, *next;
store = db->msg_store;
while(store){
next = store->next;
if(store->ref_count < 1){
db__msg_store_remove(db, store);
}
store = next;
}
}
static void db__message_remove(struct mosquitto_db *db, struct mosquitto *context, struct mosquitto_client_msg **msg, struct mosquitto_client_msg *last)
{
if(!context || !msg || !(*msg)){
@ -1019,8 +1034,3 @@ void db__limits_set(int inflight, unsigned long inflight_bytes, int queued, unsi
max_queued_bytes = queued_bytes;
}
void db__vacuum(void)
{
/* FIXME - reimplement? */
}

@ -562,8 +562,8 @@ void db__msg_store_add(struct mosquitto_db *db, struct mosquitto_msg_store *stor
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_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);
void db__vacuum(void);
void sys_tree__init(struct mosquitto_db *db);
void sys_tree__update(struct mosquitto_db *db, int interval, time_t start_time);

@ -151,6 +151,11 @@ static int persist__message_store_write(struct mosquitto_db *db, FILE *db_fptr)
stored = db->msg_store;
while(stored){
if(stored->ref_count < 1){
stored = stored->next;
continue;
}
if(stored->topic && !strncmp(stored->topic, "$SYS", 4)){
if(stored->ref_count <= 1 && stored->dest_id_count == 0){
/* $SYS messages that are only retained shouldn't be persisted. */
@ -982,6 +987,9 @@ int persist__restore(struct mosquitto_db *db)
HASH_DELETE(hh, db->msg_store_load, load);
mosquitto__free(load);
}
db__msg_store_compact(db);
return rc;
error:
err = strerror(errno);

Loading…
Cancel
Save