Skip to content

Commit 2c39077

Browse files
author
paul
committed
merging git tree
git-svn-id: https://svn.ic-s.nl/svn/dbmail/trunk/dbmail@2069 7b491191-dbf0-0310-aff6-d879d4d69008
1 parent b2b23d9 commit 2c39077

File tree

6 files changed

+65
-47
lines changed

6 files changed

+65
-47
lines changed

ChangeLog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2006-04-14 Paul J Stevens <[email protected]>
2+
3+
* check_dbmail_mailbox.c, dbmail-mailbox.c, dbmailtypes.h:
4+
search-not is now fixed.
5+
* modules/dbpgsql.c:
6+
fix some compiler warnings
7+
* dbmail-message.c:
8+
fix a memory leak.
9+
* dbmail-mailbox.c:
10+
fix a double free
11+
112
2006-04-13 Paul J Stevens <[email protected]>
213

314
* dbmail.h.in:

check_dbmail_mailbox.c

+12-13
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,13 @@ START_TEST(test_dbmail_mailbox_search)
281281
dbmail_mailbox_free(mb);
282282
g_strfreev(array);
283283

284-
printf ("all [%d], found [%d], notfound [%d]", all, found, notfound);
284+
fail_unless((all - found) == notfound, "dbmail_mailbox_search failed: SEARCH NOT");
285285

286-
return;
287286
// third case
288287
idx=0;
289288
sorted = 0;
290289
mb = dbmail_mailbox_new(get_mailbox_id());
291-
args = g_strdup("1 BODY [email protected]");
290+
args = g_strdup("UID 1,* BODY [email protected]");
292291
array = g_strsplit(args," ",0);
293292
g_free(args);
294293

@@ -847,17 +846,17 @@ Suite *dbmail_mailbox_suite(void)
847846
TCase *tc_mailbox = tcase_create("Mailbox");
848847
suite_add_tcase(s, tc_mailbox);
849848
tcase_add_checked_fixture(tc_mailbox, setup, teardown);
850-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_get_set);
851-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_new);
852-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_free);
853-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_open);
854-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_dump);
855-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_build_imap_search);
856-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_sort);
849+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_get_set);
850+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_new);
851+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_free);
852+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_open);
853+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_dump);
854+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_build_imap_search);
855+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_sort);
857856
tcase_add_test(tc_mailbox, test_dbmail_mailbox_search);
858-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_search_parsed_1);
859-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_search_parsed_2);
860-
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_orderedsubject);
857+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_search_parsed_1);
858+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_search_parsed_2);
859+
tcase_add_test(tc_mailbox, test_dbmail_mailbox_orderedsubject);
861860
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_fetch_build);
862861
// tcase_add_test(tc_mailbox, test_dbmail_mailbox_fetch);
863862
return s;

dbmail-mailbox.c

+26-22
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ struct DbmailMailbox * dbmail_mailbox_new(u64_t id)
3838
struct DbmailMailbox *self = g_new0(struct DbmailMailbox, 1);
3939
assert(self);
4040
dbmail_mailbox_set_id(self,id);
41-
41+
dbmail_mailbox_set_uid(self, FALSE);
42+
self->search = NULL;
43+
self->set = NULL;
44+
self->fi = NULL;
45+
4246
if (dbmail_mailbox_open(self)) {
4347
dbmail_mailbox_free(self);
4448
return NULL;
4549
}
4650

47-
dbmail_mailbox_set_uid(self, FALSE);
48-
self->search = NULL;
49-
self->set = NULL;
50-
self->fi = NULL;
5151
return self;
5252
}
5353

@@ -137,7 +137,7 @@ int dbmail_mailbox_open(struct DbmailMailbox *self)
137137
__FILE__, __func__);
138138
db_free_result();
139139
g_string_free(q,TRUE);
140-
return DM_EGENERAL;
140+
return DM_SUCCESS;
141141
}
142142

