From 886e3dc74b551f9d9f0b3e8f2c12f864d0265a77 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 19 Jun 2007 08:16:56 +0000 Subject: [PATCH] * leak fixes; free both list and its elements when we call modest_account_mgr_account_names * use the new function modest_account_mgr_free_account_names * some other smaller leak fixes pmo-trunk-r2303 --- src/maemo/easysetup/modest-easysetup-wizard.c | 11 +-- src/maemo/modest-main-window.c | 9 ++- src/maemo/modest-msg-edit-window.c | 9 ++- src/modest-account-mgr-helpers.c | 15 +--- src/modest-account-mgr.c | 97 +++++++------------------ src/modest-account-mgr.h | 24 ++---- src/modest-init.c | 2 + src/modest-tny-account-store.c | 17 ++--- src/modest-ui-actions.c | 6 +- src/modest-widget-memory.c | 4 +- src/widgets/modest-account-view.c | 10 +-- src/widgets/modest-header-view-render.c | 8 +- src/widgets/modest-header-view.c | 8 +- src/widgets/modest-msg-view.c | 2 +- 14 files changed, 75 insertions(+), 147 deletions(-) diff --git a/src/maemo/easysetup/modest-easysetup-wizard.c b/src/maemo/easysetup/modest-easysetup-wizard.c index eed4517..386d40e 100644 --- a/src/maemo/easysetup/modest-easysetup-wizard.c +++ b/src/maemo/easysetup/modest-easysetup-wizard.c @@ -1608,20 +1608,13 @@ create_account (ModestEasysetupWizardDialog *self, gboolean enabled) return FALSE; } - /* Sanity check: */ /* There must be at least one account now: */ /* Note, when this fails is is caused by a Maemo gconf bug that has been * fixed in versions after 3.1. */ - GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE); - if(!account_names) - { + if(!modest_account_mgr_has_accounts (self->account_manager, FALSE)) g_warning ("modest_account_mgr_account_names() returned NULL after adding an account."); - } - g_slist_free (account_names); - - - + /* The user name and email address must be set additionally: */ const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name)); modest_account_mgr_set_string (self->account_manager, account_name, diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 4073ff8..0204e87 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -560,9 +560,9 @@ on_account_store_connecting_finished (TnyAccountStore *store, ModestMainWindow * iter = g_slist_next (iter); } - - g_slist_free (account_names); - + + modest_account_mgr_free_account_names (account_names); + account_names = NULL; modest_ui_actions_do_send_receive (NULL, MODEST_WINDOW (self)); } @@ -1179,7 +1179,8 @@ on_account_update (TnyAccountStore *account_store, iter = iter->next; } - g_slist_free (account_names); + modest_account_mgr_free_account_names (account_names); + account_names = NULL; /* Order the list of accounts by its display name */ accounts = g_slist_sort (accounts, (GCompareFunc) compare_display_names); diff --git a/src/maemo/modest-msg-edit-window.c b/src/maemo/modest-msg-edit-window.c index 25f90f0..88249b6 100644 --- a/src/maemo/modest-msg-edit-window.c +++ b/src/maemo/modest-msg-edit-window.c @@ -292,11 +292,11 @@ get_transports (void) ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr(); GSList *accounts = modest_account_mgr_account_names (account_mgr, - TRUE /* only enabled accounts. */); + TRUE /* only enabled accounts. */); GSList *cursor = accounts; while (cursor) { - const gchar *account_name = cursor->data; + gchar *account_name = cursor->data; gchar *from_string = NULL; if (account_name) { from_string = modest_account_mgr_get_from_string (account_mgr, @@ -304,7 +304,7 @@ get_transports (void) } if (from_string && account_name) { - gchar *name = g_strdup (account_name); + gchar *name = account_name; ModestPair *pair = modest_pair_new ((gpointer) name, (gpointer) from_string , TRUE); transports = g_slist_prepend (transports, pair); @@ -312,7 +312,8 @@ get_transports (void) cursor = cursor->next; } - g_slist_free (accounts); + g_slist_free (accounts); /* only free the accounts, not the elements, + * because they are used in the pairlist */ return transports; } diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index da7f1f1..441dbff 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -573,13 +573,6 @@ gint on_accounts_list_sort_by_title(gconstpointer a, gconstpointer b) return g_utf8_collate((const gchar*)a, (const gchar*)b); } - -static void -free_element (gpointer data, gpointer user_data) -{ - g_free (data); -} - gboolean modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self) { @@ -598,10 +591,10 @@ modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self) if (account_name) result = modest_account_mgr_set_default_account (self, account_name); } - - g_slist_foreach (account_names, free_element, NULL); - g_slist_free (account_names); - + + modest_account_mgr_free_account_names (account_names); + account_names = NULL; + return result; } diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index b164eeb..06b8558 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -618,58 +618,6 @@ strip_prefix_from_elements (GSList * lst, guint n) } } -#if 0 -/* Not used. */ -GSList* -modest_account_mgr_search_server_accounts (ModestAccountMgr * self, - const gchar * account_name, - ModestTransportStoreProtocol proto) -{ - GSList *accounts; - GSList *cursor; - ModestAccountMgrPrivate *priv; - gchar *key; - GError *err = NULL; - - g_return_val_if_fail (self, NULL); - - key = _modest_account_mgr_get_account_keyname (account_name, NULL, TRUE); - priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); - - /* get the list of all server accounts */ - accounts = modest_conf_list_subkeys (priv->modest_conf, key, &err); - if (err) { - g_printerr ("modest: failed to get subkeys for '%s' (%s)\n", key, - err->message); - g_error_free(err); - return NULL; - } - - /* filter out the ones with the wrong protocol */ - /* we could optimize for unknown proto / unknown type, but it will only - * make the code more complex */ - cursor = accounts; - while (cursor) { - gchar *account = _modest_account_mgr_account_from_key ((gchar*)cursor->data, NULL, NULL); - gchar *acc_proto = modest_account_mgr_get_string (self, account, MODEST_ACCOUNT_PROTO,TRUE); - ModestTransportStoreProtocol this_proto = - modest_protocol_info_get_transport_store_protocol (acc_proto); - if (this_proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN && this_proto != proto) { - GSList *nxt = cursor->next; - accounts = g_slist_delete_link (accounts, cursor); - cursor = nxt; - } else - cursor = cursor->next; - - g_free (account); - g_free (acc_proto); - } - - /* +1 because we must remove the ending '/' as well */ - strip_prefix_from_elements (accounts, strlen(key)+1); - return accounts; -} -#endif GSList* modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled) @@ -704,11 +652,9 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled continue; const gchar* account_name_key = (const gchar*)iter->data; - /* printf ("DEBUG: %s: account_name_key=%s\n", __FUNCTION__, account_name_key); */ gchar* unescaped_name = account_name_key ? modest_conf_key_unescape (account_name_key) : NULL; - /* printf (" DEBUG: %s: unescaped name=%s\n", __FUNCTION__, unescaped_name); */ gboolean add = TRUE; if (only_enabled) { @@ -718,24 +664,35 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled } } - if (add) { + if (add) result = g_slist_append (result, unescaped_name); - } - else { + else g_free (unescaped_name); - } - + + g_free (iter->data); + iter->data = NULL; + iter = g_slist_next (iter); } - /* TODO: Free the strings too? */ + + /* we already freed the strings in the loop */ g_slist_free (accounts); + accounts = NULL; - return result; } +void +modest_account_mgr_free_account_names (GSList *account_names) +{ + g_slist_foreach (account_names, (GFunc)g_free, NULL); + g_slist_free (account_names); +} + + + gchar * modest_account_mgr_get_string (ModestAccountMgr *self, const gchar *name, const gchar *key, gboolean server_account) { @@ -1028,7 +985,7 @@ modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self, co GSList *cursor = NULL; cursor = account_names = modest_account_mgr_account_names (self, - TRUE /* enabled accounts, because disabled accounts are not user visible. */); + TRUE /* enabled accounts, because disabled accounts are not user visible. */); gboolean found = FALSE; @@ -1050,7 +1007,8 @@ modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self, co modest_account_mgr_free_account_data (self, account_data); cursor = cursor->next; } - g_slist_free (account_names); + modest_account_mgr_free_account_names (account_names); + account_names = NULL; return found; } @@ -1180,9 +1138,11 @@ modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled) { /* Check that at least one account exists: */ GSList *account_names = modest_account_mgr_account_names (self, - enabled); + enabled); gboolean accounts_exist = account_names != NULL; - g_slist_free (account_names); + + modest_account_mgr_free_account_names (account_names); + account_names = NULL; return accounts_exist; } @@ -1211,10 +1171,9 @@ modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account priv->busy_accounts = g_slist_append(priv->busy_accounts, g_strdup(account_name)); g_signal_emit_by_name(G_OBJECT(self), "account-busy-changed", account_name, TRUE); } - g_slist_free(account_names); - } - else - { + modest_account_mgr_free_account_names (account_names); + account_names = NULL; + } else { GSList* account = g_slist_find_custom(priv->busy_accounts, account_name, (GCompareFunc) compare_account_name); if (account) diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index aaf5c06..b992f82 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -184,32 +184,20 @@ gboolean modest_account_mgr_remove_account (ModestAccountMgr *sel * Returns: a newly allocated list of account names, or NULL in case of error or * if there are no accounts. The caller must free the returned GSList. * - * TODO: I believe that the caller must free the strings in the GSList items too, - * because this is implemented via gconf_client_all_dirs() which also requires a deep free, - * though that's not documented. murrayc. */ GSList* modest_account_mgr_account_names (ModestAccountMgr *self, gboolean only_enabled); -#if 0 -/* Not used. */ /** - * modest_account_mgr_search_server_account: - * @self: a ModestAccountMgr instance - * @account_name: get only server accounts for @account_name, or NULL for any - * @type: get only server accounts from protocol type @type, or MODEST_PROTOCOL_TYPE_UNKNOWN - * @proto: get only server account with protocol @proto, or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN for any + * modest_account_mgr_free_account_names: + * @account_name: a gslist of account names * - * List all the server account names, optionally narrowing the result down to one account. + * list all account names * - * Returns: a newly allocated list of server account names, or NULL in case of - * error or if there are no server accounts. The caller must free the returned GSList + * free the list of account names */ -GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self, - const gchar* account_name, - ModestProtocolType type, - ModestTransportStoreProtocol proto); -#endif +void modest_account_mgr_free_account_names (GSList *account_names); + /** * modest_account_mgr_account_exists: diff --git a/src/modest-init.c b/src/modest-init.c index e0f8048..ce90fbc 100644 --- a/src/modest-init.c +++ b/src/modest-init.c @@ -510,6 +510,8 @@ init_i18n (void) bind_textdomain_codeset (gettext_package, "UTF-8"); textdomain (gettext_package); + + setlocale (LC_ALL, ""); } diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 5b85b37..f5da3b4 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -624,8 +624,9 @@ create_per_account_local_outbox_folders (TnyAccountStore *self) accounts = g_slist_append (accounts, tny_account_outbox); /* cache it */ }; - - g_slist_free (account_names); + + modest_account_mgr_free_account_names (account_names); + account_names = NULL; priv->store_accounts_outboxes = accounts; } @@ -638,8 +639,6 @@ static void get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) { g_return_if_fail (self); - - /* printf ("DEBUG: %s: list=%p, type=%d\n", __FUNCTION__, list, type); */ ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); @@ -766,13 +765,11 @@ get_server_accounts (TnyAccountStore *self, TnyList *list, TnyAccountType type) iter_account_names = g_slist_next (iter_account_names); } } - - g_slist_free (account_names); + + /* free the account_names */ + modest_account_mgr_free_account_names (account_names); account_names = NULL; - - /* TODO: Delete the strings in the GSList */ - - + /* We also create a per-account local outbox folder (a _store_ account) * for each _transport_ account. */ if (type == TNY_ACCOUNT_TYPE_TRANSPORT) { diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 3009450..d09f01c 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1128,9 +1128,9 @@ modest_ui_actions_do_send_receive_all (ModestWindow *win) modest_ui_actions_do_send_receive ((const char*) iter->data, win); iter = g_slist_next (iter); } - - g_slist_foreach (account_names, (GFunc) g_free, NULL); - g_slist_free (account_names); + + modest_account_mgr_free_account_names (account_names); + account_names = NULL; } /* diff --git a/src/modest-widget-memory.c b/src/modest-widget-memory.c index c9e5b3e..d8bf887 100644 --- a/src/modest-widget-memory.c +++ b/src/modest-widget-memory.c @@ -371,7 +371,7 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view, key = _modest_widget_memory_get_keyname_with_double_type (name, type, style, MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH); sort_key = _modest_widget_memory_get_keyname_with_double_type (name, type, style, - MODEST_WIDGET_MEMORY_PARAM_COLUMN_SORT); + MODEST_WIDGET_MEMORY_PARAM_COLUMN_SORT); if (modest_conf_key_exists (conf, sort_key, NULL)) { gchar *value = modest_conf_get_string (conf, sort_key, NULL); @@ -451,6 +451,8 @@ restore_settings_header_view (ModestConf *conf, ModestHeaderView *header_view, } g_free (key); + g_free (sort_key); + g_object_unref (G_OBJECT (folder)); return TRUE; diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index 236760e..ac1598d 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -207,10 +207,8 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) cursor = account_names = modest_account_mgr_account_names (account_mgr, TRUE /* only enabled accounts. */); - if(account_names == NULL) - { - printf ("debug: modest_account_mgr_account_names() returned NULL\n"); - } + if (!account_names) + g_warning ("debug: modest_account_mgr_account_names() returned NULL\n"); while (cursor) { gchar *account_name; @@ -251,7 +249,9 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view) modest_account_mgr_free_account_data (account_mgr, account_data); cursor = cursor->next; } - g_slist_free (account_names); + + modest_account_mgr_free_account_names (account_names); + account_names = NULL; /* Try to re-select the same account: */ if (selected_name) { diff --git a/src/widgets/modest-header-view-render.c b/src/widgets/modest-header-view-render.c index de70f8f..c5384ca 100644 --- a/src/widgets/modest-header-view-render.c +++ b/src/widgets/modest-header-view-render.c @@ -246,13 +246,13 @@ _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCe header = g_markup_printf_escaped ("%s", (subject && strlen (subject)) ? subject : _("mail_va_no_subject")); g_free (subject); g_object_set (G_OBJECT (subject_cell), "markup", header, NULL); + g_free (header); set_common_flags (subject_cell, flags); - + header = g_markup_printf_escaped ("%s", modest_text_utils_get_display_address (address)); g_free (address); g_object_set (G_OBJECT (recipient_cell), "markup", header, NULL); - - g_object_set (G_OBJECT (recipient_cell), "markup", header, NULL); + g_free (header); set_common_flags (recipient_cell, flags); /* in some rare cases, mail might have no Date: field. it case, @@ -268,8 +268,6 @@ _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCe g_free (tmp_date); g_free (display_date); set_common_flags (date_cell, flags); - - g_free (header); } diff --git a/src/widgets/modest-header-view.c b/src/widgets/modest-header-view.c index 8fea86a..a4b3510 100644 --- a/src/widgets/modest-header-view.c +++ b/src/widgets/modest-header-view.c @@ -1113,14 +1113,8 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2, g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN(user_data), 0); /* col_id = gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (tree_model)); */ col_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(user_data), MODEST_HEADER_VIEW_FLAG_SORT)); + -/* if (!(++counter % 100)) { */ -/* GObject *header_view = g_object_get_data(G_OBJECT(user_data), */ -/* MODEST_HEADER_VIEW_PTR); */ -/* g_signal_emit (header_view, */ -/* signals[STATUS_UPDATE_SIGNAL], */ -/* 0, _("Sorting..."), 0, 0); */ -/* } */ switch (col_id) { case TNY_HEADER_FLAG_ATTACHMENTS: diff --git a/src/widgets/modest-msg-view.c b/src/widgets/modest-msg-view.c index b480ce1..696e268 100644 --- a/src/widgets/modest-msg-view.c +++ b/src/widgets/modest-msg-view.c @@ -1367,7 +1367,7 @@ modest_msg_view_set_message (ModestMsgView *self, TnyMsg *msg) modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW(priv->attachments_view), msg); - body = modest_tny_msg_find_body_part (msg,TRUE); + body = modest_tny_msg_find_body_part (msg, TRUE); if (body) { if (tny_mime_part_content_type_is (body, "text/html")) set_html_message (self, body, msg); -- 1.7.9.5