summaryrefslogtreecommitdiff
path: root/libyelp/yelp-document.c
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2017-02-07 18:55:01 -0800
committerChristian Hergert <chergert@redhat.com>2017-02-07 18:57:47 -0800
commit7d8ee5a1478a00af3e14fd8c563b7ae271723e79 (patch)
treea8fbfed6085862f28f533cde0817d6c73c39dc6c /libyelp/yelp-document.c
parent9dd95badfabe079291d01512319650cef0c9e619 (diff)
downloadyelp-7d8ee5a1478a00af3e14fd8c563b7ae271723e79.tar.gz
document: add destroy notify to page callback
This ensures that we only free the async data struct when the document is guaranteed to be done calling our callback. Without this, we risk potentially accessing the async request data after we have freed it when a mallard document reloads. https://bugzilla.gnome.org/show_bug.cgi?id=778258
Diffstat (limited to 'libyelp/yelp-document.c')
-rw-r--r--libyelp/yelp-document.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index f26ebd2b..547ef24d 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -51,6 +51,7 @@ struct _Request {
GCancellable *cancellable;
YelpDocumentCallback callback;
gpointer user_data;
+ GDestroyNotify notify;
GError *error;
gint idle_funcs;
@@ -113,7 +114,8 @@ static gboolean document_request_page (YelpDocument *document,
const gchar *page_id,
GCancellable *cancellable,
YelpDocumentCallback callback,
- gpointer user_data);
+ gpointer user_data,
+ GDestroyNotify notify);
static gboolean document_indexed (YelpDocument *document);
static const gchar * document_read_contents (YelpDocument *document,
const gchar *page_id);
@@ -810,7 +812,8 @@ yelp_document_request_page (YelpDocument *document,
const gchar *page_id,
GCancellable *cancellable,
YelpDocumentCallback callback,
- gpointer user_data)
+ gpointer user_data,
+ GDestroyNotify notify)
{
g_return_val_if_fail (YELP_IS_DOCUMENT (document), FALSE);
g_return_val_if_fail (YELP_DOCUMENT_GET_CLASS (document)->request_page != NULL, FALSE);
@@ -821,7 +824,8 @@ yelp_document_request_page (YelpDocument *document,
page_id,
cancellable,
callback,
- user_data);
+ user_data,
+ notify);
}
static gboolean
@@ -829,7 +833,8 @@ document_request_page (YelpDocument *document,
const gchar *page_id,
GCancellable *cancellable,
YelpDocumentCallback callback,
- gpointer user_data)
+ gpointer user_data,
+ GDestroyNotify notify)
{
Request *request;
gchar *real_id;
@@ -855,6 +860,7 @@ document_request_page (YelpDocument *document,
request->callback = callback;
request->user_data = user_data;
+ request->notify = notify;
request->idle_funcs = 0;
g_mutex_lock (&document->priv->mutex);
@@ -1510,6 +1516,9 @@ request_try_free (Request *request)
static void
request_free (Request *request)
{
+ if (request->notify)
+ request->notify (request->user_data);
+
g_object_unref (request->document);
g_free (request->page_id);
g_object_unref (request->cancellable);