[evolution-mapi] Bug #586345 - Memory leaks in offline sync
- From: Milan Crha <mcrha src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-mapi] Bug #586345 - Memory leaks in offline sync
- Date: Thu, 17 Sep 2009 17:47:09 +0000 (UTC)
commit 72a3da35cec2dd976c2e7111e7484ceec62f63e1
Author: Milan Crha <mcrha redhat com>
Date: Thu Sep 17 19:49:59 2009 +0200
Bug #586345 - Memory leaks in offline sync
.../exchange-mapi-account-listener.c | 1 +
.../exchange-mapi-account-settings.c | 2 +-
src/camel/camel-mapi-folder.c | 81 +++++++++++++-------
src/camel/camel-mapi-folder.h | 1 +
src/camel/camel-mapi-store.c | 7 ++-
src/camel/camel-mapi-summary.c | 12 +++-
src/libexchangemapi/exchange-mapi-cal-utils.c | 17 +++-
src/libexchangemapi/exchange-mapi-connection.c | 11 +++-
src/libexchangemapi/exchange-mapi-folder.c | 23 +++---
src/libexchangemapi/exchange-mapi-folder.h | 1 +
src/libexchangemapi/exchange-mapi-utils.c | 12 ++--
11 files changed, 115 insertions(+), 53 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-mapi-account-listener.c b/src/account-setup-eplugin/exchange-mapi-account-listener.c
index 4ac15c6..25c72c4 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-listener.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-listener.c
@@ -462,6 +462,7 @@ add_addressbook_sources (EAccount *account, GSList *folders)
uri = g_strdup_printf("mapigal://%s %s/;Global Address List", url->user, url->host);
source = e_source_new_with_absolute_uri ("Global Address List", uri);
+ g_free (uri);
// source = e_source_new ("Global Address List", g_strconcat (";","Global Address List" , NULL));
e_source_set_property (source, "auth", "plain/password");
e_source_set_property (source, "auth-domain", "MAPIGAL");
diff --git a/src/account-setup-eplugin/exchange-mapi-account-settings.c b/src/account-setup-eplugin/exchange-mapi-account-settings.c
index e40e088..e3f2dc5 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-settings.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-settings.c
@@ -340,7 +340,7 @@ static GtkActionEntry folder_size_entries[] = {
N_("Folder size"),
NULL,
NULL, /* XXX Add a tooltip! */
- action_folder_size_cb }
+ G_CALLBACK (action_folder_size_cb) }
};
gboolean
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 43373fc..e05d695 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -178,10 +178,8 @@ mapi_refresh_info(CamelFolder *folder, CamelException *ex)
}
-
-/*Using GFunc*/
-static void
-mapi_item_free (MapiItem *item, gpointer data)
+void
+mapi_item_free (MapiItem *item)
{
g_free (item->header.subject);
g_free (item->header.from);
@@ -196,6 +194,9 @@ mapi_item_free (MapiItem *item, gpointer data)
exchange_mapi_util_free_attachment_list (&item->attachments);
exchange_mapi_util_free_stream_list (&item->generic_streams);
+ exchange_mapi_util_free_recipient_list (&item->recipients);
+
+ g_free (item);
}
static gboolean
@@ -351,8 +352,8 @@ fetch_items_cb (FetchItemsCallbackData *item_data, gpointer data)
fi_data_mod_time.tv_usec = fi_data->last_modification_time.tv_usec;
if (timeval_compare (&item_modification_time, &fi_data_mod_time) == 1) {
- fi_data->last_modification_time.tv_sec = item_modification_time.tv_sec;
- fi_data->last_modification_time.tv_usec = item_modification_time.tv_usec;
+ fi_data->last_modification_time.tv_sec = item_modification_time.tv_sec;
+ fi_data->last_modification_time.tv_usec = item_modification_time.tv_usec;
}
if ((*flags & MSGFLAG_READ) != 0)
@@ -483,7 +484,7 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
for ( ; item_list != NULL ; item_list = g_slist_next (item_list) ) {
MapiItem *temp_item ;
MapiItem *item;
- gchar *msg_uid, *to = NULL, *from = NULL, *cc = NULL;
+ gchar *msg_uid;
guint64 id;
exists = FALSE;
@@ -522,6 +523,7 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
if (!exists) {
GSList *l = NULL;
guint32 count_to = 0, count_cc =0;
+ gchar *to = NULL, *cc = NULL;
mi->info.uid = exchange_mapi_util_mapi_ids_to_uid(item->fid, item->mid);
mi->info.subject = camel_pstring_strdup(item->header.subject);
@@ -565,8 +567,10 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
switch (*type) {
case MAPI_TO:
if (count_to) {
+ gchar *tmp = to;
to = g_strconcat (to, ", ", formatted_id, NULL);
g_free (formatted_id);
+ g_free (tmp);
} else
to = formatted_id;
count_to ++;
@@ -574,8 +578,10 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
case MAPI_CC:
if (count_cc) {
+ gchar *tmp = cc;
cc = g_strconcat (cc, ", ", formatted_id, NULL);
g_free (formatted_id);
+ g_free (tmp);
} else
cc = formatted_id;
count_cc ++;
@@ -600,15 +606,20 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
item->header.from_email : item->header.from;
if (item->header.from_email) {
- from = camel_internet_address_format_address (item->header.from,
- item->header.from_email);
+ gchar *from = camel_internet_address_format_address (item->header.from,
+ item->header.from_email);
mi->info.from = camel_pstring_strdup (from);
+
+ g_free (from);
} else
mi->info.from = NULL;
/* Fallback */
- mi->info.to = to ? camel_pstring_strdup (to) : g_strdup (item->header.to);
- mi->info.cc = to ? camel_pstring_strdup (cc) : g_strdup (item->header.cc);
+ mi->info.to = to ? camel_pstring_strdup (to) : camel_pstring_strdup (item->header.to);
+ mi->info.cc = cc ? camel_pstring_strdup (cc) : camel_pstring_strdup (item->header.cc);
+
+ g_free (to);
+ g_free (cc);
}
if (exists) {
@@ -789,7 +800,7 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
CamelMessageInfo *info = NULL;
CamelMapiMessageInfo *mapi_info = NULL;
- GSList *read_items = NULL, *unread_items = NULL;
+ GSList *read_items = NULL, *unread_items = NULL, *to_free = NULL;
flags_diff_t diff, unset_flags;
const char *folder_id;
mapi_id_t fid, deleted_items_fid;
@@ -830,40 +841,55 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
mapi_id_t *mid = g_new0 (mapi_id_t, 1); /* FIXME : */
mapi_id_t temp_fid;
guint32 flags;
+ gboolean used = FALSE;
uid = camel_message_info_uid (info);
flags= camel_message_info_flags (info);
/* Why are we getting so much noise here :-/ */
- if (!exchange_mapi_util_mapi_ids_from_uid (uid, &temp_fid, mid))
+ if (!exchange_mapi_util_mapi_ids_from_uid (uid, &temp_fid, mid)) {
+ g_free (mid);
continue;
+ }
mapi_utils_do_flags_diff (&diff, mapi_info->server_flags, mapi_info->info.flags);
mapi_utils_do_flags_diff (&unset_flags, flags, mapi_info->server_flags);
diff.changed &= folder->permanent_flags;
if (!diff.changed) {
- camel_message_info_free(info);
+ camel_message_info_free (info);
+ g_free (mid);
continue;
} else {
if (diff.bits & CAMEL_MESSAGE_DELETED) {
- if (diff.bits & CAMEL_MESSAGE_SEEN)
+ if (diff.bits & CAMEL_MESSAGE_SEEN) {
read_items = g_slist_prepend (read_items, mid);
- if (deleted_items)
+ used = TRUE;
+ }
+ if (deleted_items) {
deleted_items = g_slist_prepend (deleted_items, mid);
- else {
+ used = TRUE;
+ } else {
g_slist_free (deleted_head);
deleted_head = NULL;
deleted_head = deleted_items = g_slist_prepend (deleted_items, mid);
+ used = TRUE;
}
}
}
if (diff.bits & CAMEL_MESSAGE_SEEN) {
read_items = g_slist_prepend (read_items, mid);
+ used = TRUE;
} else if (unset_flags.bits & CAMEL_MESSAGE_SEEN) {
unread_items = g_slist_prepend (unread_items, mid);
+ used = TRUE;
}
+
+ if (used)
+ to_free = g_slist_prepend (to_free, mid);
+ else
+ g_free (mid);
}
camel_message_info_free (info);
}
@@ -908,10 +934,11 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
deleted_items = g_slist_next (deleted_items);
}
- if (unread_items) {
- /* TODO */
- g_slist_free (unread_items);
- }
+ g_slist_free (unread_items);
+ g_slist_free (deleted_head);
+
+ g_slist_foreach (to_free, (GFunc) g_free, NULL);
+ g_slist_free (to_free);
if (expunge) {
/* TODO */
@@ -1054,6 +1081,7 @@ mapi_refresh_folder(CamelFolder *folder, CamelException *ex)
}
/*Preserve last_modification_time from this fetch for later use with restrictions.*/
+ g_free (mapi_summary->sync_time_stamp);
mapi_summary->sync_time_stamp = g_time_val_to_iso8601 (&fetch_data->last_modification_time);
camel_folder_summary_touch (folder->summary);
@@ -1292,6 +1320,8 @@ fetch_item_cb (FetchItemsCallbackData *item_data, gpointer data)
item->msg.body_parts = g_slist_append (item->msg.body_parts, body);
item->is_cal = TRUE;
+
+ g_free (appointment_body_str);
} else {
if (!((body = exchange_mapi_util_find_stream (item_data->streams, PR_HTML)) ||
(body = exchange_mapi_util_find_stream (item_data->streams, PR_BODY))))
@@ -1374,7 +1404,8 @@ mapi_msg_set_recipient_list (CamelMimeMessage *msg, MapiItem *item)
camel_internet_address_add (bcc_addr, display_name, recip->email_id);
break;
}
- /* g_free (display_name); */
+
+ g_free (display_name);
}
/*Add to message*/
@@ -1579,7 +1610,6 @@ mapi_folder_item_to_msg( CamelFolder *folder,
camel_object_unref (part);
}
- exchange_mapi_util_free_attachment_list (&attach_list);
}
camel_medium_set_content_object(CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER(multipart));
@@ -1682,10 +1712,7 @@ mapi_folder_get_message( CamelFolder *folder, const char *uid, CamelException *e
}
msg = mapi_folder_item_to_msg (folder, item, ex);
-
- exchange_mapi_util_free_recipient_list (&item->recipients);
-
- g_free (item);
+ mapi_item_free (item);
if (!msg) {
camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Could not get message"));
diff --git a/src/camel/camel-mapi-folder.h b/src/camel/camel-mapi-folder.h
index b3b003a..90accc6 100644
--- a/src/camel/camel-mapi-folder.h
+++ b/src/camel/camel-mapi-folder.h
@@ -99,6 +99,7 @@ typedef struct {
GSList *generic_streams;
}MapiItem;
+void mapi_item_free (MapiItem *item);
typedef struct _CamelMapiFolder CamelMapiFolder;
typedef struct _CamelMapiFolderClass CamelMapiFolderClass;
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 71bafb8..18e53e5 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -1308,6 +1308,8 @@ mapi_folders_sync (CamelMapiStore *store, const char *top, guint32 flags, CamelE
mapi_si = camel_mapi_store_summary_add_from_full (store->summary, info->full_name, '/', fid, pfid);
+ g_free (fid);
+ g_free (pfid);
if (mapi_si == NULL) {
continue;
}
@@ -1321,7 +1323,10 @@ mapi_folders_sync (CamelMapiStore *store, const char *top, guint32 flags, CamelE
camel_store_summary_touch ((CamelStoreSummary *)store->summary);
camel_store_summary_save ((CamelStoreSummary *)store->summary);
- g_free ((char *)url);
+ g_free (url);
+
+ g_slist_foreach (list, (GFunc) exchange_mapi_folder_free, NULL);
+ g_slist_free (list);
// g_hash_table_foreach (present, get_folders_free, NULL);
// g_hash_table_destroy (present);
diff --git a/src/camel/camel-mapi-summary.c b/src/camel/camel-mapi-summary.c
index 2196df8..efd64fc 100644
--- a/src/camel/camel-mapi-summary.c
+++ b/src/camel/camel-mapi-summary.c
@@ -55,7 +55,7 @@ static int mapi_content_info_to_db (CamelFolderSummary *s, CamelMessageContentIn
static void camel_mapi_summary_class_init (CamelMapiSummaryClass *klass);
static void camel_mapi_summary_init (CamelMapiSummary *obj);
-
+static void camel_mapi_summary_finalize (CamelObject *obj);
/*End of Prototypes*/
@@ -76,7 +76,7 @@ camel_mapi_summary_get_type (void)
(CamelObjectClassInitFunc) camel_mapi_summary_class_init,
NULL,
(CamelObjectInitFunc) camel_mapi_summary_init,
- NULL);
+ (CamelObjectFinalizeFunc) camel_mapi_summary_finalize);
}
return type;
@@ -128,6 +128,13 @@ camel_mapi_summary_init (CamelMapiSummary *obj)
s->meta_summary->uid_len = 2048;
}
+static void
+camel_mapi_summary_finalize (CamelObject *obj)
+{
+ CamelMapiSummary *s = (CamelMapiSummary *)obj;
+
+ g_free (s->sync_time_stamp);
+}
/**
* camel_mapi_summary_new:
@@ -179,6 +186,7 @@ mapi_summary_header_from_db (CamelFolderSummary *summary, CamelFIRecord *fir)
MS_EXTRACT_FIRST_DIGIT(mapi_summary->version);
if (part && part++) {
+ g_free (mapi_summary->sync_time_stamp);
mapi_summary->sync_time_stamp = g_strdup (part);
}
diff --git a/src/libexchangemapi/exchange-mapi-cal-utils.c b/src/libexchangemapi/exchange-mapi-cal-utils.c
index 322c4d4..9e43006 100644
--- a/src/libexchangemapi/exchange-mapi-cal-utils.c
+++ b/src/libexchangemapi/exchange-mapi-cal-utils.c
@@ -1057,7 +1057,7 @@ update_attendee_status (struct mapi_SPropValue_array *properties, mapi_id_t mid)
const gchar *att, *att_sentby, *addrtype;
icalparameter_partstat partstat = ICAL_PARTSTAT_NONE;
const gchar *state = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_MESSAGE_CLASS);
- struct cbdata cbdata;
+ struct cbdata cbdata = { 0 };
gchar *matt, *matt_sentby;
uint32_t cur_seq;
const uint32_t *ui32;
@@ -1133,6 +1133,7 @@ update_attendee_status (struct mapi_SPropValue_array *properties, mapi_id_t mid)
/* remove the other attendees so not to confuse itip-formatter */
remove_other_attendees (cbdata.comp, matt);
} else {
+ g_free (cbdata.props);
g_object_unref (cbdata.comp);
cbdata.comp = NULL;
}
@@ -1157,7 +1158,7 @@ update_server_object (struct mapi_SPropValue_array *properties, GSList *attachme
cur_seq = ui32 ? *ui32 : 0;
if (*mid) {
- struct cbdata server_cbd;
+ struct cbdata server_cbd = {0};
fetch_server_data (*mid, &server_cbd);
if (cur_seq > server_cbd.appt_seq) {
@@ -1171,10 +1172,14 @@ update_server_object (struct mapi_SPropValue_array *properties, GSList *attachme
g_slist_free (ids);
} else
create_new = FALSE;
+
+ if (server_cbd.comp)
+ g_object_unref (server_cbd.comp);
+ g_free (server_cbd.props);
}
if (create_new) {
- struct cbdata cbdata;
+ struct cbdata cbdata = { 0 };
GSList *myrecipients = NULL;
GSList *myattachments = NULL;
icalcomponent_kind kind = icalcomponent_isa (e_cal_component_get_icalcomponent(comp));
@@ -1239,7 +1244,7 @@ check_server_for_object (struct mapi_SPropValue_array *properties, mapi_id_t *mi
struct id_list *idlist = (struct id_list *)(ids->data);
*mid = idlist->id;
} else {
- /* FIXME: what to do here? */
+ /* FIXME: what to do here? */
}
for (l = ids; l; l = l->next)
@@ -1285,10 +1290,12 @@ exchange_mapi_cal_util_camel_helper (struct mapi_SPropValue_array *properties,
}
} else if (method == ICAL_METHOD_CANCEL) {
if (mid) {
- struct cbdata server_cbd;
+ struct cbdata server_cbd = { 0 };
fetch_server_data (mid, &server_cbd);
comp = server_cbd.comp;
set_attachments_to_cal_component (comp, attachments, fileuri);
+
+ g_free (server_cbd.props);
}
} else if (method == ICAL_METHOD_REQUEST) {
if (mid)
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 900d736..883502e 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -1291,6 +1291,10 @@ exchange_mapi_connection_fetch_items (mapi_id_t fid,
cb_retval = cb (item_data, data);
g_free (item_data);
+ } else {
+ exchange_mapi_util_free_stream_list (&stream_list);
+ exchange_mapi_util_free_recipient_list (&recip_list);
+ exchange_mapi_util_free_attachment_list (&attach_list);
}
if (GetPropsTagArray->cValues)
@@ -1468,6 +1472,10 @@ exchange_mapi_connection_fetch_item (mapi_id_t fid, mapi_id_t mid,
cb (item_data, data);
g_free (item_data);
+ } else {
+ exchange_mapi_util_free_stream_list (&stream_list);
+ exchange_mapi_util_free_recipient_list (&recip_list);
+ exchange_mapi_util_free_attachment_list (&attach_list);
}
// if (GetPropsTagArray->cValues)
@@ -2675,10 +2683,11 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
/* Iterate through MV_BINARY */
if (entryids) {
for (i = 0; i < G_N_ELEMENTS (olfolder_defaults); i++) {
+ fid = 0;
entryid = entryids->lpbin [i];
retval = GetFIDFromEntryID(entryid.cb, entryid.lpb, inbox_id, &fid);
- if (fid) {
+ if (retval == MAPI_E_SUCCESS && fid) {
folder_type = g_new0 (guint32, 1);
*folder_type = olfolder_defaults[i];
diff --git a/src/libexchangemapi/exchange-mapi-folder.c b/src/libexchangemapi/exchange-mapi-folder.c
index 03c2cca..98bc484 100644
--- a/src/libexchangemapi/exchange-mapi-folder.c
+++ b/src/libexchangemapi/exchange-mapi-folder.c
@@ -80,6 +80,15 @@ exchange_mapi_folder_new (const char *folder_name, const char *container_class,
return folder;
}
+void
+exchange_mapi_folder_free (ExchangeMAPIFolder *folder)
+{
+ if (folder) {
+ g_free (folder->folder_name);
+ g_free (folder);
+ }
+}
+
ExchangeMAPIFolderType
exchange_mapi_container_class (char *type)
{
@@ -129,7 +138,7 @@ exchange_mapi_folder_get_total_count (ExchangeMAPIFolder *folder)
}
GSList *
-exchange_mapi_peek_folder_list ()
+exchange_mapi_peek_folder_list (void)
{
LOCK ();
if (!folder_list)
@@ -162,22 +171,16 @@ exchange_mapi_folder_get_folder (mapi_id_t fid)
}
void
-exchange_mapi_folder_list_free ()
+exchange_mapi_folder_list_free (void)
{
- GSList *tmp = folder_list;
LOCK ();
- while (tmp) {
- ExchangeMAPIFolder *data = tmp->data;
- g_free (data);
- data = NULL;
- tmp = tmp->next;
- }
+ g_slist_foreach (folder_list, (GFunc) exchange_mapi_folder_free, NULL);
g_slist_free (folder_list);
+
folder_list = NULL;
UNLOCK ();
d(g_print("Folder list freed\n"));
- return;
}
void
diff --git a/src/libexchangemapi/exchange-mapi-folder.h b/src/libexchangemapi/exchange-mapi-folder.h
index c695e82..026ad6f 100644
--- a/src/libexchangemapi/exchange-mapi-folder.h
+++ b/src/libexchangemapi/exchange-mapi-folder.h
@@ -77,6 +77,7 @@ exchange_mapi_folder_new (const char *folder_name, const char *container_class,
ExchangeMAPIFolderCategory catgory,
mapi_id_t folder_id, mapi_id_t parent_folder_id,
uint32_t child_count, uint32_t unread_count, uint32_t total);
+void exchange_mapi_folder_free (ExchangeMAPIFolder *folder);
ExchangeMAPIFolderType exchange_mapi_container_class (char *type);
const gchar* exchange_mapi_folder_get_name (ExchangeMAPIFolder *folder);
diff --git a/src/libexchangemapi/exchange-mapi-utils.c b/src/libexchangemapi/exchange-mapi-utils.c
index 372a484..fa5a054 100644
--- a/src/libexchangemapi/exchange-mapi-utils.c
+++ b/src/libexchangemapi/exchange-mapi-utils.c
@@ -250,8 +250,8 @@ exchange_mapi_util_free_attachment_list (GSList **attach_list)
g_free (attachment);
attachment = NULL;
}
- g_slist_free (l);
- l = NULL;
+ g_slist_free (*attach_list);
+ *attach_list = NULL;
}
void
@@ -274,8 +274,8 @@ exchange_mapi_util_free_recipient_list (GSList **recip_list)
g_free (recipient->out.all_lpProps);
*/ g_free (recipient);
}
- g_slist_free (l);
- l = NULL;
+ g_slist_free (*recip_list);
+ *recip_list = NULL;
}
void
@@ -293,8 +293,8 @@ exchange_mapi_util_free_stream_list (GSList **stream_list)
g_free (stream);
stream = NULL;
}
- g_slist_free (l);
- l = NULL;
+ g_slist_free (*stream_list);
+ *stream_list = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]