From f606d3c31ea117f7b9cb187f3521c7051a8db2ba Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 20 Feb 2008 04:24:29 +0000 Subject: [PATCH] (popup_messages): Always destroy `msg' and `lead' strings, avoiding a memory leak. Thanks to John Darrington for reporting the problem. --- src/ui/gui/ChangeLog | 6 ++++++ src/ui/gui/message-dialog.c | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index 23004c9a..e414a71b 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,9 @@ +2008-02-19 Ben Pfaff + + * message-dialog.c (popup_messages): Always destroy `msg' and + `lead' strings, avoiding a memory leak. Thanks to John Darrington + for reporting the problem. + 2008-02-19 John Darrington * dict-display.c: Display names of variables in dialog box diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index 525fca40..75f8cfdc 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -189,7 +189,8 @@ popup_messages (gpointer unused UNUSED) GtkTextIter end; GtkTextView *text_view; GtkLabel *label; - struct string lead, msg; + struct string lead = DS_EMPTY_INITIALIZER; + struct string msg = DS_EMPTY_INITIALIZER; int message_cnt; /* If a pointer grab is in effect, then the combination of that, and @@ -201,7 +202,6 @@ popup_messages (gpointer unused UNUSED) /* Compose the lead-in. */ message_cnt = error_cnt + warning_cnt + note_cnt; - ds_init_empty (&lead); if (dropped_messages == 0) ds_put_format ( &lead, @@ -227,7 +227,6 @@ popup_messages (gpointer unused UNUSED) /* Compose the messages. */ - ds_init_empty (&msg); while (!g_queue_is_empty (early_queue)) format_message (g_queue_pop_head (early_queue), &msg); if (dropped_messages) @@ -246,7 +245,6 @@ popup_messages (gpointer unused UNUSED) text_buffer = gtk_text_buffer_new (NULL); gtk_text_buffer_get_end_iter (text_buffer, &end); gtk_text_buffer_insert (text_buffer, &end, ds_data (&msg), ds_length (&msg)); - ds_destroy (&msg); label = GTK_LABEL (get_widget_assert (message_xml, "lead-in")); if (label == NULL) @@ -261,6 +259,9 @@ popup_messages (gpointer unused UNUSED) gtk_dialog_run (message_dialog); gtk_widget_hide (GTK_WIDGET (message_dialog)); + ds_destroy (&lead); + ds_destroy (&msg); + return FALSE; use_fallback: -- 2.30.2