exit mem_realloc, enters p_realloc/xrealloc.
[apps/madmutt.git] / imap / browse.c
index 30eb5e6..52dcc79 100644 (file)
 #include <stdlib.h>
 #include <ctype.h>
 
-#include "lib/mem.h"
+#include <lib-lib/mem.h>
+
 #include "lib/str.h"
 #include "lib/intl.h"
 #include "lib/debug.h"
 
 #include "mutt.h"
+#include "ascii.h"
+#include "enter.h"
 #include "imap_private.h"
 
 /* -- forward declarations -- */
@@ -60,6 +63,7 @@ int imap_browse (char *path, struct browser_state *state)
   short showparents = 0;
   int noselect;
   int noinferiors;
+  int save_lsub;
   IMAP_MBOX mx;
 
   if (imap_parse_path (path, &mx)) {
@@ -67,6 +71,8 @@ int imap_browse (char *path, struct browser_state *state)
     return -1;
   }
 
+  save_lsub = option (OPTIMAPCHECKSUBSCRIBED);
+  unset_option (OPTIMAPCHECKSUBSCRIBED);
   strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST",
            sizeof (list_cmd));
 
@@ -223,11 +229,16 @@ int imap_browse (char *path, struct browser_state *state)
       }
   }
 
-  FREE (&mx.mbox);
+  if (save_lsub)
+    set_option (OPTIMAPCHECKSUBSCRIBED);
+
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  FREE (&mx.mbox);
+  if (save_lsub)
+    set_option (OPTIMAPCHECKSUBSCRIBED);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -274,11 +285,11 @@ int imap_mailbox_create (const char *folder)
 
   mutt_sleep (0);
 
-  FREE (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  FREE (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -319,11 +330,11 @@ int imap_mailbox_rename (const char *mailbox)
   mutt_message (_("Mailbox renamed."));
   mutt_sleep (0);
 
-  FREE (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  FREE (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -346,7 +357,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd,
   do {
     if (imap_parse_list_response (idata, &name, &noselect, &noinferiors,
                                   &idata->delim) != 0) {
-      FREE (&mx.mbox);
+      p_delete(&mx.mbox);
       return -1;
     }
 
@@ -362,7 +373,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd,
   }
   while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0));
 
-  FREE (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 }
 
@@ -382,11 +393,9 @@ static void imap_add_folder (char delim, char *folder, int noselect,
   imap_unmunge_mbox_name (folder);
 
   if (state->entrylen + 1 == state->entrymax) {
-    safe_realloc (&state->entry,
-                  sizeof (struct folder_file) * (state->entrymax += 256));
-    memset (state->entry + state->entrylen, 0,
-            (sizeof (struct folder_file) *
-             (state->entrymax - state->entrylen)));
+    p_realloc(&state->entry, state->entrymax += 256);
+    p_clear(state->entry + state->entrylen,
+            state->entrymax - state->entrylen);
   }
 
   /* render superiors as unix-standard ".." */
@@ -402,7 +411,7 @@ static void imap_add_folder (char delim, char *folder, int noselect,
    * than at scan, since it's so expensive to scan. But that's big changes
    * to browser.c */
   if (!((regexec (Mask.rx, relpath, 0, NULL, 0) == 0) ^ Mask.not)) {
-    FREE (&mx.mbox);
+    p_delete(&mx.mbox);
     return;
   }
 
@@ -426,7 +435,7 @@ static void imap_add_folder (char delim, char *folder, int noselect,
   (state->entry)[state->entrylen].inferiors = !noinferiors;
   (state->entrylen)++;
 
-  FREE (&mx.mbox);
+  p_delete(&mx.mbox);
 }
 
 static int compare_names (struct folder_file *a, struct folder_file *b)