libreport/0003-gui-wizard-gtk-Fix-a-double-free-condition.patch

54 lines
1.9 KiB
Diff
Raw Normal View History

2020-09-25 17:34:08 +00:00
From ce557c0fb309184a9a8fc38a76404324d94803b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20Grabovsk=C3=BD?= <mgrabovs@redhat.com>
Date: Fri, 25 Sep 2020 19:23:51 +0200
Subject: [PATCH] gui-wizard-gtk: Fix a double free condition
We may only free `log_msg` in `update_command_run_log()` if it is the
result of the call to `g_strdup_printf()`, otherwise the caller takes
care of it.
Partially reverts 7aba6e53.
Resolves rhbz#1882319
---
src/gui-wizard-gtk/wizard.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index 8a4486f2..a532c633 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -1385,7 +1385,7 @@ static void cancel_processing(GtkLabel *status_label, const char *message, int t
pango_attr_list_unref(list);
}
-static void update_command_run_log(const char* message, struct analyze_event_data *evd)
+static void update_command_run_log(char *message, struct analyze_event_data *evd)
{
const bool it_is_a_dot = (message[0] == '.' && message[1] == '\0');
@@ -1393,12 +1393,18 @@ static void update_command_run_log(const char* message, struct analyze_event_dat
gtk_label_set_text(g_lbl_event_log, message);
/* Don't append new line behind single dot */
- g_autofree const char *log_msg = it_is_a_dot ? message : g_strdup_printf("%s\n", message);
+ char *log_msg = it_is_a_dot ? message : g_strdup_printf("%s\n", message);
append_to_textview(g_tv_event_log, log_msg);
save_to_event_log(evd, log_msg);
+
+ if (log_msg != message)
+ {
+ /* We assume message is managed by the caller. */
+ free(log_msg);
+ }
}
-static void run_event_gtk_error(const char *error_line, void *param)
+static void run_event_gtk_error(char *error_line, void *param)
{
update_command_run_log(error_line, (struct analyze_event_data *)param);
}
--
2.26.2