Skip to content

Commit 2e1f3e5

Browse files
committed
wip: fix leakage
1 parent 8ae55ae commit 2e1f3e5

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

src/dbmail-message.c

+29-31
Original file line numberDiff line numberDiff line change
@@ -724,41 +724,40 @@ DbmailMessage * dbmail_message_init_with_string(DbmailMessage *self, const GStri
724724
GMimeStream *stream;
725725

726726
assert(self->content == NULL);
727+
assert(self->raw_content == NULL);
727728

728729
stream = g_mime_stream_mem_new_with_buffer(str->str, str->len);
729730
parser = g_mime_parser_new_with_stream(stream);
730731
g_object_unref(stream);
731732

732-
if (strncmp(str->str, "From ", 5) == 0) {
733-
/* don't use gmime's from scanner since body lines may begin with 'From ' */
734-
char *end;
735-
if ((end = g_strstr_len(str->str, 80, "\n"))) {
736-
size_t l = end - str->str;
737-
from = g_strndup(str->str, l);
738-
TRACE(TRACE_DEBUG, "From_ [%s]", from);
739-
}
740-
}
741-
742733
content = GMIME_OBJECT(g_mime_parser_construct_message(parser));
743734
if (content) {
744735
dbmail_message_set_class(self, DBMAIL_MESSAGE);
745-
self->content = content;
746-
self->raw_content = dbmail_message_to_string(self);
747-
if (from) {
748-
dbmail_message_set_internal_date(self, from);
736+
737+
if (strncmp(str->str, "From ", 5) == 0) {
738+
/* don't use gmime's from scanner since body lines may begin with 'From ' */
739+
char *end;
740+
if ((end = g_strstr_len(str->str, 80, "\n"))) {
741+
size_t l = end - str->str;
742+
from = g_strndup(str->str, l);
743+
TRACE(TRACE_DEBUG, "From_ [%s]", from);
744+
dbmail_message_set_internal_date(self, from);
745+
g_free(from);
746+
}
749747
}
750-
g_object_unref(parser);
748+
749+
self->content = content;
750+
self->raw_content = g_strdup(str->str);
751751
} else {
752752
content = GMIME_OBJECT(g_mime_parser_construct_part(parser));
753753
if (content) {
754754
dbmail_message_set_class(self, DBMAIL_MESSAGE_PART);
755755
self->content = content;
756-
self->raw_content = dbmail_message_to_string(self);
757-
g_object_unref(parser);
756+
self->raw_content = g_strdup(str->str);
758757
}
759758
}
759+
g_object_unref(parser);
760760

761-
if (from) g_free(from);
762761
_map_headers(self);
763762
return self;
764763
}
@@ -815,15 +814,14 @@ static void _register_header(const char *header, const char *value, gpointer use
815814
g_relation_insert(m->headers, hname, hvalue);
816815
}
817816

818-
void dbmail_message_set_physid(DbmailMessage *self, uint64_t physid)
817+
void dbmail_message_set_physid(DbmailMessage *self, uint64_t id)
819818
{
820-
self->id = physid;
821-
self->physid = physid;
819+
self->id = id;
822820
}
823821

824822
uint64_t dbmail_message_get_physid(const DbmailMessage *self)
825823
{
826-
return self->physid;
824+
return self->id;
827825
}
828826

829827
void dbmail_message_set_internal_date(DbmailMessage *self, char *internal_date)
@@ -1121,7 +1119,7 @@ static int _update_message(DbmailMessage *self)
11211119
uint64_t rfcsize = (uint64_t)dbmail_message_get_size(self,TRUE);
11221120

11231121
if (! db_update("UPDATE %sphysmessage SET messagesize = %lu, rfcsize = %lu WHERE id = %lu",
1124-
DBPFX, size, rfcsize, self->physid))
1122+
DBPFX, size, rfcsize, self->id))
11251123
return DM_EQUERY;
11261124

