[evolution-data-server] Don't free vcard memory in e_data_book_view_notify_update*_vcard()



commit 3b48d4f7d985cc44b7cce72c9f001afc4aedf688
Author: Christophe Dumez <christophe dumez intel com>
Date:   Wed Oct 5 10:36:20 2011 +0300

    Don't free vcard memory in e_data_book_view_notify_update*_vcard()
    
    Instead, the vcard memory is freed by the caller which feels more
    consistent with the rest of the code and less error-prone.

 addressbook/backends/file/e-book-backend-file.c |   10 ++++------
 addressbook/libedata-book/e-data-book-view.c    |   15 ++++-----------
 addressbook/libedata-book/e-data-book-view.h    |    4 ++--
 3 files changed, 10 insertions(+), 19 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index f250249..3adeddd 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -909,7 +909,7 @@ static void
 notify_update_vcard (EDataBookView *book_view,
                      gboolean prefiltered,
                      const gchar *id,
-                     gchar *vcard)
+                     const gchar *vcard)
 {
 	if (prefiltered)
 		e_data_book_view_notify_update_prefiltered_vcard (book_view, id, vcard);
@@ -1003,6 +1003,7 @@ book_view_thread (gpointer data)
 			}
 
 			notify_update_vcard (book_view, TRUE, data->uid, vcard);
+			g_free (vcard);
 		}
 
 		g_slist_foreach (summary_list, (GFunc) e_book_backend_sqlitedb_search_data_free, NULL);
@@ -1028,10 +1029,9 @@ book_view_thread (gpointer data)
 				if (strcmp (id_dbt.data, E_BOOK_BACKEND_FILE_VERSION_NAME)) {
 					notify_update_vcard (book_view, allcontacts,
 							     id_dbt.data, vcard_dbt.data);
-				} else {
-					g_free (vcard_dbt.data);
 				}
 
+				g_free (vcard_dbt.data);
 				db_error = dbc->c_get (dbc, &id_dbt, &vcard_dbt, DB_NEXT);
 			}
 
@@ -1695,13 +1695,11 @@ view_notify_update (EDataBookView *view,
 								  fields, &with_all_required_fields, NULL);
 
 		if (vcard) {
-
 			if (with_all_required_fields) {
 				e_data_book_view_notify_update_prefiltered_vcard (view, uid, vcard);
 				notified = TRUE;
-			} else {
-				g_free (vcard);
 			}
+			g_free (vcard);
 		}
 	}
 
diff --git a/addressbook/libedata-book/e-data-book-view.c b/addressbook/libedata-book/e-data-book-view.c
index ca1e969..c39bc62 100644
--- a/addressbook/libedata-book/e-data-book-view.c
+++ b/addressbook/libedata-book/e-data-book-view.c
@@ -432,16 +432,14 @@ e_data_book_view_notify_update (EDataBookView *book_view,
 void
 e_data_book_view_notify_update_vcard (EDataBookView *book_view,
                                       const gchar *id,
-                                      gchar *vcard)
+                                      const gchar *vcard)
 {
 	EDataBookViewPrivate *priv = book_view->priv;
 	gboolean currently_in_view, want_in_view;
 	EContact *contact;
 
-	if (!priv->running) {
-		g_free (vcard);
+	if (!priv->running)
 		return;
-	}
 
 	g_mutex_lock (priv->pending_mutex);
 
@@ -462,7 +460,6 @@ e_data_book_view_notify_update_vcard (EDataBookView *book_view,
 
 	/* Do this last so that id is still valid when notify_ is called */
 	g_object_unref (contact);
-	g_free (vcard);
 
 	g_mutex_unlock (priv->pending_mutex);
 }
@@ -490,15 +487,13 @@ e_data_book_view_notify_update_vcard (EDataBookView *book_view,
 void
 e_data_book_view_notify_update_prefiltered_vcard (EDataBookView *book_view,
                                                   const gchar *id,
-                                                  gchar *vcard)
+                                                  const gchar *vcard)
 {
 	EDataBookViewPrivate *priv = book_view->priv;
 	gboolean currently_in_view;
 
-	if (!priv->running) {
-		g_free (vcard);
+	if (!priv->running)
 		return;
-	}
 
 	g_mutex_lock (priv->pending_mutex);
 
@@ -509,8 +504,6 @@ e_data_book_view_notify_update_prefiltered_vcard (EDataBookView *book_view,
 	else
 		notify_add (book_view, id, vcard);
 
-	g_free (vcard);
-
 	g_mutex_unlock (priv->pending_mutex);
 }
 
diff --git a/addressbook/libedata-book/e-data-book-view.h b/addressbook/libedata-book/e-data-book-view.h
index d535725..405754f 100644
--- a/addressbook/libedata-book/e-data-book-view.h
+++ b/addressbook/libedata-book/e-data-book-view.h
@@ -59,8 +59,8 @@ EBookBackendSExp *	e_data_book_view_get_card_sexp		(EDataBookView *book_view);
 EBookBackend *		e_data_book_view_get_backend		(EDataBookView *book_view);
 void			e_data_book_view_notify_update		(EDataBookView *book_view, const EContact *contact);
 
-void			e_data_book_view_notify_update_vcard	(EDataBookView *book_view, const gchar *id, gchar *vcard);
-void			e_data_book_view_notify_update_prefiltered_vcard (EDataBookView *book_view, const gchar *id, gchar *vcard);
+void			e_data_book_view_notify_update_vcard	(EDataBookView *book_view, const gchar *id, const gchar *vcard);
+void			e_data_book_view_notify_update_prefiltered_vcard (EDataBookView *book_view, const gchar *id, const gchar *vcard);
 
 void			e_data_book_view_notify_remove		(EDataBookView *book_view, const gchar *id);
 void			e_data_book_view_notify_complete	(EDataBookView *book_view, const GError *error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]