summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2020-06-25 11:41:15 +0200
committerMichael Catanzaro <mcatanzaro@gnome.org>2020-06-25 15:59:06 +0000
commitca300c9f439bef880797856a16bab5f8c4637120 (patch)
tree487723527cf954627517ea9283d4da0dcc38fb15
parent5a75e6663d756d0e0f9e37f3067ba866510c5a3f (diff)
downloadepiphany-ca300c9f439bef880797856a16bab5f8c4637120.tar.gz
Fix memory leaks in history query results
Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1178
-rw-r--r--embed/ephy-web-view.c2
-rw-r--r--lib/history/ephy-history-service.c41
-rw-r--r--lib/history/ephy-history-types.c6
-rw-r--r--lib/history/ephy-history-types.h1
-rw-r--r--lib/sync/ephy-history-manager.c1
-rw-r--r--src/ephy-history-dialog.c4
-rw-r--r--tests/ephy-history-test.c3
7 files changed, 37 insertions, 21 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 716711d34..e0b4eebe7 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1159,8 +1159,6 @@ get_host_for_url_cb (gpointer service,
webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW (view), set_zoom);
view->is_setting_zoom = FALSE;
}
-
- ephy_history_host_free (host);
}
static void
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 9c869825d..e9660f8e2 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -79,6 +79,7 @@ typedef struct _EphyHistoryServiceMessage {
gpointer user_data;
GCancellable *cancellable;
GDestroyNotify method_argument_cleanup;
+ GDestroyNotify result_cleanup;
EphyHistoryJobCallback callback;
} EphyHistoryServiceMessage;
@@ -335,6 +336,7 @@ ephy_history_service_message_new (EphyHistoryService *service,
EphyHistoryServiceMessageType type,
gpointer method_argument,
GDestroyNotify method_argument_cleanup,
+ GDestroyNotify result_cleanup,
GCancellable *cancellable,
EphyHistoryJobCallback callback,
gpointer user_data)
@@ -345,6 +347,7 @@ ephy_history_service_message_new (EphyHistoryService *service,
message->type = type;
message->method_argument = method_argument;
message->method_argument_cleanup = method_argument_cleanup;
+ message->result_cleanup = result_cleanup;
message->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
message->callback = callback;
message->user_data = user_data;
@@ -358,6 +361,9 @@ ephy_history_service_message_free (EphyHistoryServiceMessage *message)
if (message->method_argument_cleanup)
message->method_argument_cleanup (message->method_argument);
+ if (message->result_cleanup)
+ message->result_cleanup (message->result);
+
if (message->cancellable)
g_object_unref (message->cancellable);
@@ -698,6 +704,7 @@ ephy_history_service_add_visit (EphyHistoryService *self,
message = ephy_history_service_message_new (self, ADD_VISIT,
ephy_history_page_visit_copy (visit),
(GDestroyNotify)ephy_history_page_visit_free,
+ NULL,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -717,6 +724,7 @@ ephy_history_service_add_visits (EphyHistoryService *self,
message = ephy_history_service_message_new (self, ADD_VISITS,
ephy_history_page_visit_list_copy (visits),
(GDestroyNotify)ephy_history_page_visit_list_free,
+ NULL,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -754,7 +762,10 @@ ephy_history_service_query_visits (EphyHistoryService *self,
g_assert (query != NULL);
message = ephy_history_service_message_new (self, QUERY_VISITS,
- ephy_history_query_copy (query), (GDestroyNotify)ephy_history_query_free, cancellable, callback, user_data);
+ ephy_history_query_copy (query),
+ (GDestroyNotify)ephy_history_query_free,
+ (GDestroyNotify)ephy_history_page_visit_list_free,
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -783,7 +794,9 @@ ephy_history_service_query_urls (EphyHistoryService *self,
g_assert (query != NULL);
message = ephy_history_service_message_new (self, QUERY_URLS,
- ephy_history_query_copy (query), (GDestroyNotify)ephy_history_query_free,
+ ephy_history_query_copy (query),
+ (GDestroyNotify)ephy_history_query_free,
+ (GDestroyNotify)ephy_history_url_list_free,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -799,8 +812,9 @@ ephy_history_service_get_hosts (EphyHistoryService *self,
g_assert (EPHY_IS_HISTORY_SERVICE (self));
message = ephy_history_service_message_new (self, GET_HOSTS,
- NULL, NULL, cancellable,
- callback, user_data);
+ NULL, NULL,
+ (GDestroyNotify)ephy_history_host_list_free,
+ cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -818,6 +832,7 @@ ephy_history_service_query_hosts (EphyHistoryService *self,
message = ephy_history_service_message_new (self, QUERY_HOSTS,
ephy_history_query_copy (query),
(GDestroyNotify)ephy_history_query_free,
+ (GDestroyNotify)ephy_history_host_list_free,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -879,7 +894,7 @@ ephy_history_service_set_url_title (EphyHistoryService *self,
url = ephy_history_url_new (orig_url, title, 0, 0, 0);
message = ephy_history_service_message_new (self, SET_URL_TITLE,
url, (GDestroyNotify)ephy_history_url_free,
- cancellable, callback, user_data);
+ NULL, cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -927,7 +942,7 @@ ephy_history_service_set_url_zoom_level (EphyHistoryService *self,
message = ephy_history_service_message_new (self, SET_URL_ZOOM_LEVEL,
variant, (GDestroyNotify)g_variant_unref,
- cancellable, callback, user_data);
+ NULL, cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -969,7 +984,7 @@ ephy_history_service_set_url_hidden (EphyHistoryService *self,
message = ephy_history_service_message_new (self, SET_URL_HIDDEN,
url, (GDestroyNotify)ephy_history_url_free,
- cancellable, callback, user_data);
+ NULL, cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -1000,7 +1015,7 @@ ephy_history_service_get_url (EphyHistoryService *self,
g_assert (url != NULL);
message = ephy_history_service_message_new (self, GET_URL,
- g_strdup (url), g_free,
+ g_strdup (url), g_free, (GDestroyNotify)ephy_history_url_free,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -1033,7 +1048,7 @@ ephy_history_service_get_host_for_url (EphyHistoryService *self,
g_assert (url != NULL);
message = ephy_history_service_message_new (self, GET_HOST_FOR_URL,
- g_strdup (url), g_free,
+ g_strdup (url), g_free, (GDestroyNotify)ephy_history_host_free,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -1138,7 +1153,7 @@ ephy_history_service_delete_urls (EphyHistoryService *self,
message = ephy_history_service_message_new (self, DELETE_URLS,
ephy_history_url_list_copy (urls), (GDestroyNotify)ephy_history_url_list_free,
- cancellable, callback, user_data);
+ NULL, cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -1152,7 +1167,7 @@ ephy_history_service_delete_host (EphyHistoryService *self,
EphyHistoryServiceMessage *message =
ephy_history_service_message_new (self, DELETE_HOST,
ephy_history_host_copy (host), (GDestroyNotify)ephy_history_host_free,
- cancellable, callback, user_data);
+ NULL, cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -1167,7 +1182,7 @@ ephy_history_service_clear (EphyHistoryService *self,
g_assert (EPHY_IS_HISTORY_SERVICE (self));
message = ephy_history_service_message_new (self, CLEAR,
- NULL, NULL,
+ NULL, NULL, NULL,
cancellable, callback, user_data);
ephy_history_service_send_message (self, message);
}
@@ -1179,7 +1194,7 @@ ephy_history_service_quit (EphyHistoryService *self,
{
EphyHistoryServiceMessage *message =
ephy_history_service_message_new (self, QUIT,
- NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
callback, user_data);
ephy_history_service_send_message (self, message);
}
diff --git a/lib/history/ephy-history-types.c b/lib/history/ephy-history-types.c
index 9a806f7fd..b1b4b5ba2 100644
--- a/lib/history/ephy-history-types.c
+++ b/lib/history/ephy-history-types.c
@@ -126,6 +126,12 @@ ephy_history_host_free (EphyHistoryHost *host)
g_free (host);
}
+void
+ephy_history_host_list_free (GList *list)
+{
+ g_list_free_full (list, (GDestroyNotify)ephy_history_host_free);
+}
+
EphyHistoryURL *
ephy_history_url_new (const char *url,
const char *title,
diff --git a/lib/history/ephy-history-types.h b/lib/history/ephy-history-types.h
index 692ab50c9..20dacfbdf 100644
--- a/lib/history/ephy-history-types.h
+++ b/lib/history/ephy-history-types.h
@@ -105,6 +105,7 @@ void ephy_history_page_visit_list_free (GList* list);
EphyHistoryHost * ephy_history_host_new (const char *url, const char *title, int visit_count, double zoom_level);
EphyHistoryHost * ephy_history_host_copy (EphyHistoryHost *original);
void ephy_history_host_free (EphyHistoryHost *host);
+void ephy_history_host_list_free (GList *list);
EphyHistoryURL * ephy_history_url_new (const char *url, const char *title, int visit_count, int typed_count, gint64 last_visit_time);
EphyHistoryURL * ephy_history_url_copy (EphyHistoryURL *url);
diff --git a/lib/sync/ephy-history-manager.c b/lib/sync/ephy-history-manager.c
index df94e2034..bffcd1ca3 100644
--- a/lib/sync/ephy-history-manager.c
+++ b/lib/sync/ephy-history-manager.c
@@ -513,7 +513,6 @@ merge_history_cb (EphyHistoryService *service,
out:
data->callback (to_upload, data->user_data);
- g_list_free_full (urls, (GDestroyNotify)ephy_history_url_free);
if (records_ht_id)
g_hash_table_unref (records_ht_id);
if (records_ht_url)
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 7f9e9f6db..306dc9b73 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -113,7 +113,7 @@ on_find_urls_cb (gpointer service,
if (!success)
return;
- self->urls = (GList *)result_data;
+ self->urls = ephy_history_url_list_copy (result_data);
clear_listbox (self->listbox);
@@ -149,7 +149,7 @@ remove_pending_sorter_source (EphyHistoryDialog *self,
g_clear_handle_id (&self->sorter_source, g_source_remove);
if (free_urls && self->urls) {
- g_list_free_full (self->urls, (GDestroyNotify)ephy_history_url_free);
+ ephy_history_host_list_free (self->urls);
self->urls = NULL;
}
}
diff --git a/tests/ephy-history-test.c b/tests/ephy-history-test.c
index 1497e8cd5..be168aebc 100644
--- a/tests/ephy-history-test.c
+++ b/tests/ephy-history-test.c
@@ -159,7 +159,6 @@ verify_create_history_entry_cb (EphyHistoryService *service,
current_baseline = current_baseline->next;
}
- ephy_history_page_visit_list_free (visits);
ephy_history_page_visit_list_free (baseline_visits);
g_object_unref (service);
@@ -204,7 +203,6 @@ get_url (EphyHistoryService *service,
g_assert_nonnull (url);
g_assert_cmpstr (url->title, ==, "GNOME");
- ephy_history_url_free (url);
g_object_unref (service);
gtk_main_quit ();
}
@@ -296,7 +294,6 @@ test_get_url_done (EphyHistoryService *service,
g_assert_nonnull (url);
g_assert_cmpstr (url->url, ==, "http://www.gnome.org");
g_assert_cmpint (url->id, !=, -1);
- ephy_history_url_free (url);
} else
g_assert_null (url);