11271125
if (! db_update("UPDATE %smessages SET status = %d WHERE message_idnr = %lu",
@@ -1336,7 +1334,7 @@ void _message_cache_envelope_date(const DbmailMessage *self)
13361334
_header_value_get_id(value, sortfield, datefield, &headervalue_id);
13371335

13381336
if (headervalue_id && headername_id)
1339-
_header_insert(self->physid, headername_id, headervalue_id);
1337+
_header_insert(self->id, headername_id, headervalue_id);
13401338

13411339
g_free(value);
13421340
g_free(sortfield);
@@ -1346,7 +1344,7 @@ void _message_cache_envelope_date(const DbmailMessage *self)
13461344
int dbmail_message_cache_headers(const DbmailMessage *self)
13471345
{
13481346
assert(self);
1349-
assert(self->physid);
1347+
assert(self->id);
13501348

13511349
if (! GMIME_IS_MESSAGE(self->content)) {
13521350
TRACE(TRACE_ERR,"self->content is not a message");
@@ -1731,7 +1729,7 @@ static gboolean _header_cache(const char UNUSED *key, const char *header, gpoint
17311729

17321730
/* Insert relation between physmessage, header name and header value */
17331731
if (headervalue_id)
1734-
_header_insert(self->physid, headername_id, headervalue_id);
1732+
_header_insert(self->id, headername_id, headervalue_id);
17351733
else
17361734
TRACE(TRACE_INFO, "error inserting headervalue. skipping.");
17371735

@@ -1747,7 +1745,7 @@ static gboolean _header_cache(const char UNUSED *key, const char *header, gpoint
17471745
return FALSE;
17481746
}
17491747

1750-
static void insert_field_cache(uint64_t physid, const char *field, const char *value)
1748+
static void insert_field_cache(uint64_t id, const char *field, const char *value)
17511749
{
17521750
gchar *clean_value;
17531751
C c; S s;
@@ -1761,7 +1759,7 @@ static void insert_field_cache(uint64_t physid, const char *field, const char *v
17611759
TRY
17621760
db_begin_transaction(c);
17631761
s = db_stmt_prepare(c,"INSERT INTO %s%sfield (physmessage_id, %sfield) VALUES (?,?)", DBPFX, field, field);
1764-
db_stmt_set_u64(s, 1, physid);
1762+
db_stmt_set_u64(s, 1, id);
17651763
db_stmt_set_str(s, 2, clean_value);
17661764
db_stmt_exec(s);
17671765
db_commit_transaction(c);
@@ -1796,7 +1794,7 @@ void dbmail_message_cache_referencesfield(const DbmailMessage *self)
17961794
g_free(field);
17971795

17981796
if (! refs) {
1799-
TRACE(TRACE_DEBUG, "reference_decode failed [%lu]", self->physid);
1797+
TRACE(TRACE_DEBUG, "reference_decode failed [%lu]", self->id);
18001798
return;
18011799
}
18021800

@@ -1805,7 +1803,7 @@ void dbmail_message_cache_referencesfield(const DbmailMessage *self)
18051803

18061804
while (refs->msgid) {
18071805
if (! g_tree_lookup(tree,refs->msgid)) {
1808-
insert_field_cache(self->physid, "references", refs->msgid);
1806+
insert_field_cache(self->id, "references", refs->msgid);
18091807
g_tree_insert(tree,refs->msgid,refs->msgid);
18101808
}
18111809
if (refs->next == NULL)
@@ -1828,7 +1826,7 @@ void dbmail_message_cache_envelope(const DbmailMessage *self)
18281826
TRY
18291827
db_begin_transaction(c);
18301828
s = db_stmt_prepare(c, "INSERT INTO %senvelope (physmessage_id, envelope) VALUES (?,?)", DBPFX);
1831-
db_stmt_set_u64(s, 1, self->physid);
1829+
db_stmt_set_u64(s, 1, self->id);
18321830
db_stmt_set_str(s, 2, envelope);
18331831
db_stmt_exec(s);
18341832
db_commit_transaction(c);

src/dbmailtypes.h

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ enum DBMAIL_MESSAGE_FILTER_TYPES {
131131

132132
typedef struct {
133133
uint64_t id;
134-
uint64_t physid;
135134
time_t internal_date;
136135
int internal_date_gmtoff;
137136
GString *envelope_recipient;

0 commit comments

Comments
 (0)