From 6f5d119539bd88b09c358210edbc66256d9e192d Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 26 Nov 2024 21:46:54 -0800 Subject: [PATCH] libsysprof: guard message string and dup contents --- src/libsysprof/sysprof-document-loader.c | 31 +++++++++++++++++++++--- src/libsysprof/sysprof-document-loader.h | 4 ++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/libsysprof/sysprof-document-loader.c b/src/libsysprof/sysprof-document-loader.c index 5429aa67..60266939 100644 --- a/src/libsysprof/sysprof-document-loader.c +++ b/src/libsysprof/sysprof-document-loader.c @@ -263,7 +263,7 @@ sysprof_document_loader_get_property (GObject *object, break; case PROP_MESSAGE: - g_value_set_string (value, sysprof_document_loader_get_message (self)); + g_value_take_string (value, sysprof_document_loader_dup_message (self)); break; case PROP_SYMBOLIZER: @@ -445,14 +445,39 @@ sysprof_document_loader_get_fraction (SysprofDocumentLoader *self) * This only updates between calls of sysprof_document_loader_load_async() * and sysprof_document_loader_load_finish(). * - * Returns: (nullable): a string containing a load message + * Returns: (nullable): %NULL */ const char * sysprof_document_loader_get_message (SysprofDocumentLoader *self) { g_return_val_if_fail (SYSPROF_IS_DOCUMENT_LOADER (self), NULL); - return self->message; + return NULL; +} + +/** + * sysprof_document_loader_dup_message: + * @self: a #SysprofDocumentLoader + * + * Gets a text message representing what is happenin with loading. + * + * This only updates between calls of sysprof_document_loader_load_async() + * and sysprof_document_loader_load_finish(). + * + * Returns: (nullable) (transfer full): a string or %NULL + */ +char * +sysprof_document_loader_dup_message (SysprofDocumentLoader *self) +{ + char *ret; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_LOADER (self), NULL); + + g_mutex_lock (&self->mutex); + ret = g_strdup (self->message); + g_mutex_unlock (&self->mutex); + + return ret; } static void diff --git a/src/libsysprof/sysprof-document-loader.h b/src/libsysprof/sysprof-document-loader.h index 1a1ea7da..c47baa4c 100644 --- a/src/libsysprof/sysprof-document-loader.h +++ b/src/libsysprof/sysprof-document-loader.h @@ -46,7 +46,9 @@ void sysprof_document_loader_set_symbolizer (SysprofDocumentLo SysprofSymbolizer *symbolizer); SYSPROF_AVAILABLE_IN_ALL double sysprof_document_loader_get_fraction (SysprofDocumentLoader *self); -SYSPROF_AVAILABLE_IN_ALL +SYSPROF_AVAILABLE_IN_48 +char *sysprof_document_loader_dup_message (SysprofDocumentLoader *self); +SYSPROF_DEPRECATED_IN_48_FOR(sysprof_document_loader_dup_message) const char *sysprof_document_loader_get_message (SysprofDocumentLoader *self); SYSPROF_AVAILABLE_IN_48 GListModel *sysprof_document_loader_list_tasks (SysprofDocumentLoader *self);