143143
if (self->ids) {
@@ -166,7 +166,7 @@ int dbmail_mailbox_open(struct DbmailMailbox *self)
166166
static size_t dump_message_to_stream(struct DbmailMessage *message, GMimeStream *ostream)
167167
{
168168
size_t r = 0;
169-
gchar *s;
169+
gchar *s, *d;
170170
GString *sender;
171171
GString *date;
172172
InternetAddressList *ialist;
@@ -188,7 +188,9 @@ static size_t dump_message_to_stream(struct DbmailMessage *message, GMimeStream
188188
}
189189
internet_address_list_destroy(ialist);
190190

191-
date = g_string_new(dbmail_message_get_internal_date(message));
191+
d = dbmail_message_get_internal_date(message);
192+
date = g_string_new(d);
193+
g_free(d);
192194
if (date->len < 1)
193195
date = g_string_new(FROM_STANDARD_DATE);
194196

@@ -1292,7 +1294,6 @@ static GTree * mailbox_search_parsed(struct DbmailMailbox *self, search_key_t *s
12921294
ids = g_list_next(ids);
12931295
}
12941296

1295-
g_list_free(ids);
12961297
return s->found;
12971298
}
12981299

@@ -1416,7 +1417,7 @@ GTree * dbmail_mailbox_get_set(struct DbmailMailbox *self, const char *set)
14161417
g_tree_destroy(a);
14171418

14181419
self->set = g_tree_keys(b);
1419-
1420+
14201421
trace(TRACE_DEBUG,"%s,%s: self->set contains [%d] ids between [%llu] and [%llu]",
14211422
__FILE__, __func__, g_list_length(g_list_first(self->set)), lo, hi);
14221423

@@ -1427,12 +1428,9 @@ static gboolean _do_search(GNode *node, struct DbmailMailbox *self)
14271428
{
14281429
search_key_t *s = (search_key_t *)node->data;
14291430

1430-
if (s->merged == TRUE)
1431+
if (s->searched)
14311432
return FALSE;
1432-
1433-
trace(TRACE_DEBUG,"%s,%s: type [%d]", __FILE__, __func__, s->type);
14341433

1435-
14361434
switch (s->type) {
14371435
case IST_SET:
14381436
if (! dbmail_mailbox_get_set(self, (const char *)s->search))
@@ -1453,7 +1451,7 @@ static gboolean _do_search(GNode *node, struct DbmailMailbox *self)
14531451

14541452
case IST_DATA_BODY:
14551453
mailbox_search_parsed(self,s);
1456-
break;
1454+
break;
14571455

14581456
case IST_SUBSEARCH_NOT:
14591457
case IST_SUBSEARCH_AND:
@@ -1468,9 +1466,10 @@ static gboolean _do_search(GNode *node, struct DbmailMailbox *self)
14681466
return TRUE;
14691467
}
14701468

1471-
s->merged = TRUE;
1472-
trace(TRACE_DEBUG,"%s,%s: type [%d] depth [%d] rows [%d]\n", __FILE__, __func__,
1473-
s->type, g_node_depth(node), s->found ? g_tree_nnodes(s->found): 0);
1469+
s->searched = TRUE;
1470+
1471+
trace(TRACE_DEBUG,"%s,%s: [%d] depth [%d] type [%d] rows [%d]\n", __FILE__, __func__,
1472+
(int)s, g_node_depth(node), s->type, s->found ? g_tree_nnodes(s->found): 0);
14741473

14751474
return FALSE;
14761475
}
@@ -1488,7 +1487,12 @@ static gboolean _merge_search(GNode *node, GTree *found)
14881487
GNode *x, *y;
14891488
GTree *z;
14901489

1491-
trace(TRACE_DEBUG,"%s,%s: node depth [%d] type [%d]", __FILE__, __func__, g_node_depth(node), s->type);
1490+
if (s->merged == TRUE)
1491+
return FALSE;
1492+
1493+
trace(TRACE_DEBUG,"%s,%s: [%d] depth [%d] type [%d]",
1494+
__FILE__, __func__,
1495+
(int)s, g_node_depth(node), s->type);
14921496
switch(s->type) {
14931497
case IST_SUBSEARCH_AND:
14941498
g_node_children_foreach(node, G_TRAVERSE_LEAVES, (GNodeForeachFunc)_merge_search, (gpointer)found);
@@ -1499,12 +1503,11 @@ static gboolean _merge_search(GNode *node, GTree *found)
14991503
break;
15001504

15011505
z = g_tree_new((GCompareFunc)ucmp);
1502-
g_tree_foreach(found, (GTraverseFunc) g_tree_copy, z);
1506+
g_tree_foreach(found, (GTraverseFunc)g_tree_copy, z);
15031507
g_node_children_foreach(node, G_TRAVERSE_LEAVES, (GNodeForeachFunc)_merge_search, (gpointer) z);
15041508
if (z)
15051509
g_tree_merge(found, z, IST_SUBSEARCH_NOT);
15061510
g_tree_destroy(z);
1507-
15081511
break;
15091512

15101513
case IST_SUBSEARCH_OR:
@@ -1521,10 +1524,11 @@ static gboolean _merge_search(GNode *node, GTree *found)
15211524
default:
15221525
if (s->found && found)
15231526
g_tree_merge(found, s->found, IST_SUBSEARCH_AND);
1524-
15251527
break;
15261528
}
15271529

1530+
s->merged = TRUE;
1531+
15281532
return FALSE;
15291533
}
15301534

