diff --git a/src/storage-rbox/rbox-mail.cpp b/src/storage-rbox/rbox-mail.cpp index ff68b4ab..04f0aeda 100644 --- a/src/storage-rbox/rbox-mail.cpp +++ b/src/storage-rbox/rbox-mail.cpp @@ -138,7 +138,13 @@ static int rbox_mail_metadata_get(struct rbox_mail *rmail, enum rbox_metadata_ke FUNC_END(); return -1; } - rmail->rados_mail->get_metadata(key, value_r); + + // we need to copy the pointer. Because dovecots memory mgmnt will free it! + char* val = NULL; + rmail->rados_mail->get_metadata(key, &val); + if (val != NULL) { + *value_r = i_strdup(val); + } FUNC_END(); return 0; } @@ -313,7 +319,9 @@ int rbox_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r) { rmail->rados_mail->add_metadata(metadata_phy); if (value != NULL && free_value) { + i_warning("FREE_V"); i_free(value); + i_warning("FREE_V_DONE"); } return ret; } @@ -517,6 +525,7 @@ static int rbox_get_cached_metadata(struct rbox_mail *mail, enum rbox_metadata_k char *value = NULL; unsigned int order = 0; + bool free_value = true; string_t *str = str_new(imail->mail.data_pool, 64); if (mail_cache_lookup_field(imail->mail.mail.transaction->cache_view, str, imail->mail.mail.seq, @@ -544,6 +553,7 @@ static int rbox_get_cached_metadata(struct rbox_mail *mail, enum rbox_metadata_k if (value == NULL) { value = i_strdup(""); + free_value = false; } if (cache_field != MAIL_CACHE_POP3_ORDER) { index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx, value, strlen(value) + 1); @@ -559,7 +569,9 @@ static int rbox_get_cached_metadata(struct rbox_mail *mail, enum rbox_metadata_k change unexpectedly */ str_truncate(str, 0); str_append(str, value); - i_free(value); + if (free_value && value != NULL) { + i_free(value); + } *value_r = str_c(str); return 0; }