Fix several memory leaks around template parsing.
authorAndrej Kacian <ticho@claws-mail.org>
Tue, 11 Jul 2017 16:37:54 +0000 (18:37 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 11 Jul 2017 16:37:54 +0000 (18:37 +0200)
FLEX-generated quote_fmt_scan_string() allocates a buffer
(and actually returns a pointer to it, although its prototype
in quote_fmt.h says its return value is void), which needs
to be cleaned up afterwards.

src/compose.c
src/prefs_template.c
src/quote_fmt.h

index 21e690ae13ebea2e5c8e7fe345823870e768efab..4dfb9622d57134a9593db5238b0158baae403c63 100644 (file)
@@ -1084,6 +1084,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        else
                                gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                        quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
 
                        g_free(tmp);
                }
@@ -1177,6 +1178,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
                        compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                        quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
 
                        g_free(subject);
                        g_free(tmp);
@@ -1652,6 +1654,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                else
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
 
                g_free(tmp);
        }
@@ -1834,6 +1837,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                else
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
 
                g_free(tmp);
                procmsg_msginfo_free(&full_msginfo);
@@ -2025,6 +2029,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
                        else
                                gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                        quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
 
                        g_free(tmp);
                }
@@ -3125,6 +3130,10 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                quote_fmt_parse();
 
                buf = quote_fmt_get_buffer();
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
+
                if (buf == NULL)
                        alertpanel_error(_("The \"Quotation mark\" of the template is invalid."));
                else
@@ -3158,11 +3167,18 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                }
 
                buf = quote_fmt_get_buffer();
+
                if (buf == NULL) {
                        gint line = quote_fmt_get_line();
                        alertpanel_error(err_msg, line);
+                       quote_fmt_reset_vartable();
+                       quote_fmtlex_destroy();
+
                        goto error;
                }
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
+
        } else
                buf = "";
 
@@ -8882,6 +8898,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->to && *tmpl->to != '\0') {
@@ -8900,6 +8919,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_TO, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->cc && *tmpl->cc != '\0') {
@@ -8918,6 +8940,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_CC, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->bcc && *tmpl->bcc != '\0') {
@@ -8936,6 +8961,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_BCC, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        if (tmpl->replyto && *tmpl->replyto != '\0') {
@@ -8954,6 +8982,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        compose_entry_append(compose, buf, COMPOSE_REPLYTO, PREF_TEMPLATE);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        /* process the subject */
@@ -8973,6 +9004,9 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                } else {
                        gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
                }
+
+               quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
 
        procmsg_msginfo_free( &dummyinfo );
index 9e2f28e719b39716d71255dd007031185598dcca..e8f656de441b509e52fe5437da89de1cf862215a 100644 (file)
@@ -714,9 +714,11 @@ gboolean prefs_template_string_is_valid(gchar *string, gint *line, gboolean esca
                if (!parsed_buf) {
                        if (line)
                                *line = quote_fmt_get_line();
+                       quote_fmtlex_destroy();
                        return FALSE;
                }
                quote_fmt_reset_vartable();
+               quote_fmtlex_destroy();
        }
        return result;
 }
index b0112c501c3680badb1870699aef42bdf7884d57..900adeab25e75ba01571ab735c82f286cc1fad2a 100644 (file)
@@ -45,6 +45,7 @@ void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
                        gboolean escaped_string);
 #endif
 gint quote_fmtparse(void);
+int quote_fmtlex_destroy(void);
 void quote_fmt_scan_string(const gchar *str);
 void quote_fmt_reset_vartable(void);
 gint quote_fmt_get_cursor_pos(void);