Fix a memory leak in summary_set_header().
authorAndrej Kacian <ticho@claws-mail.org>
Fri, 3 Aug 2018 12:02:38 +0000 (14:02 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Fri, 3 Aug 2018 12:02:38 +0000 (14:02 +0200)
src/summaryview.c

index 9bf442054fb200b51aa8f09fc40f0ec50abab383..306972c4f2195f113e5d183207ebd0f7d2ae4556 100644 (file)
@@ -3481,9 +3481,16 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
        if (!to_text)
                to_text = _("(No Recipient)");
        else {
-               if (prefs_common.summary_from_show == SHOW_NAME)
-                       to_text = procheader_get_fromname(to_text);
-               else if (prefs_common.summary_from_show == SHOW_ADDR)
+               if (prefs_common.summary_from_show == SHOW_NAME) {
+                       gchar *tmp = procheader_get_fromname(to_text);
+                       /* need to keep to_text pointing to stack, so heap-allocated
+                        * string from procheader_get_fromname() will be copied to buf */
+                       if (tmp != NULL) {
+                               strncpy2(buf, tmp, sizeof(buf));
+                               g_free(tmp);
+                               to_text = buf;
+                       }
+               } else if (prefs_common.summary_from_show == SHOW_ADDR)
                        extract_address(to_text);
        }
 
@@ -3493,6 +3500,8 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[],
        } else {
                if (prefs_common.use_addr_book) {
                        gchar *tmp = summary_complete_address(to_text);
+                       /* need to keep to_text pointing to stack, so heap-allocated
+                        * string from summary_complete_address() will be copied to buf */
                        if (tmp) {
                                strncpy2(buf, tmp, sizeof(buf));
                                g_free(tmp);