diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 93d5f8a..8cb1cd8 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -3822,7 +3822,11 @@ e_book_backend_ldap_build_query (EBookBackendLDAP *bl,
 	}
 
 	e_sexp_input_text (sexp, query, strlen (query));
-	e_sexp_parse (sexp);
+	if (e_sexp_parse (sexp) == -1) {
+		g_warning ("%s: Error in parsing '%s': %s", G_STRFUNC, query, e_sexp_get_error (sexp));
+		g_object_unref (sexp);
+		return NULL;
+	}
 
 	r = e_sexp_eval (sexp);
 
diff --git a/addressbook/libebook-contacts/e-book-query.c b/addressbook/libebook-contacts/e-book-query.c
index 3604bae..38a3ec3 100644
--- a/addressbook/libebook-contacts/e-book-query.c
+++ b/addressbook/libebook-contacts/e-book-query.c
@@ -777,6 +777,7 @@ e_book_query_from_string (const gchar *query_string)
 
 	if (e_sexp_parse (sexp) == -1) {
 		g_warning ("%s: Error in parsing: %s", G_STRFUNC, e_sexp_get_error (sexp));
+		g_object_unref (sexp);
 		return NULL;
 	}
 
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 2f51d2d..18568c8 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -3318,6 +3318,7 @@ e_book_backend_sqlitedb_check_summary_query_locked (EBookBackendSqliteDB *ebsdb,
 	if (esexp_error == -1) {
 		if (invalid_query)
 			*invalid_query = TRUE;
+		g_object_unref (sexp);
 
 		return FALSE;
 	}
diff --git a/addressbook/libedata-book/e-book-backend-summary.c b/addressbook/libedata-book/e-book-backend-summary.c
index 2275548..ba59c9f 100644
--- a/addressbook/libedata-book/e-book-backend-summary.c
+++ b/addressbook/libedata-book/e-book-backend-summary.c
@@ -1273,6 +1273,7 @@ e_book_backend_summary_search (EBookBackendSummary *summary,
 	esexp_error = e_sexp_parse (sexp);
 
 	if (esexp_error == -1) {
+		g_object_unref (sexp);
 		return NULL;
 	}
 
diff --git a/camel/camel-db.c b/camel/camel-db.c
index f21c359..71b06a6 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -2263,7 +2263,7 @@ cdb_delete_ids (CamelDB *cdb,
                 GError **error)
 {
 	gchar *tmp;
-	gint ret = 0;
+	gint ret;
 	gboolean first = TRUE;
 	GString *str = g_string_new ("DELETE FROM ");
 	GList *iterator;
@@ -2294,7 +2294,7 @@ cdb_delete_ids (CamelDB *cdb,
 
 	g_string_append (str, ")");
 
-	ret = ret == -1 ? ret : camel_db_add_to_transaction (cdb, str->str, error);
+	ret = camel_db_add_to_transaction (cdb, str->str, error);
 
 	if (ret == -1)
 		camel_db_abort_transaction (cdb, NULL);
diff --git a/libedataserverui/e-webdav-discover-widget.c b/libedataserverui/e-webdav-discover-widget.c
index 984455f..3fe9dc7 100644
--- a/libedataserverui/e-webdav-discover-widget.c
+++ b/libedataserverui/e-webdav-discover-widget.c
@@ -646,7 +646,7 @@ e_webdav_discover_content_trust_prompt_done_cb (GObject *source_object,
 			e_webdav_discover_content_refresh_done_cb, rd);
 	} else {
 		g_cancellable_cancel (rd->cancellable);
-		g_cancellable_set_error_if_cancelled (rd->cancellable, &local_error);
+		g_warn_if_fail (g_cancellable_set_error_if_cancelled (rd->cancellable, &local_error));
 		g_simple_async_result_take_error (rd->simple, local_error);
 		local_error = NULL;
 		g_simple_async_result_complete (rd->simple);
diff --git a/tools/addressbook-export/addressbook-export.c b/tools/addressbook-export/addressbook-export.c
index 7c19614..0ce10b0 100644
--- a/tools/addressbook-export/addressbook-export.c
+++ b/tools/addressbook-export/addressbook-export.c
@@ -80,7 +80,7 @@ action_list_folders_init (ActionContext *p_actctx)
 		EBookClient *book_client;
 		EBookQuery *query;
 		ESource *source;
-		GSList *contacts;
+		GSList *contacts = NULL;
 		const gchar *display_name;
 		const gchar *uid;
 		gchar *query_str;
@@ -110,8 +110,8 @@ action_list_folders_init (ActionContext *p_actctx)
 		query_str = e_book_query_to_string (query);
 		e_book_query_unref (query);
 
-		e_book_client_get_contacts_sync (
-			book_client, query_str, &contacts, NULL, NULL);
+		if (!e_book_client_get_contacts_sync (book_client, query_str, &contacts, NULL, NULL))
+			contacts = NULL;
 
 		display_name = e_source_get_display_name (source);
 		uid = e_source_get_uid (source);
@@ -125,9 +125,7 @@ action_list_folders_init (ActionContext *p_actctx)
 				"\"%s\",\"%s\",%d\n",
 				uid, display_name, g_slist_length (contacts));
 
-		g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
-		g_slist_free (contacts);
-
+		g_slist_free_full (contacts, g_object_unref);
 		g_object_unref (book_client);
 	}
 
@@ -806,7 +804,7 @@ action_list_cards_init (ActionContext *p_actctx)
 	EBookClient *book_client;
 	EBookQuery *query;
 	ESource *source;
-	GSList *contacts;
+	GSList *contacts = NULL;
 	const gchar *uid;
 	gchar *query_str;
 	GError *error = NULL;
@@ -853,13 +851,11 @@ action_list_cards_init (ActionContext *p_actctx)
 	query_str = e_book_query_to_string (query);
 	e_book_query_unref (query);
 
-	e_book_client_get_contacts_sync (
-		book_client, query_str, &contacts, NULL, &error);
-
-	action_list_cards (contacts, p_actctx);
+	if (e_book_client_get_contacts_sync (book_client, query_str, &contacts, NULL, &error)) {
+		action_list_cards (contacts, p_actctx);
+		g_slist_free_full (contacts, g_object_unref);
+	}
 
-	g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
-	g_slist_free (contacts);
 	g_object_unref (book_client);
 
 	if (error != NULL) {
