]> granicus.if.org Git - mutt/commitdiff
Fix a couple memory leaks in pattern.c
authorKevin McCarthy <kevin@8t8.us>
Thu, 18 Jan 2018 02:57:49 +0000 (18:57 -0800)
committerKevin McCarthy <kevin@8t8.us>
Thu, 18 Jan 2018 02:57:49 +0000 (18:57 -0800)
BUFFER.data was not being freed in a couple cases.

The pattern and simple search were not being freed if imap_search()
failed.

pattern.c

index f788b2e93b9ecd0eb24de969667279520162292c..d71252f2e239c6beb8857d956f87df00b9903d22 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -1414,10 +1414,10 @@ void mutt_check_simple (char *s, size_t len, const char *simple)
 
 int mutt_pattern_func (int op, char *prompt)
 {
-  pattern_t *pat;
-  char buf[LONG_STRING] = "", *simple;
+  pattern_t *pat = NULL;
+  char buf[LONG_STRING] = "", *simple = NULL;
   BUFFER err;
-  int i;
+  int i, rv = -1;
   progress_t progress;
 
   strfcpy (buf, NONULL (Context->pattern), sizeof (buf));
@@ -1434,15 +1434,13 @@ int mutt_pattern_func (int op, char *prompt)
   err.data = safe_malloc(err.dsize);
   if ((pat = mutt_pattern_comp (buf, MUTT_FULL_MSG, &err)) == NULL)
   {
-    FREE (&simple);
     mutt_error ("%s", err.data);
-    FREE (&err.data);
-    return (-1);
+    goto bail;
   }
 
 #ifdef USE_IMAP
   if (Context->magic == MUTT_IMAP && imap_search (Context, pat) < 0)
-    return -1;
+    goto bail;
 #endif
 
   mutt_progress_init (&progress, _("Executing command on matching messages..."),
@@ -1524,11 +1522,15 @@ int mutt_pattern_func (int op, char *prompt)
       Context->limit_pattern = mutt_pattern_comp (buf, MUTT_FULL_MSG, &err);
     }
   }
+
+  rv = 0;
+
+bail:
   FREE (&simple);
   mutt_pattern_free (&pat);
   FREE (&err.data);
 
-  return 0;
+  return rv;
 }
 
 int mutt_search_command (int cur, int op)
@@ -1577,6 +1579,7 @@ int mutt_search_command (int cur, int op)
        LastSearch[0] = '\0';
        return (-1);
       }
+      FREE (&err.data);
       mutt_clear_error ();
     }
   }