Skip to content

Commit

Permalink
#233: copy char* in get_metadata. Dovecots memory managment will free it
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Jan 18, 2019
1 parent 3de64f3 commit 386c9a5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/storage-rbox/rbox-mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 386c9a5

Please sign in to comment.