dbmail-message.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static void _set_content_from_stream(struct DbmailMessage *self, GMimeStream *st
295295
GMimeStream *fstream, *bstream, *mstream;
296296
GMimeFilter *filter;
297297
GMimeParser *parser;
298-
gchar *buf;
298+
gchar *buf, *from;
299299
size_t t;
300300

301301
/*
@@ -354,8 +354,11 @@ static void _set_content_from_stream(struct DbmailMessage *self, GMimeStream *st
354354
case DBMAIL_MESSAGE:
355355
trace(TRACE_DEBUG,"%s,%s: parse message",__FILE__,__func__);
356356
self->content = GMIME_OBJECT(g_mime_parser_construct_message(parser));
357-
if (g_mime_parser_get_scan_from(parser))
358-
dbmail_message_set_internal_date(self, g_mime_parser_get_from(parser));
357+
if (g_mime_parser_get_scan_from(parser)) {
358+
from = g_mime_parser_get_from(parser);
359+
dbmail_message_set_internal_date(self, from);
360+
g_free(from);
361+
}
359362

360363
break;
361364
case DBMAIL_MESSAGE_PART:

dbmailtypes.h

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ typedef struct {
319319
int match;
320320
GTree *found;
321321
gboolean reverse;
322+
gboolean searched;
322323
gboolean merged;
323324
} search_key_t;
324325

modules/dbpgsql.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ static void _create_binary_table(void){
183183
rows = db_num_rows(); fields = db_num_fields();
184184

185185
if(!bintbl){
186-
bintbl = (char***)malloc(sizeof(char**) * rows);
186+
bintbl = (char***)g_malloc(sizeof(char**) * rows);
187187
memset(bintbl, 0, sizeof(char**) * rows);
188188
for(i = 0; i < rows; i++){
189-
*(bintbl + i) = (char**)malloc(sizeof(char*) * fields);
189+
*(bintbl + i) = (char**)g_malloc(sizeof(char*) * fields);
190190
memset(*(bintbl + i), 0, sizeof(char*) * fields);
191191
}
192192
}
@@ -200,10 +200,10 @@ static void _free_binary_table(void){
200200
for(i = 0; i < rows; i++){
201201
for(j = 0; j < fields; j++)
202202
if(bintbl[i][j])
203-
free(bintbl[i][j]);
204-
free(bintbl[i]);
203+
g_free(bintbl[i][j]);
204+
g_free(bintbl[i]);
205205
}
206-
free(bintbl);
206+
g_free(bintbl);
207207
bintbl = NULL;
208208
}
209209

@@ -212,8 +212,8 @@ static void _set_binary_table(unsigned row, unsigned field){
212212
unsigned char* tmp;
213213
size_t result_size;
214214
if(!bintbl[row][field]){
215-
tmp = PQunescapeBytea(PQgetvalue(res, row, field), &result_size);
216-
bintbl[row][field] = (char*)malloc(result_size + 1);
215+
tmp = PQunescapeBytea((const unsigned char *)PQgetvalue(res, row, field), &result_size);
216+
bintbl[row][field] = (char*)g_malloc(result_size + 1);
217217
memcpy(bintbl[row][field], tmp, result_size);
218218
PQfreemem(tmp); tmp = NULL;
219219
bintbl[row][field][result_size] = '\0';
@@ -343,8 +343,8 @@ unsigned long db_escape_binary(char *to,
343343
size_t to_length;
344344
unsigned char *esc_to;
345345

346-
esc_to = PQescapeBytea(from, length, &to_length);
347-
strncpy(to, esc_to, to_length);
346+
esc_to = PQescapeBytea((const unsigned char *)from, length, &to_length);
347+
strncpy(to, (const char *)esc_to, to_length);
348348
PQfreemem(esc_to);
349349
return (unsigned long)(to_length - 1);
350350
}

0 commit comments

Comments
 (0)