[evolution-data-server] build_sqlitedb: Fix memory leaks and optimize function
- From: Christophe Dumez <cdumez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] build_sqlitedb: Fix memory leaks and optimize function
- Date: Fri, 7 Oct 2011 10:57:56 +0000 (UTC)
commit fb5445569e55d5eb48198f99272fd28d06db7922
Author: Christophe Dumez <christophe dumez intel com>
Date: Wed Oct 5 09:26:05 2011 +0300
build_sqlitedb: Fix memory leaks and optimize function
This patch fixes 2 possible memory leaks in build_sqlitedb()
function, makes use of e_util_free_object_slist() utility function,
slightly improves error checking and makes some minor optimizations.
addressbook/backends/file/e-book-backend-file.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 4ac347b..c0c055d 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -210,9 +210,10 @@ build_sqlitedb (EBookBackendFilePrivate *bfpriv)
DBT id_dbt, vcard_dbt;
GSList *contacts = NULL;
GError *error = NULL;
+ gboolean skipped_version = FALSE;
if (!db) {
- g_warning (G_STRLOC ": Not openend yet");
+ g_warning (G_STRLOC ": Not opened yet");
return FALSE;
}
@@ -228,33 +229,39 @@ build_sqlitedb (EBookBackendFilePrivate *bfpriv)
db_error = dbc->c_get (dbc, &id_dbt, &vcard_dbt, DB_FIRST);
while (db_error == 0) {
-
/* don't include the version in the list of cards */
- if (id_dbt.size != strlen (E_BOOK_BACKEND_FILE_VERSION_NAME) + 1
- || strcmp (id_dbt.data, E_BOOK_BACKEND_FILE_VERSION_NAME)) {
+ if (skipped_version || strcmp (id_dbt.data, E_BOOK_BACKEND_FILE_VERSION_NAME)) {
EContact *contact = create_contact (id_dbt.data, vcard_dbt.data);
contacts = g_slist_prepend (contacts, contact);
+ } else {
+ skipped_version = TRUE;
}
+ g_free (vcard_dbt.data);
db_error = dbc->c_get (dbc, &id_dbt, &vcard_dbt, DB_NEXT);
}
dbc->c_close (dbc);
- contacts = g_slist_reverse (contacts);
+ /* Detect error case */
+ if (db_error != DB_NOTFOUND) {
+ g_warning (G_STRLOC ": dbc->c_get failed with %s", db_strerror (db_error));
+ e_util_free_object_slist (contacts);
+ return FALSE;
+ }
if (!e_book_backend_sqlitedb_add_contacts (bfpriv->sqlitedb,
SQLITEDB_FOLDER_ID,
contacts, FALSE, &error)) {
g_warning ("Failed to build contact summary: %s", error->message);
g_error_free (error);
+ e_util_free_object_slist (contacts);
return FALSE;
}
- g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
- g_slist_free (contacts);
+ e_util_free_object_slist (contacts);
if (!e_book_backend_sqlitedb_set_is_populated (bfpriv->sqlitedb, SQLITEDB_FOLDER_ID, TRUE, &error)) {
g_warning ("Failed to set the sqlitedb populated flag: %s", error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]