[gnome-software: 6/7] gs-app: Change gs_app_get_version_history() to return a ref
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 6/7] gs-app: Change gs_app_get_version_history() to return a ref
- Date: Fri, 30 Apr 2021 12:08:49 +0000 (UTC)
commit a00ab0a87799c62211efdcfef16849c905238899
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 f52bb2c76..877ed1008 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -5353,17 +5353,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 6f8520f76..6ac309da9 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1237,7 +1237,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;
/* change widgets */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]