vcl/unx/gtk3/gtkinst.cxx | 4 ++++ 1 file changed, 4 insertions(+) New commits: commit 9490f58df1c298de18bfea5e7baf425fafe66594 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Mar 21 23:21:23 2025 -0700 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Mar 22 16:59:08 2025 +0100
gtk3: Fix memory leak in GtkInstanceBuilder::postprocess_widget While `gtk_widget_get_tooltip_text` returns a `const char*` owned by the instance for GTK 4 [1], it returns a `gchar*` for which the caller takes ownership for GTK 3 [2]. Use `g_autofree` so it automatically gets freed. This fixes this memory leak reported by valgrind: ==499478== 780 bytes in 34 blocks are definitely lost in loss record 18,648 of 19,759 ==499478== at 0x4844818: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==499478== by 0x1306B2C1: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8400.0) ==499478== by 0x13087E72: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8400.0) ==499478== by 0x12FE6D7A: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.8400.0) ==499478== by 0x12FC58BB: g_object_get_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.8400.0) ==499478== by 0x12FC5DB4: g_object_get (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.8400.0) ==499478== by 0x18C7A79D: gtk_widget_get_tooltip_text (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.2417.32) ==499478== by 0x186F2E37: (anonymous namespace)::GtkInstanceBuilder::postprocess_widget(_GtkWidget*) (gtkinst.cxx:24221) ==499478== by 0x186ECC70: (anonymous namespace)::GtkInstanceBuilder::postprocess(void*, void*) (gtkinst.cxx:24339) ==499478== by 0x1308714F: g_slist_foreach (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8400.0) ==499478== by 0x186EC3ED: (anonymous namespace)::GtkInstanceBuilder::GtkInstanceBuilder(_GtkWidget*, std::basic_string_view<char16_t, std::char_traits<char16_t> >, rtl::OUString const&, SystemChildWindow*, bool) (gtkinst.cxx:24422) ==499478== by 0x186D3039: std::__detail::_MakeUniq<(anonymous namespace)::GtkInstanceBuilder>::__single_object std::make_unique<(anonymous namespace)::GtkInstanceBuilder, _GtkWidget*&, rtl::OUString const&, rtl::OUString const&, decltype(nullptr), bool>(_GtkWidget*&, rtl::OUString const&, rtl::OUString const&, decltype(nullptr)&&, bool&&) (unique_ptr.h:1077) [1] https://docs.gtk.org/gtk4/method.Widget.get_tooltip_text.html [2] https://docs.gtk.org/gtk3/method.Widget.get_tooltip_text.html Change-Id: I36ce82565f07227683477b682b34dbd77e806478 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183216 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index b320850ad6c0..989f51996b22 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -24218,7 +24218,11 @@ private: if (m_pStringReplace) { // tdf#136498 %PRODUCTNAME shown in tool tips +#if GTK_CHECK_VERSION(4, 0, 0) const char* pTooltip = gtk_widget_get_tooltip_text(pWidget); +#else + g_autofree char* pTooltip = gtk_widget_get_tooltip_text(pWidget); +#endif if (pTooltip && pTooltip[0]) { OUString aTooltip(pTooltip, strlen(pTooltip), RTL_TEXTENCODING_UTF8);