[gnome-software/gnome-40: 6/7] gs-app: Change gs_app_get_version_history() to return a ref
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-40: 6/7] gs-app: Change gs_app_get_version_history() to return a ref
- Date: Mon, 3 May 2021 10:44:31 +0000 (UTC)
commit bb1cc3a52fca7e98b053f4c9751df28bfd505dec
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Apr 29 15:52:43 2021 +0100
gs-app: Change gs_app_get_version_history() to return a ref
It seems the version history can be updated from a separate thread while
refreshing. This can cause crashes if the UI thread queries the version
history, then it’s updated from another thread, then the UI thread
starts iterating over the `GPtrArray` it queried — which has since been
freed.
Fix that by returning a strong ref to the `GPtrArray`, and doing so
under the app’s mutex.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #1227
lib/gs-app.c | 11 ++++++++---
src/gs-app-version-history-dialog.c | 2 +-
src/gs-details-page.c | 2 +-
3 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index efbc4756a..f165df562 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -5341,17 +5341,22 @@ gs_app_set_update_permissions (GsApp *app, GsAppPermissions update_permissions)
* Gets the list of past releases for an application (including the latest
* one).
*
- * Returns: (element-type AsRelease) (transfer none) (nullable): a list, or
+ * Returns: (element-type AsRelease) (transfer container) (nullable): a list, or
* %NULL if the version history is not known
*
- * Since: 40
+ * Since: 41
**/
GPtrArray *
gs_app_get_version_history (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
+ g_autoptr(GMutexLocker) locker = NULL;
g_return_val_if_fail (GS_IS_APP (app), NULL);
- return priv->version_history;
+
+ locker = g_mutex_locker_new (&priv->mutex);
+ if (priv->version_history == NULL)
+ return NULL;
+ return g_ptr_array_ref (priv->version_history);
}
/**
diff --git a/src/gs-app-version-history-dialog.c b/src/gs-app-version-history-dialog.c
index 5262596a2..8b61b7c2b 100644
--- a/src/gs-app-version-history-dialog.c
+++ b/src/gs-app-version-history-dialog.c
@@ -28,7 +28,7 @@ static void
populate_version_history (GsAppVersionHistoryDialog *dialog,
GsApp *app)
{
- GPtrArray *version_history;
+ g_autoptr(GPtrArray) version_history = NULL;
/* remove previous */
gs_container_remove_all (GTK_CONTAINER (dialog->listbox));
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 22b38e929..c985f3b06 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1191,7 +1191,7 @@ gs_details_page_refresh_all (GsDetailsPage *self)
guint64 user_integration_bf;
gboolean show_support_box = FALSE;
g_autofree gchar *origin = NULL;
- GPtrArray *version_history;
+ g_autoptr(GPtrArray) version_history = NULL;
guint icon_size;
if (!gs_page_is_active (GS_PAGE (self)))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]