drop mem_alloc and mem_free, use my own hand crafted optmized macros that
authorPierre Habouzit <madcoder@debian.org>
Sat, 28 Oct 2006 21:56:10 +0000 (23:56 +0200)
committerPierre Habouzit <madcoder@debian.org>
Sat, 28 Oct 2006 21:56:10 +0000 (23:56 +0200)
are *WAY* better to find allocation bugs.

found 5 or 6 of'em (mostly will generate crashes)

99 files changed:
Makefile.am
account.c
alias.c
attach.c
browser.c
buffer.c
buffy.c
charset.c
color.c
commands.c
compose.c
compress.c
configure.in
copy.c
crypt-gpgme.c
crypt-mod.c
crypt.c
curs_lib.c
curs_main.c
edit.c
enter.c
from.c
gnupgparse.c
handler.c
hash.c
hcache.c
history.c
hook.c
imap/auth.c
imap/auth_sasl.c
imap/browse.c
imap/command.c
imap/imap.c
imap/message.c
imap/mx_imap.c
imap/utf7.c
imap/util.c
init.c
init.h
keymap.c
lib-lib/Makefile.am [new file with mode: 0644]
lib-lib/mem.c [new file with mode: 0644]
lib-lib/mem.h [new file with mode: 0644]
lib.c
lib/Makefile.am
lib/list.c
lib/mem.c
lib/mem.h
lib/rx.c
lib/str.c
list.c
main.c
mbox.c
menu.c
mh.c
mutt_idna.c
mutt_libesmtp.c
mutt_sasl.c
mutt_socket.c
mutt_ssl.c
mutt_ssl_gnutls.c
mutt_tunnel.c
muttlib.c
mx.c
nntp/mx_nntp.c
nntp/newsrc.c
nntp/nntp.c
pager.c
parse.c
pattern.c
pgp.c
pgpinvoke.c
pgpkey.c
pgplib.c
pgppacket.c
pgppubring.c
pop/mx_pop.c
pop/pop.c
pop/pop_auth.c
pop/pop_lib.c
postpone.c
query.c
recvattach.c
recvcmd.c
regex.c
remailer.c
rfc1524.c
rfc2047.c
rfc2231.c
rfc3676.c
rfc822.c
score.c
send.c
sendlib.c
sidebar.c
smime.c
status.c
thread.c
url.c

index 26c05d0..d0c2bba 100644 (file)
@@ -19,7 +19,7 @@ NNTP_SUBDIR = nntp
 NNTP_INCLUDES = -I$(top_srcdir)/nntp
 endif
 
-SUBDIRS = m4 po intl doc contrib lib $(IMAP_SUBDIR) $(POP_SUBDIR) $(NNTP_SUBDIR)
+SUBDIRS = m4 po lib-lib intl doc contrib lib $(IMAP_SUBDIR) $(POP_SUBDIR) $(NNTP_SUBDIR)
 
 bin_SCRIPTS = muttngbug fleang
 
@@ -50,9 +50,11 @@ muttng_SOURCES = $(BUILT_SOURCES) \
        xterm.c
 
 muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(LIBPOP) $(LIBNNTP) \
-       -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
+       -Llib-lib -llib -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
 
-muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(top_builddir)/lib/libsane.a \
+muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \
+                     $(top_builddir)/lib-lib/liblib.a \
+                     $(top_builddir)/lib/libsane.a \
        $(LIBIMAPDEPS) $(LIBPOPDEPS) $(LIBNNTPDEPS) $(INTLDEPS)
 
 makedoc_SOURCES = makedoc.c
@@ -115,7 +117,7 @@ muttng_dotlock_LDADD = @LIBOBJS@
 muttng_dotlock_DEPENDENCIES = @LIBOBJS@
 
 pgpringng_SOURCES = pgppubring.c pgplib.c lib.c extlib.c sha1.c md5c.c pgppacket.c ascii.c
-pgpringng_LDADD = @LIBOBJS@ $(INTLLIBS) -Llib -lsane
+pgpringng_LDADD = @LIBOBJS@ $(INTLLIBS) -Llib-lib -llib -Llib -lsane
 pgpringng_DEPENDENCIES = @LIBOBJS@ $(INTLDEPS)
 
 pgpewrapng_SOURCES = pgpewrap.c
index 0942adc..0e0f946 100644 (file)
--- a/account.c
+++ b/account.c
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "ascii.h"
diff --git a/alias.c b/alias.c
index 667dad2..8a6c892 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -14,6 +14,8 @@
 #include <string.h>
 #include <ctype.h>
 
+#include <lib-lib/mem.h>
+
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
@@ -73,7 +75,7 @@ static ADDRESS *mutt_expand_aliases_r (ADDRESS * a, LIST ** expn)
         }
 
         if (!i) {
-          u = mem_malloc (sizeof (LIST));
+          u = p_new(LIST, 1);
           u->data = str_dup (a->mailbox);
           u->next = *expn;
           *expn = u;
@@ -430,9 +432,9 @@ int mutt_alias_complete (char *s, size_t buflen)
       while (a) {
         if (a->name && (strstr (a->name, s) == a->name)) {
           if (!a_list)          /* init */
-            a_cur = a_list = (ALIAS *) mem_malloc (sizeof (ALIAS));
+            a_cur = a_list = p_new(ALIAS, 1);
           else {
-            a_cur->next = (ALIAS *) mem_malloc (sizeof (ALIAS));
+            a_cur->next = p_new(ALIAS, 1);
             a_cur = a_cur->next;
           }
           memcpy (a_cur, a, sizeof (ALIAS));
@@ -452,7 +454,7 @@ int mutt_alias_complete (char *s, size_t buflen)
   while (a_list) {
     a_cur = a_list;
     a_list = a_list->next;
-    mem_free (&a_cur);
+    p_delete(&a_cur);
   }
 
   /* remove any aliases marked for deletion */
@@ -730,6 +732,6 @@ new_aliases:
   }
 
   mutt_menuDestroy (&menu);
-  mem_free (&AliasTable);
+  p_delete(&AliasTable);
 
 }
index 913dbb7..42953e3 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "handler.h"
@@ -144,12 +146,12 @@ int mutt_compose_attachment (BODY * a)
               b->parameter = NULL;
             }
             if (b->description) {
-              mem_free (&a->description);
+              p_delete(&a->description);
               a->description = b->description;
               b->description = NULL;
             }
             if (b->form_name) {
-              mem_free (&a->form_name);
+              p_delete(&a->form_name);
               a->form_name = b->form_name;
               b->form_name = NULL;
             }
@@ -335,9 +337,9 @@ void mutt_check_lookup_list (BODY * b, char *type, int len)
         debug_print (1, ("\"%s\" -> %s\n", b->filename, type));
       }
       if (tmp.subtype)
-        mem_free (&tmp.subtype);
+        p_delete(&tmp.subtype);
       if (tmp.xtype)
-        mem_free (&tmp.xtype);
+        p_delete(&tmp.xtype);
     }
   }
 }
@@ -452,7 +454,7 @@ int mutt_view_attachment (FILE * fp, BODY * a, int flag, HEADER * hdr,
 
     if (fp) {
       /* recv case: we need to save the attachment to a file */
-      mem_free (&fname);
+      p_delete(&fname);
       if (mutt_save_attachment (fp, a, tempfile, 0, NULL) == -1)
         goto return_error;
     }
index d111765..ff4dc3d 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mx.h"
@@ -79,14 +81,14 @@ static void destroy_state (struct browser_state *state)
   int c;
 
   for (c = 0; c < state->entrylen; c++) {
-    mem_free (&((state->entry)[c].name));
-    mem_free (&((state->entry)[c].desc));
-    mem_free (&((state->entry)[c].st));
+    p_delete(&((state->entry)[c].name));
+    p_delete(&((state->entry)[c].desc));
+    p_delete(&((state->entry)[c].st));
   }
 #ifdef USE_IMAP
-  mem_free (&state->folder);
+  p_delete(&state->folder);
 #endif
-  mem_free (&state->entry);
+  p_delete(&state->entry);
 }
 
 static int browser_compare_subject (const void *a, const void *b)
@@ -440,7 +442,7 @@ static void add_folder (MUTTMENU * m, struct browser_state *state,
     (state->entry)[state->entrylen].mtime = s->st_mtime;
     (state->entry)[state->entrylen].size = s->st_size;
 
-    (state->entry)[state->entrylen].st = mem_malloc (sizeof (struct stat));
+    (state->entry)[state->entrylen].st = p_new(struct stat, 1);
     memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat));
   }
 
@@ -1100,8 +1102,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         if (mutt_yesorno (msg, M_NO) == M_YES) {
           if (!imap_delete_mailbox (Context, mx)) {
             /* free the mailbox from the browser */
-            mem_free (&((state.entry)[nentry].name));
-            mem_free (&((state.entry)[nentry].desc));
+            p_delete(&((state.entry)[nentry].name));
+            p_delete(&((state.entry)[nentry].desc));
             /* and move all other entries up */
             if (nentry + 1 < state.entrylen)
               memmove (state.entry + nentry, state.entry + nentry + 1,
@@ -1116,7 +1118,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         }
         else
           mutt_message _("Mailbox not deleted.");
-        mem_free (&mx.mbox);
+        p_delete(&mx.mbox);
       }
       break;
 #endif
@@ -1189,7 +1191,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
 
       strfcpy (buf, NONULL (Mask.pattern), sizeof (buf));
       if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) {
-        regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t));
+        regex_t *rx = p_new(regex_t, 1);
         char *s = buf;
         int not = 0, err;
 
@@ -1207,13 +1209,13 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
           regerror (err, rx, buf, sizeof (buf));
           regfree (rx);
-          mem_free (&rx);
+          p_delete(&rx);
           mutt_error ("%s", buf);
         }
         else {
           str_replace (&Mask.pattern, buf);
           regfree (Mask.rx);
-          mem_free (&Mask.rx);
+          p_delete(&Mask.rx);
           Mask.rx = rx;
           Mask.not = not;
 
@@ -1398,7 +1400,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
            folder.ff->st = NULL;
            folder.ff->is_new = nd->new;
            folder.ff->nd = nd;
-           mem_free (&f->desc);
+           p_delete(&f->desc);
            mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
                  newsgroup_format_str, (unsigned long) &folder,
                  M_FORMAT_ARROWCURSOR);
@@ -1442,7 +1444,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
     case OP_SUBSCRIBE_PATTERN:
     case OP_UNSUBSCRIBE_PATTERN:
       if (option (OPTNEWS)) {
-        regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t));
+        regex_t *rx = p_new(regex_t, 1);
         char *s = buf;
         int j = menu->current;
         NNTP_DATA *nd;
@@ -1458,14 +1460,14 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
           else
             snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
           if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) {
-            mem_free (&rx);
+            p_delete(&rx);
             break;
           }
 
           if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
             regerror (err, rx, buf, sizeof (buf));
             regfree (rx);
-            mem_free (&rx);
+            p_delete(&rx);
             mutt_error ("%s", buf);
             break;
           }
@@ -1496,7 +1498,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
                folder.f = NULL;
                folder.new = nd->new;
                folder.nd = nd;
-               mem_free (&f->desc);
+               p_delete(&f->desc);
                mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
                        newsgroup_format_str, (unsigned long) &folder,
                        M_FORMAT_ARROWCURSOR);
@@ -1530,7 +1532,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         nntp_clear_cacheindex (news);
         if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE)
           regfree (rx);
-        mem_free (&rx);
+        p_delete(&rx);
       }
 #ifdef USE_IMAP
       else
index 9bd412b..cfe19be 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -14,6 +14,8 @@
 #include <string.h>
 #include <ctype.h>
 
+#include <lib-lib/mem.h>
+
 #include "buffer.h"
 
 #include "lib/mem.h"
  * Disregards the 'destroy' flag, which seems reserved for caller.
  * This is bad, but there's no apparent protocol for it.
  */
-BUFFER *mutt_buffer_init (BUFFER * b)
+BUFFER *mutt_buffer_init(BUFFER *b)
 {
   if (!b) {
-    b = mem_malloc (sizeof (BUFFER));
+    b = p_new(BUFFER, 1);
     if (!b)
       return NULL;
   }
   else {
-    mem_free(&b->data);
+    p_delete(&b->data);
   }
   memset (b, 0, sizeof (BUFFER));
   return b;
@@ -76,9 +78,9 @@ void mutt_buffer_free (BUFFER ** p)
   if (!p || !*p)
     return;
 
-  mem_free (&(*p)->data);
+  p_delete(&(*p)->data);
   /* dptr is just an offset to data and shouldn't be freed */
-  mem_free (p);
+  p_delete(p);
 }
 
 /* dynamically grows a BUFFER to accomodate s, in increments of 128 bytes.
@@ -204,10 +206,10 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags)
       cmd = str_substrdup (tok->dptr, pc);
       if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {
         debug_print (1, ("unable to fork command: %s\n", cmd));
-        mem_free (&cmd);
+        p_delete(&cmd);
         return (-1);
       }
-      mem_free (&cmd);
+      p_delete(&cmd);
 
       tok->dptr = pc + 1;
 
@@ -223,21 +225,21 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags)
        * the token */
       if (expn.data && qc) {
         mutt_buffer_addstr (dest, expn.data);
-        mem_free (&expn.data);
+        p_delete(&expn.data);
       }
       else if (expn.data) {
         expnlen = str_len (expn.data);
         tok->dsize = expnlen + str_len (tok->dptr) + 1;
-        ptr = mem_malloc (tok->dsize);
+        ptr = xmalloc(tok->dsize);
         memcpy (ptr, expn.data, expnlen);
         strcpy (ptr + expnlen, tok->dptr);      /* __STRCPY_CHECKED__ */
         if (tok->destroy)
-          mem_free (&tok->data);
+          p_delete(&tok->data);
         tok->data = ptr;
         tok->dptr = ptr;
         tok->destroy = 1;       /* mark that the caller should destroy this data */
         ptr = NULL;
-        mem_free (&expn.data);
+        p_delete(&expn.data);
       }
     }
     else if (ch == '$' && (!qc || qc == '"')
@@ -263,7 +265,7 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags)
             (mutt_option_value (var, tmp, sizeof (tmp)) && (env = tmp)))
           mutt_buffer_addstr (dest, env);
       }
-      mem_free (&var);
+      p_delete(&var);
     }
     else
       mutt_buffer_addch (dest, ch);
diff --git a/buffy.c b/buffy.c
index b00170b..ddb0ec7 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -14,6 +14,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffy.h"
 #include "buffer.h"
@@ -170,8 +172,8 @@ void buffy_update_mailbox (BUFFY * b)
 
 /* func to free buffy for list_del() */
 static void buffy_free (BUFFY** p) {
-  mem_free(&(*p)->path);
-  mem_free(p);
+  p_delete(&(*p)->path);
+  p_delete(p);
 }
 
 int buffy_lookup (const char* path) {
index 14e79f4..9bf63f8 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "charset.h"
 #include "ascii.h"
@@ -389,14 +391,14 @@ int mutt_convert_string (char **ps, const char *from, const char *to,
     len = str_len (s);
     ib = s, ibl = len + 1;
     obl = MB_LEN_MAX * ibl;
-    ob = buf = mem_malloc (obl + 1);
+    ob = buf = xmalloc(obl + 1);
 
     mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
     iconv_close (cd);
 
     *ob = '\0';
 
-    mem_free (ps);
+    p_delete(ps);
     *ps = buf;
 
     str_adjust (ps);
@@ -440,14 +442,14 @@ FGETCONV *fgetconv_open (FILE * file, const char *from, const char *to,
     cd = mutt_iconv_open (to, from, flags);
 
   if (cd != (iconv_t) - 1) {
-    fc = mem_malloc (sizeof (struct fgetconv_s));
+    fc = p_new(struct fgetconv_s, 1);
     fc->p = fc->ob = fc->bufo;
     fc->ib = fc->bufi;
     fc->ibl = 0;
     fc->inrepls = mutt_is_utf8 (to) ? repls : repls + 1;
   }
   else
-    fc = mem_malloc (sizeof (struct fgetconv_not));
+    fc = p_new(struct fgetconv_not, 1);
   fc->file = file;
   fc->cd = cd;
   return (FGETCONV *) fc;
@@ -532,7 +534,7 @@ void fgetconv_close (FGETCONV ** _fc)
 
   if (fc->cd != (iconv_t) - 1)
     iconv_close (fc->cd);
-  mem_free (_fc);
+  p_delete(_fc);
 }
 
 const char *mutt_get_first_charset (const char *charset)
@@ -562,11 +564,11 @@ static size_t convert_string (const char *f, size_t flen,
   if (cd == (iconv_t) (-1))
     return (size_t) (-1);
   obl = 4 * flen + 1;
-  ob = buf = mem_malloc (obl);
+  ob = buf = xmalloc(obl);
   n = my_iconv(cd, &f, &flen, &ob, &obl);
   if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
     e = errno;
-    mem_free (&buf);
+    p_delete(&buf);
     iconv_close (cd);
     errno = e;
     return (size_t) (-1);
@@ -601,12 +603,11 @@ int mutt_convert_nonmime_string (char **ps)
     n = c1 ? c1 - c : str_len (c);
     if (!n)
       continue;
-    fromcode = mem_malloc (n + 1);
-    strfcpy (fromcode, c, n + 1);
+    fromcode = p_dupstr(c, n);
     m = convert_string (u, ulen, fromcode, Charset, &s, &slen);
-    mem_free (&fromcode);
+    p_delete(&fromcode);
     if (m != (size_t) (-1)) {
-      mem_free (ps);
+      p_delete(ps);
       *ps = s;
       return 0;
     }
diff --git a/color.c b/color.c
index 5484bba..ffc04db 100644 (file)
--- a/color.c
+++ b/color.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "ascii.h"
@@ -125,14 +127,14 @@ static void mutt_free_color_line (COLOR_LINE ** l, int free_colors)
 
   regfree (&tmp->rx);
   mutt_pattern_free (&tmp->color_pattern);
-  mem_free (&tmp->pattern);
-  mem_free (l);
+  p_delete(&tmp->pattern);
+  p_delete(l);
 }
 
 void ci_start_color (void)
 {
   memset (ColorDefs, A_NORMAL, sizeof (int) * MT_COLOR_MAX);
-  ColorQuote = (int *) mem_malloc (COLOR_QUOTE_INIT * sizeof (int));
+  ColorQuote = p_new(int, COLOR_QUOTE_INIT);
   memset (ColorQuote, A_NORMAL, sizeof (int) * COLOR_QUOTE_INIT);
   ColorQuoteSize = COLOR_QUOTE_INIT;
   ColorQuoteUsed = 0;
@@ -225,7 +227,7 @@ int mutt_alloc_color (int fg, int bg)
     i++;
   }
 
-  p = (COLOR_LIST *) mem_malloc (sizeof (COLOR_LIST));
+  p = p_new(COLOR_LIST, 1);
   p->next = ColorList;
   ColorList = p;
 
@@ -269,14 +271,14 @@ void mutt_free_color (int fg, int bg)
 
       if (p == ColorList) {
         ColorList = ColorList->next;
-        mem_free (&p);
+        p_delete(&p);
         return;
       }
       q = ColorList;
       while (q) {
         if (q->next == p) {
           q->next = p->next;
-          mem_free (&p);
+          p_delete(&p);
           return;
         }
         q = q->next;
index 95a7d1d..9b00f9e 100644 (file)
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "recvattach.h"
@@ -273,7 +275,7 @@ void ci_bounce_message (HEADER * h, int *redraw)
 
   if (mutt_addrlist_to_idna (adr, &err) < 0) {
     mutt_error (_("Bad IDN: '%s'"), err);
-    mem_free (&err);
+    p_delete(&err);
     rfc822_free_address (&adr);
     return;
   }
@@ -581,7 +583,7 @@ void mutt_enter_command (void)
   err.dsize = sizeof (errbuf);
   memset (&token, 0, sizeof (token));
   r = mutt_parse_rc_line (buffer, &token, &err);
-  mem_free (&token.data);
+  p_delete(&token.data);
   if (errbuf[0]) {
     /* since errbuf could potentially contain printf() sequences in it,
        we must call mutt_error() in this fashion so that vsprintf()
@@ -871,7 +873,7 @@ void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp)
 
   /* clean up previous junk */
   mutt_free_parameter (&b->parameter);
-  mem_free (&b->subtype);
+  p_delete(&b->subtype);
 
   mutt_parse_content_type (buf, b);
 
index 8af5084..78f1ab9 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mutt_curses.h"
@@ -338,7 +340,7 @@ static int edit_address_list (int line, ADDRESS ** addr)
   if (mutt_addrlist_to_idna (*addr, &err) != 0) {
     mutt_error (_("Warning: '%s' is a bad IDN."), err);
     mutt_refresh ();
-    mem_free (&err);
+    p_delete(&err);
   }
 
   /* redraw the expanded list so the user can see the result */
@@ -374,8 +376,8 @@ static int delete_attachment (MUTTMENU * menu, short *idxlen, int x)
   idx[x]->content->next = NULL;
   idx[x]->content->parts = NULL;
   mutt_free_body (&(idx[x]->content));
-  mem_free (&idx[x]->tree);
-  mem_free (&idx[x]);
+  p_delete(&idx[x]->tree);
+  p_delete(&idx[x]);
   for (; x < *idxlen - 1; x++)
     idx[x] = idx[x + 1];
   menu->max = --(*idxlen);
@@ -618,7 +620,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
           buf[0] = 0;
         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
             && buf[0]) {
-          mem_free (&msg->env->newsgroups);
+          p_delete(&msg->env->newsgroups);
           str_skip_trailws (buf);
           msg->env->newsgroups = str_dup (str_skip_initws (buf));
           move (HDR_TO, HDR_XOFFSET);
@@ -636,7 +638,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
           strfcpy (buf, msg->env->followup_to, sizeof (buf));
         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
             && buf[0]) {
-          mem_free (&msg->env->followup_to);
+          p_delete(&msg->env->followup_to);
           str_skip_trailws (buf);
           msg->env->followup_to = str_dup (str_skip_initws (buf));
           move (HDR_CC, HDR_XOFFSET);
@@ -654,7 +656,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
           strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
             && buf[0]) {
-          mem_free (&msg->env->x_comment_to);
+          p_delete(&msg->env->x_comment_to);
           msg->env->x_comment_to = str_dup (buf);
           move (HDR_BCC, HDR_XOFFSET);
           clrtoeol ();
@@ -715,7 +717,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
                            fcc, fcclen);
         if (mutt_env_to_idna (msg->env, &tag, &err)) {
           mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
-          mem_free (&err);
+          p_delete(&err);
         }
       }
       else {
@@ -730,7 +732,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
       /* attachments may have been added */
       if (idxlen && idx[idxlen - 1]->content->next) {
         for (i = 0; i < idxlen; i++)
-          mem_free (&idx[i]);
+          p_delete(&idx[i]);
         idxlen = 0;
         idx =
           mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
@@ -760,7 +762,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
         menu->redraw |= REDRAW_INDEX;
       }
       else
-        mem_free (&idx[idxlen]);
+        p_delete(&idx[idxlen]);
 
       menu->redraw |= REDRAW_STATUS;
 
@@ -809,11 +811,11 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
           else {
             error = 1;
             mutt_error (_("Unable to attach %s!"), att);
-            mem_free (&idx[idxlen]);
+            p_delete(&idx[idxlen]);
           }
         }
 
-        mem_free (&files);
+        p_delete(&files);
         if (!error)
           mutt_clear_error ();
 
@@ -889,7 +891,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
 
         if (!ctx->msgcount) {
           mx_close_mailbox (ctx, NULL);
-          mem_free (&ctx);
+          p_delete(&ctx);
           mutt_error _("No messages in that folder.");
 
           break;
@@ -933,7 +935,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
             else {
               mutt_error _("Unable to attach!");
 
-              mem_free (&idx[idxlen]);
+              p_delete(&idx[idxlen]);
             }
           }
         }
@@ -943,7 +945,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
           mx_close_mailbox (Context, NULL);
         else
           mx_fastclose_mailbox (Context);
-        mem_free (&Context);
+        p_delete(&Context);
 
         /* go back to the folder we started from */
         Context = this;
@@ -1199,7 +1201,7 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
         /* Touch the file */
         if (!(fp = safe_fopen (fname, "w"))) {
           mutt_error (_("Can't create file %s"), fname);
-          mem_free (&idx[idxlen]);
+          p_delete(&idx[idxlen]);
           continue;
         }
         fclose (fp);
@@ -1285,10 +1287,10 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
           if (idx[idxlen]->unowned)
             idx[idxlen]->content->unlink = 0;
           mutt_free_body (&idx[idxlen]->content);
-          mem_free (&idx[idxlen]->tree);
-          mem_free (&idx[idxlen]);
+          p_delete(&idx[idxlen]->tree);
+          p_delete(&idx[idxlen]);
         }
-        mem_free (&idx);
+        p_delete(&idx);
         idxlen = 0;
         idxmax = 0;
         r = -1;
@@ -1420,13 +1422,13 @@ int mutt_compose_menu (HEADER * msg,    /* structure for new message */
     msg->content = idx[0]->content;
     for (i = 0; i < idxlen; i++) {
       idx[i]->content->aptr = NULL;
-      mem_free (&idx[i]);
+      p_delete(&idx[i]);
     }
   }
   else
     msg->content = NULL;
 
-  mem_free (&idx);
+  p_delete(&idx);
 
   return (r);
 }
index e179b7d..622bbc5 100644 (file)
@@ -7,6 +7,8 @@
  * please see the file GPL in the top level source directory.
  */
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 
 #ifdef USE_COMPRESSED
@@ -113,7 +115,7 @@ static COMPRESS_INFO *set_compress_info (CONTEXT * ctx)
   COMPRESS_INFO *ci;
 
   /* Now lets uncompress this thing */
-  ci = mem_malloc (sizeof (COMPRESS_INFO));
+  ci = p_new(COMPRESS_INFO, 1);
   ctx->compressinfo = (void *) ci;
   ci->append = find_compress_hook (M_APPENDHOOK, ctx->path);
   ci->open = find_compress_hook (M_OPENHOOK, ctx->path);
@@ -130,8 +132,7 @@ static void set_path (CONTEXT * ctx)
 
   /* Uncompress to /tmp */
   mutt_mktemp (tmppath);
-  ctx->path = mem_malloc (str_len (tmppath) + 1);
-  strcpy (ctx->path, tmppath);
+  ctx->path = p_dupstr(tmppath, str_len(tmppath));
 }
 
 static int get_size (const char *path)
@@ -197,8 +198,8 @@ int mutt_check_mailbox_compressed (CONTEXT * ctx)
   COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
 
   if (ci->size != get_size (ctx->realpath)) {
-    mem_free (&ctx->compressinfo);
-    mem_free (&ctx->realpath);
+    p_delete(&ctx->compressinfo);
+    p_delete(&ctx->realpath);
     mutt_error _("Mailbox was corrupted!");
 
     return (-1);
@@ -216,7 +217,7 @@ int mutt_open_read_compressed (CONTEXT * ctx)
 
   if (!ci->open) {
     ctx->magic = 0;
-    mem_free (ctx->compressinfo);
+    p_delete(&ctx->compressinfo);
     return (-1);
   }
   if (!ci->close || access (ctx->path, W_OK) != 0)
@@ -235,7 +236,7 @@ int mutt_open_read_compressed (CONTEXT * ctx)
 
   if ((fp = fopen (ctx->realpath, "r")) == NULL) {
     mutt_perror (ctx->realpath);
-    mem_free (&cmd);
+    p_delete(&cmd);
     return (-1);
   }
   mutt_block_signals ();
@@ -244,7 +245,7 @@ int mutt_open_read_compressed (CONTEXT * ctx)
     mutt_unblock_signals ();
     mutt_error _("Unable to lock mailbox!");
 
-    mem_free (&cmd);
+    p_delete(&cmd);
     return (-1);
   }
 
@@ -260,11 +261,11 @@ int mutt_open_read_compressed (CONTEXT * ctx)
   if (rc) {
     mutt_any_key_to_continue (NULL);
     ctx->magic = 0;
-    mem_free (ctx->compressinfo);
+    p_delete(&ctx->compressinfo);
     mutt_error (_("Error executing: %s : unable to open the mailbox!\n"),
                 cmd);
   }
-  mem_free (&cmd);
+  p_delete(&cmd);
   if (rc)
     return (-1);
 
@@ -278,7 +279,7 @@ int mutt_open_read_compressed (CONTEXT * ctx)
 
 void restore_path (CONTEXT * ctx)
 {
-  mem_free (&ctx->path);
+  p_delete(&ctx->path);
   ctx->path = ctx->realpath;
 }
 
@@ -299,7 +300,7 @@ int mutt_open_append_compressed (CONTEXT * ctx)
       return (mutt_open_read_compressed (ctx));
 
     ctx->magic = 0;
-    mem_free (&ctx->compressinfo);
+    p_delete(&ctx->compressinfo);
     return (-1);
   }
 
@@ -332,7 +333,7 @@ void mutt_fast_close_compressed (CONTEXT * ctx)
       remove_file (ctx);
 
     restore_path (ctx);
-    mem_free (&ctx->compressinfo);
+    p_delete(&ctx->compressinfo);
   }
 }
 
@@ -353,7 +354,7 @@ int mutt_sync_compressed (CONTEXT * ctx)
 
   if ((fp = fopen (ctx->realpath, "a")) == NULL) {
     mutt_perror (ctx->realpath);
-    mem_free (&cmd);
+    p_delete(&cmd);
     return (-1);
   }
   mutt_block_signals ();
@@ -364,7 +365,7 @@ int mutt_sync_compressed (CONTEXT * ctx)
 
     store_size (ctx);
 
-    mem_free (&cmd);
+    p_delete(&cmd);
     return (-1);
   }
 
@@ -386,7 +387,7 @@ int mutt_sync_compressed (CONTEXT * ctx)
   mutt_unblock_signals ();
   fclose (fp);
 
-  mem_free (&cmd);
+  p_delete(&cmd);
 
   store_size (ctx);
 
@@ -428,7 +429,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx)
 
   if ((fp = fopen (ctx->realpath, "a")) == NULL) {
     mutt_perror (ctx->realpath);
-    mem_free (&cmd);
+    p_delete(&cmd);
     return (-1);
   }
   mutt_block_signals ();
@@ -437,7 +438,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx)
     mutt_unblock_signals ();
     mutt_error _("Unable to lock mailbox!");
 
-    mem_free (&cmd);
+    p_delete(&cmd);
     return (-1);
   }
 
@@ -458,7 +459,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx)
     mutt_error (_
                 (" %s: Error compressing mailbox!  Uncompressed one kept!\n"),
                 ctx->path);
-    mem_free (&cmd);
+    p_delete(&cmd);
     mbox_unlock_compressed (ctx, fp);
     mutt_unblock_signals ();
     fclose (fp);
@@ -470,8 +471,8 @@ int mutt_slow_close_compressed (CONTEXT * ctx)
   fclose (fp);
   remove_file (ctx);
   restore_path (ctx);
-  mem_free (&cmd);
-  mem_free (&ctx->compressinfo);
+  p_delete(&cmd);
+  p_delete(&ctx->compressinfo);
 
   return (0);
 }
index 705402d..37190f2 100644 (file)
@@ -1178,6 +1178,7 @@ AC_SUBST(HTMLCLEAN_CMD)
 AC_OUTPUT(Makefile intl/Makefile m4/Makefile
         po/Makefile.in doc/Makefile contrib/Makefile
         muttbug.sh
+        lib-lib/Makefile
         lib/Makefile
         imap/Makefile
         pop/Makefile
diff --git a/copy.c b/copy.c
index 48dcabb..d312d46 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "handler.h"
@@ -157,7 +159,7 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end,
           mem_realloc (&headers[x], str_len (headers[x]) +
                         str_len (this_one) + sizeof (char));
           strcat (headers[x], this_one);        /* __STRCAT_CHECKED__ */
-          mem_free (&this_one);
+          p_delete(&this_one);
         }
 
         this_one = NULL;
@@ -250,7 +252,7 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end,
       mem_realloc (&headers[x], str_len (headers[x]) +
                     str_len (this_one) + sizeof (char));
       strcat (headers[x], this_one);    /* __STRCAT_CHECKED__ */
-      mem_free (&this_one);
+      p_delete(&this_one);
     }
 
     this_one = NULL;
@@ -303,8 +305,8 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end,
   /* Free in a separate loop to be sure that all headers are freed
    * in case of error. */
   for (x = 0; x < hdr_count; x++)
-    mem_free (&headers[x]);
-  mem_free (&headers);
+    p_delete(&headers[x]);
+  p_delete(&headers);
 
   if (error)
     return (-1);
@@ -390,7 +392,7 @@ mutt_copy_header (FILE * in, HEADER * h, FILE * out, int flags,
         /* Mutt stores references in reverse order, thus we create
          * a reordered refs list that we can put in the headers */
         for (; listp; listp = listp->next, refs = t) {
-          t = (LIST *) mem_malloc (sizeof (LIST));
+          t = p_new(LIST, 1);
           t->data = listp->data;
           t->next = refs;
         }
@@ -401,7 +403,7 @@ mutt_copy_header (FILE * in, HEADER * h, FILE * out, int flags,
 
         /* clearing refs from memory */
         for (t = refs; refs; refs = t->next, t = refs)
-          mem_free (&refs);
+          p_delete(&refs);
 
         if (fputc ('\n', out) == EOF)
           return (-1);
@@ -944,6 +946,6 @@ static int address_header_decode (char **h)
 
   rfc822_free_address (&a);
 
-  mem_free (&s);
+  p_delete(&s);
   return 1;
 }
index ef199cb..25f8f02 100644 (file)
@@ -18,6 +18,8 @@
 
 #ifdef CRYPT_BACKEND_GPGME
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_crypt.h"
 #include "mutt_menu.h"
@@ -132,12 +134,10 @@ static void print_utf8 (FILE * fp, const char *buf, size_t len)
 {
   char *tstr;
 
-  tstr = mem_malloc (len + 1);
-  memcpy (tstr, buf, len);
-  tstr[len] = 0;
+  tstr = p_dupstr(buf, len);
   mutt_convert_string (&tstr, "utf-8", Charset, M_ICONV_HOOK_FROM);
   fputs (tstr, fp);
-  mem_free (&tstr);
+  p_delete(&tstr);
 }
 
 
@@ -233,7 +233,7 @@ static void crypt_free_key (crypt_key_t ** keylist)
   while (*keylist) {
     crypt_key_t *k = (*keylist)->next;
 
-    mem_free (&k);
+    p_delete(&k);
     *keylist = k;
   }
 }
@@ -560,7 +560,7 @@ static gpgme_key_t *create_recipient_set (const char *keylist,
         else {
           mutt_error (_("error adding recipient `%s': %s\n"),
                       buf, gpgme_strerror (err));
-          mem_free (&rset);
+          p_delete(&rset);
           return NULL;
         }
       }
@@ -836,13 +836,13 @@ BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign)
     convert_to_7bit (a);
   plaintext = body_to_data_object (a, 0);
   if (!plaintext) {
-    mem_free (&rset);
+    p_delete(&rset);
     return NULL;
   }
 
   outfile = encrypt_gpgme_object (plaintext, rset, 0, sign);
   gpgme_data_release (plaintext);
-  mem_free (&rset);
+  p_delete(&rset);
   if (!outfile)
     return NULL;
 
@@ -894,13 +894,13 @@ BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist)
 
   plaintext = body_to_data_object (a, 0);
   if (!plaintext) {
-    mem_free (&rset);
+    p_delete(&rset);
     return NULL;
   }
 
   outfile = encrypt_gpgme_object (plaintext, rset, 1, 0);
   gpgme_data_release (plaintext);
-  mem_free (&rset);
+  p_delete(&rset);
   if (!outfile)
     return NULL;
 
@@ -1034,7 +1034,7 @@ static void show_fingerprint (gpgme_key_t key, STATE * state)
     return;
   is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
 
-  buf = mem_malloc (str_len (prefix) + str_len (s) * 4 + 2);
+  buf = xmalloc(str_len (prefix) + str_len (s) * 4 + 2);
   strcpy (buf, prefix);         /* __STRCPY_CHECKED__ */
   p = buf + str_len (buf);
   if (is_pgp && str_len (s) == 40) {     /* PGP v4 style formatted. */
@@ -1064,7 +1064,7 @@ static void show_fingerprint (gpgme_key_t key, STATE * state)
   *p++ = '\n';
   *p = 0;
   state_attach_puts (buf, state);
-  mem_free (&buf);
+  p_delete(&buf);
 }
 
 /* Show the valididy of a key used for one signature. */
@@ -1729,7 +1729,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset)
   if (!fname)
     return;
   unlink (fname);
-  mem_free (&fname);
+  p_delete(&fname);
 
   fc = fgetconv_open (fp, charset, Charset, M_ICONV_HOOK_FROM);
 
@@ -1922,7 +1922,7 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s)
           }
           else {
             unlink (tmpfname);
-            mem_free (&tmpfname);
+            p_delete(&tmpfname);
           }
         }
         gpgme_release (ctx);
@@ -2541,10 +2541,8 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array,
   n = s - string;
   if (!n)
     return NULL;                /* empty key */
-  array->key = mem_malloc (n + 1);
+  array->key = p_dupstr(string, n );
   p = (unsigned char *) array->key;
-  memcpy (p, string, n);        /* fixme: trim trailing spaces */
-  p[n] = 0;
   string = s + 1;
 
   if (*string == '#') {         /* hexstring */
@@ -2555,7 +2553,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array,
     if (!n || (n & 1))
       return NULL;              /* empty or odd number of digits */
     n /= 2;
-    p = mem_malloc (n + 1);
+    p = xmalloc(n + 1);
     array->value = (char *) p;
     for (s1 = string; n; s1 += 2, n--)
       *p++ = xtoi_2 (s1);
@@ -2585,7 +2583,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array,
         n++;
     }
 
-    p = mem_malloc (n + 1);
+    p = xmalloc(n + 1);
     array->value = (char *) p;
     for (s = string; n; s++, n--) {
       if (*s == '\\') {
@@ -2616,7 +2614,7 @@ static struct dn_array_s *parse_dn (const unsigned char *string)
   int i;
 
   arraysize = 7;                /* C,ST,L,O,OU,CN,email */
-  array = mem_malloc ((arraysize + 1) * sizeof *array);
+  array = p_new(struct dn_array_s, arraysize + 1);
   arrayidx = 0;
   while (*string) {
     while (*string == ' ')
@@ -2627,12 +2625,12 @@ static struct dn_array_s *parse_dn (const unsigned char *string)
       struct dn_array_s *a2;
 
       arraysize += 5;
-      a2 = mem_malloc ((arraysize + 1) * sizeof *array);
+      a2 = p_new(struct dn_array_s, arraysize + 1);
       for (i = 0; i < arrayidx; i++) {
         a2[i].key = array[i].key;
         a2[i].value = array[i].value;
       }
-      mem_free (&array);
+      p_delete(&array);
       array = a2;
     }
     array[arrayidx].key = NULL;
@@ -2654,10 +2652,10 @@ static struct dn_array_s *parse_dn (const unsigned char *string)
 
 failure:
   for (i = 0; i < arrayidx; i++) {
-    mem_free (&array[i].key);
-    mem_free (&array[i].value);
+    p_delete(&array[i].key);
+    p_delete(&array[i].value);
   }
-  mem_free (&array);
+  p_delete(&array);
   return NULL;
 }
 
@@ -2688,10 +2686,10 @@ static void parse_and_print_user_id (FILE * fp, const char *userid)
     else {
       print_dn_parts (fp, dn);
       for (i = 0; dn[i].key; i++) {
-        mem_free (&dn[i].key);
-        mem_free (&dn[i].value);
+        p_delete(&dn[i].key);
+        p_delete(&dn[i].value);
       }
-      mem_free (&dn);
+      p_delete(&dn);
     }
   }
 }
@@ -3087,7 +3085,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app,
   err = gpgme_new (&ctx);
   if (err) {
     mutt_error (_("gpgme_new failed: %s"), gpgme_strerror (err));
-    mem_free (&pattern);
+    p_delete(&pattern);
     return NULL;
   }
 
@@ -3118,12 +3116,12 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app,
     patarr[n] = NULL;
     err = gpgme_op_keylist_ext_start (ctx, (const char **) patarr, secret, 0);
     for (n = 0; patarr[n]; n++)
-      mem_free (&patarr[n]);
-    mem_free (&patarr);
+      p_delete(&patarr[n]);
+    p_delete(&patarr);
     if (err) {
       mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err));
       gpgme_release (ctx);
-      mem_free (&pattern);
+      p_delete(&pattern);
       return NULL;
     }
 
@@ -3179,7 +3177,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app,
     if (err) {
       mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err));
       gpgme_release (ctx);
-      mem_free (&pattern);
+      p_delete(&pattern);
       return NULL;
     }
 
@@ -3207,7 +3205,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app,
   }
 
   gpgme_release (ctx);
-  mem_free (&pattern);
+  p_delete(&pattern);
   return db;
 }
 
@@ -3227,7 +3225,7 @@ static LIST *crypt_add_string_to_hints (LIST * hints, const char *str)
       hints = mutt_add_list (hints, t);
   }
 
-  mem_free (&scratch);
+  p_delete(&scratch);
   return hints;
 }
 
@@ -3419,7 +3417,7 @@ static crypt_key_t *crypt_select_key (crypt_key_t * keys,
   }
 
   mutt_menuDestroy (&menu);
-  mem_free (&key_table);
+  p_delete(&key_table);
 
   set_option (OPTNEEDREDRAW);
 
@@ -3640,7 +3638,7 @@ static crypt_key_t *crypt_ask_for_key (char *tag,
       if (l)
         str_replace (&l->dflt, resp);
       else {
-        l = mem_malloc (sizeof (struct crypt_cache));
+        l = p_new(struct crypt_cache, 1);
         l->next = id_defaults;
         id_defaults = l;
         l->what = str_dup (whatfor);
@@ -3731,7 +3729,7 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc,
         }
       }
       else if (r == -1) {
-        mem_free (&keylist);
+        p_delete(&keylist);
         rfc822_free_address (&tmp);
         rfc822_free_address (&addr);
         return NULL;
@@ -3750,7 +3748,7 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc,
                                     app,
 #endif
                                     &forced_valid)) == NULL) {
-        mem_free (&keylist);
+        p_delete(&keylist);
         rfc822_free_address (&tmp);
         rfc822_free_address (&addr);
         return NULL;
index 9200ef9..6a93bad 100644 (file)
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "crypt-mod.h"
 #include "lib/mem.h"
 
@@ -27,7 +29,7 @@ static crypt_module_t modules;
 /* Register a new crypto module. */
 void crypto_module_register (crypt_module_specs_t specs)
 {
-  crypt_module_t module_new = mem_malloc (sizeof (*module_new));
+  crypt_module_t module_new = p_new(struct crypt_module, 1);
 
   module_new->specs = specs;
   module_new->next = modules;
diff --git a/crypt.c b/crypt.c
index 54d60fe..dad41c3 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -16,6 +16,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "handler.h"
@@ -826,7 +828,7 @@ int mutt_signed_handler (BODY * a, STATE * s)
       state_attach_puts (_("[-- The following data is signed --]\n\n"), s);
 
 
-      mem_free (&signatures);
+      p_delete(&signatures);
     }
     else
       state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"),
index 0cb31c6..9f8b8aa 100644 (file)
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mutt_menu.h"
@@ -201,12 +203,12 @@ int mutt_yesorno (const char *msg, int def)
    * ensure there is enough room for the answer and truncate the question
    * to fit.
    */
-  answer_string = mem_malloc (COLS + 1);
+  answer_string = p_new(char, COLS + 1);
   snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no,
             def == M_YES ? no : yes);
   answer_string_len = str_len (answer_string);
   printw ("%.*s%s", COLS - answer_string_len, msg, answer_string);
-  mem_free (&answer_string);
+  p_delete(&answer_string);
 
   FOREVER {
     mutt_refresh ();
@@ -464,7 +466,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen,
     *redraw = REDRAW_FULL;
   }
   else {
-    char *pc = mem_malloc (str_len (prompt) + 3);
+    char *pc = p_new(char, str_len(prompt) + 3);
 
     sprintf (pc, "%s: ", prompt);       /* __SPRINTF_CHECKED__ */
     mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
@@ -474,7 +476,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen,
         != 0)
       buf[0] = 0;
     MAYBE_REDRAW (*redraw);
-    mem_free (&pc);
+    p_delete(&pc);
   }
 
   return 0;
index ff7b8e3..82f8402 100644 (file)
@@ -14,6 +14,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mx.h"
@@ -298,9 +300,7 @@ static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
 
   /* save the list of new messages */
   if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
-    save_new =
-      (HEADER **) mem_malloc (sizeof (HEADER *) *
-                               (Context->msgcount - oldcount));
+    save_new = p_new(HEADER*, Context->msgcount - oldcount);
     for (j = oldcount; j < Context->msgcount; j++)
       save_new[j - oldcount] = Context->hdrs[j];
   }
@@ -332,7 +332,7 @@ static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
             mutt_uncollapse_thread (Context, h);
         }
       }
-      mem_free (&save_new);
+      p_delete(&save_new);
       mutt_set_virtual (Context);
     }
   }
@@ -484,7 +484,7 @@ int mutt_index_menu (void)
       if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
         if (!Context->path) {
           /* fatal error occurred */
-          mem_free (&Context);
+          p_delete(&Context);
           menu->redraw = REDRAW_FULL;
         }
         set_option (OPTSEARCHINVALID);
@@ -966,7 +966,7 @@ int mutt_index_menu (void)
             snprintf (buf, sizeof (buf), "~A");
           unset_option (OPTHIDEREAD);
         }
-        mem_free (&Context->pattern);
+        p_delete(&Context->pattern);
         Context->pattern = str_dup (buf);
       }
       if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
@@ -1154,7 +1154,7 @@ int mutt_index_menu (void)
 
       /* check for a fatal error, or all messages deleted */
       if (!Context->path)
-        mem_free (&Context);
+        p_delete(&Context);
 
       /* if we were in the pager, redisplay the message */
       if (menu->menu == MENU_PAGER) {
@@ -1257,7 +1257,7 @@ int mutt_index_menu (void)
           menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
           break;
         }
-        mem_free (&Context);
+        p_delete(&Context);
       }
 
       mutt_sleep (0);
@@ -1340,7 +1340,7 @@ int mutt_index_menu (void)
       {
         if (Context) {
           mx_fastclose_mailbox (Context);
-          mem_free (&Context);
+          p_delete(&Context);
         }
         done = 1;
       }
diff --git a/edit.c b/edit.c
index 893b495..2f1a377 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "enter.h"
@@ -132,9 +134,9 @@ static int be_barf_file (const char *path, char **buf, int buflen)
 static void be_free_memory (char **buf, int buflen)
 {
   while (buflen-- > 0)
-    mem_free (&buf[buflen]);
+    p_delete(&buf[buflen]);
   if (buf)
-    mem_free (&buf);
+    p_delete(&buf);
 }
 
 static char **be_include_messages (char *msg, char **buf, int *bufmax,
@@ -392,7 +394,7 @@ int mutt_builtin_editor (const char *path, HEADER * msg, HEADER * cur)
           buflen--;
           strfcpy (tmp, buf[buflen], sizeof (tmp));
           tmp[str_len (tmp) - 1] = 0;
-          mem_free (&buf[buflen]);
+          p_delete(&buf[buflen]);
           buf[buflen] = NULL;
           continue;
         }
diff --git a/enter.c b/enter.c
index b979a2e..cda61f2 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mutt_menu.h"
@@ -166,7 +168,7 @@ static void replace_part (ENTER_STATE *state, size_t from, const char *buf)
   memcpy (state->wbuf + state->curpos, savebuf, savelen * sizeof (wchar_t));
   state->lastchar = state->curpos + savelen;
 
-  mem_free (&savebuf);
+  p_delete(&savebuf);
 }
 
 /*
@@ -663,7 +665,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x,
 
 bye:
 
-  mem_free (&tempbuf);
+  p_delete(&tempbuf);
   return rv;
 }
 
@@ -672,8 +674,8 @@ void mutt_free_enter_state (ENTER_STATE ** esp)
   if (!esp)
     return;
 
-  mem_free (&(*esp)->wbuf);
-  mem_free (esp);
+  p_delete(&(*esp)->wbuf);
+  p_delete(esp);
 }
 
 /*
diff --git a/from.c b/from.c
index 7b0ed8e..e3c85eb 100644 (file)
--- a/from.c
+++ b/from.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 
 #include "lib/mem.h"
index 1f8a0a3..080bc29 100644 (file)
@@ -33,6 +33,8 @@
 #include <time.h>
 #include <ctype.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "pgp.h"
 #include "charset.h"
@@ -88,7 +90,7 @@ static void fix_uid (char *uid)
     char *ob;
     size_t ibl, obl;
 
-    buf = mem_malloc (n + 1);
+    buf = p_new(char, n + 1);
     ib = uid, ibl = d - uid + 1, ob = buf, obl = n;
     my_iconv(cd, &ib, &ibl, &ob, &obl);
     if (!ibl) {
@@ -99,7 +101,7 @@ static void fix_uid (char *uid)
       else if (ob - buf == n && (buf[n] = 0, str_len (buf) < n))
         memcpy (uid, buf, n);
     }
-    mem_free (&buf);
+    p_delete(&buf);
     iconv_close (cd);
   }
 }
index 7da0547..a1a1353 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -18,6 +18,8 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "recvattach.h"
@@ -775,9 +777,9 @@ int text_enriched_handler (BODY * a, STATE * s)
 
   state_putc ('\n', s);         /* add a final newline */
 
-  mem_free (&(stte.buffer));
-  mem_free (&(stte.line));
-  mem_free (&(stte.param));
+  p_delete(&(stte.buffer));
+  p_delete(&(stte.line));
+  p_delete(&(stte.param));
 
   return (0);
 }
@@ -1099,7 +1101,7 @@ static int autoview_handler (BODY * a, STATE * s)
   mutt_sanitize_filename (fname, 1);
   rfc1524_expand_filename (entry->nametemplate, fname, tempfile,
                            sizeof (tempfile));
-  mem_free (&fname);
+  p_delete(&fname);
 
   if (entry->command) {
     strfcpy (command, entry->command, sizeof (command));
diff --git a/hash.c b/hash.c
index 72225be..3cd6140 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -15,6 +15,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 
 #include "lib/mem.h"
@@ -40,7 +42,7 @@ int hash_string (const unsigned char *s, int n)
 
 HASH *hash_create (int nelem)
 {
-  HASH *table = mem_malloc (sizeof (HASH));
+  HASH *table = p_new(HASH, 1);
 
   if (nelem == 0)
     nelem = 2;
@@ -50,7 +52,7 @@ HASH *hash_create (int nelem)
   return table;
 }
 
-HASH *hash_resize (HASH * ptr, int nelem)
+HASH *hash_resize(HASH *ptr, int nelem)
 {
   HASH *table;
   struct hash_elem *elem, *tmp;
@@ -63,11 +65,11 @@ HASH *hash_resize (HASH * ptr, int nelem)
       tmp = elem;
       elem = elem->next;
       hash_insert (table, tmp->key, tmp->data, 1);
-      mem_free (&tmp);
+      p_delete(&tmp);
     }
   }
-  mem_free (&ptr->table);
-  mem_free (&ptr);
+  p_delete(&ptr->table);
+  p_delete(&ptr);
 
   return table;
 }
@@ -82,7 +84,7 @@ int hash_insert (HASH * table, const char *key, void *data, int allow_dup)
   struct hash_elem *ptr;
   int h;
 
-  ptr = (struct hash_elem *) mem_malloc (sizeof (struct hash_elem));
+  ptr = p_new(struct hash_elem, 1);
   h = hash_string ((unsigned char *) key, table->nelem);
   ptr->key = key;
   ptr->data = data;
@@ -99,7 +101,7 @@ int hash_insert (HASH * table, const char *key, void *data, int allow_dup)
     for (tmp = table->table[h], last = NULL; tmp; last = tmp, tmp = tmp->next) {
       r = str_cmp (tmp->key, key);
       if (r == 0) {
-        mem_free (&ptr);
+        p_delete(&ptr);
         return (-1);
       }
       if (r > 0)
@@ -137,7 +139,7 @@ void hash_delete_hash (HASH * table, int hash, const char *key, const void *data
       *last = ptr->next;
       if (destroy)
         destroy (ptr->data);
-      mem_free (&ptr);
+      p_delete(&ptr);
 
       ptr = *last;
     } else {
@@ -162,11 +164,11 @@ void hash_destroy (HASH ** ptr, void (*destroy) (void *))
       elem = elem->next;
       if (destroy)
         destroy (tmp->data);
-      mem_free (&tmp);
+      p_delete(&tmp);
     }
   }
-  mem_free (&pptr->table);
-  mem_free (ptr);
+  p_delete(&pptr->table);
+  p_delete(ptr);
 }
 
 void hash_map (HASH* table, void (*mapfunc) (const char* key, void* data,
index 0febef6..e31aabc 100644 (file)
--- a/hcache.c
+++ b/hcache.c
@@ -39,6 +39,9 @@
 #if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #ifdef USE_IMAP
 #include "message.h"
@@ -87,7 +90,7 @@ static void *lazy_malloc (size_t siz)
     siz = 4096;
   }
 
-  return mem_malloc (siz);
+  return xmalloc(siz);
 }
 
 static void lazy_realloc (void *ptr, size_t siz)
@@ -165,8 +168,7 @@ static void restore_char (char **c, const unsigned char *d, int *off)
     return;
   }
 
-  *c = mem_malloc (size);
-  memcpy (*c, d + *off, size);
+  *c = p_dup(d + *off, size);
   *off += size;
 }
 
@@ -197,7 +199,7 @@ static void restore_address (ADDRESS ** a, const unsigned char *d, int *off)
   restore_int (&counter, d, off);
 
   while (counter) {
-    *a = mem_malloc (sizeof (ADDRESS));
+    *a = p_new(ADDRESS, 1);
     restore_char (&(*a)->personal, d, off);
     restore_char (&(*a)->mailbox, d, off);
     restore_int ((unsigned int *) &(*a)->group, d, off);
@@ -233,7 +235,7 @@ static void restore_list (LIST ** l, const unsigned char *d, int *off)
   restore_int (&counter, d, off);
 
   while (counter) {
-    *l = mem_malloc (sizeof (LIST));
+    *l = p_new(LIST, 1);
     restore_char (&(*l)->data, d, off);
     l = &(*l)->next;
     counter--;
@@ -271,7 +273,7 @@ static void restore_buffer (BUFFER ** b, const unsigned char *d, int *off)
     return;
   }
 
-  *b = mem_malloc (sizeof (BUFFER));
+  *b = p_new(BUFFER, 1);
 
   restore_char (&(*b)->data, d, off);
   restore_int (&offset, d, off);
@@ -309,7 +311,7 @@ restore_parameter (PARAMETER ** p, const unsigned char *d, int *off)
   restore_int (&counter, d, off);
 
   while (counter) {
-    *p = mem_malloc (sizeof (PARAMETER));
+    *p = p_new(PARAMETER, 1);
     restore_char (&(*p)->attribute, d, off);
     restore_char (&(*p)->value, d, off);
     p = &(*p)->next;
@@ -615,8 +617,8 @@ mutt_hcache_open(const char *path, const char *folder)
 
   if (!path || path[0] == '\0')
   {
-    mem_free(&h->folder);
-    mem_free(&h);
+    p_delete(&h->folder);
+    p_delete(&h);
     return NULL;
   }
 
@@ -630,8 +632,8 @@ mutt_hcache_open(const char *path, const char *folder)
     return h;
   else
   {
-    mem_free(&h->folder);
-    mem_free(&h);
+    p_delete(&h->folder);
+    p_delete(&h);
 
     return NULL;
   }
@@ -646,8 +648,8 @@ mutt_hcache_close(void *db)
     return;
 
   vlclose(h->db);
-  mem_free(&h->folder);
-  mem_free(&h);
+  p_delete(&h->folder);
+  p_delete(&h);
 }
 
 void *
@@ -671,7 +673,7 @@ mutt_hcache_fetch(void *db, const char *filename,
 
   if (! crc32_matches(data, h->crc))
   {
-    mem_free(&data);
+    p_delete(&data);
     return NULL;
   }
 
@@ -701,7 +703,7 @@ mutt_hcache_store(void *db, const char *filename, HEADER * header,
 
   ret = vlput(h->db, path, ksize, data, dsize, VL_DOVER);
 
-  mem_free(&data);
+  p_delete(&data);
 
   return ret;
 }
@@ -737,8 +739,8 @@ void *mutt_hcache_open (const char *path, const char *folder)
   h->crc = generate_crc32 ();
 
   if (!path || path[0] == '\0') {
-    mem_free (&h->folder);
-    mem_free (&h);
+    p_delete(&h->folder);
+    p_delete(&h);
     return NULL;
   }
 
@@ -755,8 +757,8 @@ void *mutt_hcache_open (const char *path, const char *folder)
     return h;
   }
   else {
-    mem_free (&h->folder);
-    mem_free (&h);
+    p_delete(&h->folder);
+    p_delete(&h);
 
     return NULL;
   }
@@ -771,8 +773,8 @@ void mutt_hcache_close (void *db)
   }
 
   gdbm_close (h->db);
-  mem_free (&h->folder);
-  mem_free (&h);
+  p_delete(&h->folder);
+  p_delete(&h);
 }
 
 void *mutt_hcache_fetch (void *db, const char *filename,
@@ -796,7 +798,7 @@ void *mutt_hcache_fetch (void *db, const char *filename,
   data = gdbm_fetch (h->db, key);
 
   if (!crc32_matches (data.dptr, h->crc)) {
-    mem_free(&data.dptr);
+    p_delete(&data.dptr);
     return NULL;
   }
 
@@ -827,7 +829,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header,
 
   ret = gdbm_store (h->db, key, data, GDBM_REPLACE);
 
-  mem_free (&data.dptr);
+  p_delete(&data.dptr);
 
   return ret;
 }
@@ -881,7 +883,7 @@ void *mutt_hcache_open (const char *path, const char *folder)
   h->crc = generate_crc32 ();
 
   if (!path || path[0] == '\0') {
-    mem_free (&h);
+    p_delete(&h);
     return NULL;
   }
 
@@ -891,13 +893,13 @@ void *mutt_hcache_open (const char *path, const char *folder)
 
   h->fd = open (h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
   if (h->fd < 0) {
-    mem_free (&h);
+    p_delete(&h);
     return NULL;
   }
 
   if (mx_lock_file (h->lockfile, h->fd, 1, 0, 5)) {
     close (h->fd);
-    mem_free (&h);
+    p_delete(&h);
     return NULL;
   }
 
@@ -905,7 +907,7 @@ void *mutt_hcache_open (const char *path, const char *folder)
   if (ret) {
     mx_unlock_file (h->lockfile, h->fd, 0);
     close (h->fd);
-    mem_free (&h);
+    p_delete(&h);
     return NULL;
   }
 
@@ -917,7 +919,7 @@ void *mutt_hcache_open (const char *path, const char *folder)
       h->env->close (h->env, 0);
       mx_unlock_file (h->lockfile, h->fd, 0);
       close (h->fd);
-      mem_free (&h);
+      p_delete(&h);
       return NULL;
     }
   }
@@ -933,7 +935,7 @@ void *mutt_hcache_open (const char *path, const char *folder)
     h->env->close (h->env, 0);
     mx_unlock_file (h->lockfile, h->fd, 0);
     close (h->fd);
-    mem_free (&h);
+    p_delete(&h);
     return NULL;
   }
 
@@ -952,7 +954,7 @@ void mutt_hcache_close (void *db)
   h->env->close (h->env, 0);
   mx_unlock_file (h->lockfile, h->fd, 0);
   close (h->fd);
-  mem_free (&h);
+  p_delete(&h);
 }
 
 void *mutt_hcache_fetch (void *db, const char *filename,
@@ -975,7 +977,7 @@ void *mutt_hcache_fetch (void *db, const char *filename,
   h->db->get (h->db, NULL, &key, &data, 0);
 
   if (!crc32_matches (data.data, h->crc)) {
-    mem_free(&data.data);
+    p_delete(&data.data);
     return NULL;
   }
 
@@ -1007,7 +1009,7 @@ mutt_hcache_store (void *db, const char *filename, HEADER * header,
 
   ret = h->db->put (h->db, NULL, &key, &data, 0);
 
-  mem_free (&data.data);
+  p_delete(&data.data);
 
   return ret;
 }
index 66559c0..2976633 100644 (file)
--- a/history.c
+++ b/history.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "history.h"
 #include "lib/mem.h"
@@ -33,8 +35,8 @@ static void init_history (struct history *h)
   if (OldSize) {
     if (h->hist) {
       for (i = 0; i < OldSize; i++)
-        mem_free (&h->hist[i]);
-      mem_free (&h->hist);
+        p_delete(&h->hist[i]);
+      p_delete(&h->hist);
     }
   }
 
diff --git a/hook.c b/hook.c
index 0a7ce54..d665cb3 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "mx.h"
@@ -89,7 +91,7 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
   if (data & (M_FOLDERHOOK | M_MBOXHOOK)) {
     strfcpy (path, pattern.data, sizeof (path));
     _mutt_expand_path (path, sizeof (path), 1);
-    mem_free (&pattern.data);
+    p_delete(&pattern.data);
     memset (&pattern, 0, sizeof (pattern));
     pattern.data = str_dup (path);
   }
@@ -108,7 +110,7 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
 
     strfcpy (tmp, pattern.data, sizeof (tmp));
     mutt_check_simple (tmp, sizeof (tmp), DefaultHook);
-    mem_free (&pattern.data);
+    p_delete(&pattern.data);
     memset (&pattern, 0, sizeof (pattern));
     pattern.data = str_dup (tmp);
   }
@@ -116,7 +118,7 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
   if (data & (M_MBOXHOOK | M_SAVEHOOK | M_FCCHOOK)) {
     strfcpy (path, command.data, sizeof (path));
     mutt_expand_path (path, sizeof (path));
-    mem_free (&command.data);
+    p_delete(&command.data);
     memset (&command, 0, sizeof (command));
     command.data = str_dup (path);
   }
@@ -132,8 +134,8 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
          * pattern, so if we've already seen this pattern/command pair, just
          * ignore it instead of creating a duplicate */
         if (!str_cmp (ptr->command, command.data)) {
-          mem_free (&command.data);
-          mem_free (&pattern.data);
+          p_delete(&command.data);
+          p_delete(&pattern.data);
           return 0;
         }
       }
@@ -143,9 +145,9 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
          * order of execution of the hooks, which i think is desirable since
          * a common action to perform is to change the default (.) entry
          * based upon some other information. */
-        mem_free (&ptr->command);
+        p_delete(&ptr->command);
         ptr->command = command.data;
-        mem_free (&pattern.data);
+        p_delete(&pattern.data);
         return 0;
       }
     }
@@ -163,7 +165,7 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
       goto error;
   }
   else {
-    rx = mem_malloc (sizeof (regex_t));
+    rx = p_new(regex_t, 1);
 #ifdef M_CRYPTHOOK
     if ((rc =
          REGCOMP (rx, NONULL (pattern.data),
@@ -178,7 +180,7 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
     {
       regerror (rc, rx, err->data, err->dsize);
       regfree (rx);
-      mem_free (&rx);
+      p_delete(&rx);
       goto error;
     }
   }
@@ -198,20 +200,20 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data,
   return 0;
 
 error:
-  mem_free (&pattern.data);
-  mem_free (&command.data);
+  p_delete(&pattern.data);
+  p_delete(&command.data);
   return (-1);
 }
 
 static void delete_hook (HOOK * h)
 {
-  mem_free (&h->command);
-  mem_free (&h->rx.pattern);
+  p_delete(&h->command);
+  p_delete(&h->rx.pattern);
   if (h->rx.rx) {
     regfree (h->rx.rx);
   }
   mutt_pattern_free (&h->pattern);
-  mem_free (&h);
+  p_delete(&h);
 }
 
 /* Deletes all hooks of type ``type'', or all defined hooks if ``type'' is 0 */
@@ -292,7 +294,7 @@ void mutt_folder_hook (char *path)
           mutt_error ("%s", err.data);
           mutt_sleep (1);       /* pause a moment to let the user see the error */
           if (ERROR_STOP) {
-            mem_free (&token.data);
+            p_delete(&token.data);
             current_hook_type = 0;
             return;
           }
@@ -300,7 +302,7 @@ void mutt_folder_hook (char *path)
       }
     }
   }
-  mem_free (&token.data);
+  p_delete(&token.data);
 
   current_hook_type = 0;
 }
@@ -338,13 +340,13 @@ void mutt_message_hook (CONTEXT * ctx, HEADER * hdr, int type)
           mutt_error ("%s", err.data);
           mutt_sleep (1);
           if (ERROR_STOP) {
-            mem_free (&token.data);
+            p_delete(&token.data);
             current_hook_type = 0;
             return;
           }
         }
   }
-  mem_free (&token.data);
+  p_delete(&token.data);
   current_hook_type = 0;
 }
 
@@ -465,7 +467,7 @@ void mutt_account_hook (const char *url)
         mutt_error ("%s", err.data);
         mutt_sleep (1);
         if (ERROR_STOP) {
-          mem_free (&token.data);
+          p_delete(&token.data);
           current_hook_type = 0;
           return;
         }
@@ -473,6 +475,6 @@ void mutt_account_hook (const char *url)
     }
   }
 
-  mem_free (&token.data);
+  p_delete(&token.data);
 }
 #endif
index 7c6293d..4861fbb 100644 (file)
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/debug.h"
@@ -71,7 +73,7 @@ int imap_authenticate (IMAP_DATA * idata)
             !ascii_strcasecmp (authenticator->method, method))
           if ((r = authenticator->authenticate (idata, method)) !=
               IMAP_AUTH_UNAVAIL) {
-            mem_free (&methods);
+            p_delete(&methods);
             return r;
           }
 
@@ -79,7 +81,7 @@ int imap_authenticate (IMAP_DATA * idata)
       }
     }
 
-    mem_free (&methods);
+    p_delete(&methods);
   }
   else {
     /* Fall back to default: any authenticator */
index 60e4656..f9be180 100644 (file)
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mutt_sasl.h"
index fd9c473..73bfcbc 100644 (file)
@@ -17,6 +17,8 @@
 #include <stdlib.h>
 #include <ctype.h>
 
+#include <lib-lib/mem.h>
+
 #include "lib/mem.h"
 #include "lib/str.h"
 #include "lib/intl.h"
@@ -231,13 +233,13 @@ int imap_browse (char *path, struct browser_state *state)
   if (save_lsub)
     set_option (OPTIMAPCHECKSUBSCRIBED);
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
   if (save_lsub)
     set_option (OPTIMAPCHECKSUBSCRIBED);
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -284,11 +286,11 @@ int imap_mailbox_create (const char *folder)
 
   mutt_sleep (0);
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -329,11 +331,11 @@ int imap_mailbox_rename (const char *mailbox)
   mutt_message (_("Mailbox renamed."));
   mutt_sleep (0);
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -356,7 +358,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) {
-      mem_free (&mx.mbox);
+      p_delete(&mx.mbox);
       return -1;
     }
 
@@ -372,7 +374,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd,
   }
   while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0));
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 }
 
@@ -412,7 +414,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)) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return;
   }
 
@@ -436,7 +438,7 @@ static void imap_add_folder (char delim, char *folder, int noselect,
   (state->entry)[state->entrylen].inferiors = !noinferiors;
   (state->entrylen)++;
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
 }
 
 static int compare_names (struct folder_file *a, struct folder_file *b)
index a28ae7a..1232457 100644 (file)
@@ -16,6 +16,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/debug.h"
@@ -74,12 +76,12 @@ int imap_cmd_start (IMAP_DATA * idata, const char *cmd)
   cmd_make_sequence (idata);
   /* seq, space, cmd, \r\n\0 */
   outlen = str_len (idata->cmd.seq) + str_len (cmd) + 4;
-  out = (char *) mem_malloc (outlen);
+  out = p_new(char, outlen);
   snprintf (out, outlen, "%s %s\r\n", idata->cmd.seq, cmd);
 
   rc = mutt_socket_write (idata->conn, out);
 
-  mem_free (&out);
+  p_delete(&out);
 
   return (rc < 0) ? IMAP_CMD_BAD : 0;
 }
@@ -188,13 +190,13 @@ int imap_exec (IMAP_DATA * idata, const char *cmd, int flags)
   cmd_make_sequence (idata);
   /* seq, space, cmd, \r\n\0 */
   outlen = str_len (idata->cmd.seq) + str_len (cmd) + 4;
-  out = (char *) mem_malloc (outlen);
+  out = p_new(char, outlen);
   snprintf (out, outlen, "%s %s\r\n", idata->cmd.seq, cmd);
 
   rc = mutt_socket_write_d (idata->conn, out,
                             flags & IMAP_CMD_PASS ? IMAP_LOG_PASS :
                             IMAP_LOG_CMD);
-  mem_free (&out);
+  p_delete(&out);
 
   if (rc < 0) {
     cmd_handle_fatal (idata);
@@ -432,7 +434,7 @@ static void cmd_parse_capabilities (IMAP_DATA * idata, char *s)
   debug_print (2, ("Handling CAPABILITY\n"));
 
   s = imap_next_word (s);
-  mem_free (&idata->capstr);
+  p_delete(&idata->capstr);
   idata->capstr = str_dup (s);
 
   memset (idata->capabilities, 0, sizeof (idata->capabilities));
@@ -580,7 +582,7 @@ static void cmd_parse_lsub (IMAP_DATA* idata, char* s) {
     err.dsize = sizeof (errstr);
     if (mutt_parse_rc_line (buf, &token, &err))
       debug_print (1, ("Error adding subscribed mailbox: %s\n", errstr));
-    mem_free (&token.data);
+    p_delete(&token.data);
   }
   else
     debug_print (1, ("Bad LSUB response\n"));
index db9901a..8c7cc5e 100644 (file)
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "buffer.h"
@@ -66,7 +68,7 @@ int imap_access (const char *path, int flags)
   if (!(idata = imap_conn_find (&mx.account,
                                 option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW :
                                 0))) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return -1;
   }
 
@@ -74,11 +76,11 @@ int imap_access (const char *path, int flags)
 
   /* we may already be in the folder we're checking */
   if (!ascii_strcmp(idata->mailbox, mx.mbox)) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return 0;
   }
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
 
   if (mutt_bit_isset (idata->capabilities, IMAP4REV1))
@@ -138,7 +140,7 @@ int imap_delete_mailbox (CONTEXT * ctx, IMAP_MBOX mx)
     if (!(idata = imap_conn_find (&mx.account,
                                   option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW
                                   : 0))) {
-      mem_free (&mx.mbox);
+      p_delete(&mx.mbox);
       return -1;
     }
   }
@@ -243,7 +245,7 @@ void imap_expunge_mailbox (IMAP_DATA * idata)
       if (idata->cache[cacheno].uid == HEADER_DATA (h)->uid &&
           idata->cache[cacheno].path) {
         unlink (idata->cache[cacheno].path);
-        mem_free (&idata->cache[cacheno].path);
+        p_delete(&idata->cache[cacheno].path);
       }
 
       imap_free_header_data (&h->data);
@@ -387,7 +389,7 @@ IMAP_DATA *imap_conn_find (const ACCOUNT * account, int flags)
     else
       mutt_account_unsetpass (&idata->conn->account);
 
-    mem_free (&idata->capstr);
+    p_delete(&idata->capstr);
   }
   if (new && idata->state == IMAP_AUTHENTICATED) {
     imap_get_delim (idata);
@@ -462,7 +464,7 @@ int imap_open_connection (IMAP_DATA * idata)
     idata->state = IMAP_AUTHENTICATED;
     if (imap_check_capabilities (idata) != 0)
       goto bail;
-    mem_free (&idata->capstr);
+    p_delete(&idata->capstr);
   }
   else {
     imap_error ("imap_open_connection()", buf);
@@ -475,7 +477,7 @@ err_close_conn:
   mutt_socket_close (idata->conn);
   idata->state = IMAP_DISCONNECTED;
 bail:
-  mem_free (&idata->capstr);
+  p_delete(&idata->capstr);
   return -1;
 }
 
@@ -557,11 +559,11 @@ int imap_open_mailbox (CONTEXT * ctx)
 
   /* Clean up path and replace the one in the ctx */
   imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
-  mem_free (&(idata->mailbox));
+  p_delete(&(idata->mailbox));
   idata->mailbox = str_dup (buf);
   imap_qualify_path (buf, sizeof (buf), &mx, idata->mailbox);
 
-  mem_free (&(ctx->path));
+  p_delete(&(ctx->path));
   ctx->path = str_dup (buf);
 
   idata->ctx = ctx;
@@ -701,14 +703,14 @@ int imap_open_mailbox (CONTEXT * ctx)
   }
 
   debug_print (2, ("msgcount is %d\n", ctx->msgcount));
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
   if (idata->state == IMAP_SELECTED)
     idata->state = IMAP_AUTHENTICATED;
 fail_noidata:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -727,7 +729,7 @@ int imap_open_mailbox_append (CONTEXT * ctx)
    * ctx is brand new and mostly empty */
 
   if (!(idata = imap_conn_find (&(mx.account), 0))) {
-    mem_free(&mx.mbox);
+    p_delete(&mx.mbox);
     return (-1);
   }
   conn = idata->conn;
@@ -737,7 +739,7 @@ int imap_open_mailbox_append (CONTEXT * ctx)
 
   imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));
 
-  mem_free(&mx.mbox);
+  p_delete(&mx.mbox);
 
   /* really we should also check for W_OK */
   if (!imap_access (ctx->path, F_OK))
@@ -761,8 +763,8 @@ void imap_logout (IMAP_DATA * idata)
   idata->status = IMAP_BYE;
   imap_cmd_start (idata, "LOGOUT");
   while (imap_cmd_step (idata) == IMAP_CMD_CONTINUE);
-  mem_free (&idata->cmd.buf);
-  mem_free (&idata);
+  p_delete(&idata->cmd.buf);
+  p_delete(&idata);
 }
 
 /*
@@ -870,7 +872,7 @@ int imap_make_msg_set (IMAP_DATA * idata, BUFFER * buf, int flag, int changed)
     }
   }
 
-  mem_free (&hdrs);
+  p_delete(&hdrs);
 
   return count;
 }
@@ -1053,10 +1055,10 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint)
   rc = 0;
 out:
   if (cmd.data)
-    mem_free (&cmd.data);
+    p_delete(&cmd.data);
   if (appendctx) {
     mx_fastclose_mailbox (appendctx);
-    mem_free (&appendctx);
+    p_delete(&appendctx);
   }
   return rc;
 }
@@ -1082,7 +1084,7 @@ void imap_close_mailbox (CONTEXT * ctx)
     }
 
     idata->reopen &= IMAP_REOPEN_ALLOW;
-    mem_free (&(idata->mailbox));
+    p_delete(&(idata->mailbox));
     mutt_free_list (&idata->flags);
     idata->ctx = NULL;
   }
@@ -1094,7 +1096,7 @@ void imap_close_mailbox (CONTEXT * ctx)
   for (i = 0; i < IMAP_CACHE_LEN; i++) {
     if (idata->cache[i].path) {
       unlink (idata->cache[i].path);
-      mem_free (&idata->cache[i].path);
+      p_delete(&idata->cache[i].path);
     }
   }
 }
@@ -1166,13 +1168,13 @@ int imap_mailbox_check (char *path, int new)
     connflags = M_IMAP_CONN_NONEW;
 
   if (!(idata = imap_conn_find (&(mx.account), connflags))) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return -1;
   }
   conn = idata->conn;
 
   imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
 
   imap_munge_mbox_name (mbox, sizeof (mbox), buf);
   strfcpy (mbox_unquoted, buf, sizeof (mbox_unquoted));
@@ -1348,15 +1350,15 @@ int imap_search (CONTEXT* ctx, const pattern_t* pat) {
   memset (&buf, 0, sizeof (buf));
   mutt_buffer_addstr (&buf, "UID SEARCH ");
   if (imap_compile_search (pat, &buf) < 0) {
-    mem_free (&buf.data);
+    p_delete(&buf.data);
     return -1;
   }
   if (imap_exec (idata, buf.data, 0) < 0) {
-    mem_free (&buf.data);
+    p_delete(&buf.data);
     return -1;
   }
 
-  mem_free (&buf.data);
+  p_delete(&buf.data);
   return 0;
 }
 
@@ -1464,7 +1466,7 @@ int imap_subscribe (char *path, int subscribe)
               subscribe ? "" : "un", path);
     if (mutt_parse_rc_line (mbox, &token, &err))
       debug_print (1, ("Error adding subscribed mailbox: %s\n", errstr));
-    mem_free (&token.data);
+    p_delete(&token.data);
   }
 
   if (subscribe)
@@ -1478,11 +1480,11 @@ int imap_subscribe (char *path, int subscribe)
   if (imap_exec (idata, buf, 0) < 0)
     goto fail;
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -1569,7 +1571,7 @@ int imap_complete (char *dest, size_t dlen, char *path) {
   /* don't open a new socket just for completion. Instead complete over
    * known mailboxes/hooks/etc */
   if (!(idata = imap_conn_find (&(mx.account), M_IMAP_CONN_NONEW))) {
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     strfcpy (dest, path, dlen);
     return imap_complete_hosts (dest, dlen);
   }
@@ -1625,7 +1627,7 @@ int imap_complete (char *dest, size_t dlen, char *path) {
     imap_qualify_path (dest, dlen, &mx, completion);
     mutt_pretty_mailbox (dest);
 
-    mem_free (&mx.mbox);
+    p_delete(&mx.mbox);
     return 0;
   }
 
index 949f5d9..dcfe4ca 100644 (file)
@@ -17,6 +17,8 @@
 #include <stdlib.h>
 #include <ctype.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "buffer.h"
@@ -174,7 +176,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend)
 
         rewind (fp);
 
-        mem_free (&uid_validity);
+        p_delete(&uid_validity);
 
       }
       while ((rc != IMAP_CMD_OK) && ((mfhrc == -1) ||
@@ -345,7 +347,7 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
       return 0;
     else {
       unlink (cache->path);
-      mem_free (&cache->path);
+      p_delete(&cache->path);
     }
   }
 
@@ -356,7 +358,7 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
   mutt_mktemp (path);
   cache->path = str_dup (path);
   if (!(msg->fp = safe_fopen (path, "w+"))) {
-    mem_free (&cache->path);
+    p_delete(&cache->path);
     return -1;
   }
 
@@ -480,7 +482,7 @@ bail:
   safe_fclose (&msg->fp);
   if (cache->path) {
     unlink (cache->path);
-    mem_free (&cache->path);
+    p_delete(&cache->path);
   }
 
   return -1;
@@ -594,11 +596,11 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg)
     goto fail;
   }
 
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -740,18 +742,18 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
   }
 
   if (cmd.data)
-    mem_free (&cmd.data);
+    p_delete(&cmd.data);
   if (sync_cmd.data)
-    mem_free (&sync_cmd.data);
-  mem_free (&mx.mbox);
+    p_delete(&sync_cmd.data);
+  p_delete(&mx.mbox);
   return 0;
 
 fail:
   if (cmd.data)
-    mem_free (&cmd.data);
+    p_delete(&cmd.data);
   if (sync_cmd.data)
-    mem_free (&sync_cmd.data);
-  mem_free (&mx.mbox);
+    p_delete(&sync_cmd.data);
+  p_delete(&mx.mbox);
   return -1;
 }
 
@@ -782,7 +784,7 @@ void imap_free_header_data (void **data)
   /* this should be safe even if the list wasn't used */
   mutt_free_list (&(((IMAP_HEADER_DATA *) * data)->keywords));
 
-  mem_free (data);
+  p_delete(data);
 }
 
 /* imap_set_flags: fill out the message header according to the flags from
@@ -798,7 +800,7 @@ char *imap_set_flags (IMAP_DATA * idata, HEADER * h, char *s)
 
   debug_print (2, ("parsing FLAGS\n"));
   if ((s = msg_parse_flags (&newh, s)) == NULL) {
-    mem_free (&newh.data);
+    p_delete(&newh.data);
     return NULL;
   }
 
@@ -824,7 +826,7 @@ char *imap_set_flags (IMAP_DATA * idata, HEADER * h, char *s)
 
   mutt_free_list (&(HEADER_DATA (h)->keywords));
   HEADER_DATA (h)->keywords = newh.data->keywords;
-  mem_free (&newh.data);
+  p_delete(&newh.data);
 
   return s;
 }
index 6ad4b32..dbec056 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <sys/stat.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "imap_private.h"
 
index 95e8fd6..7eeed83 100644 (file)
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "charset.h"
 #include "imap_private.h"
@@ -52,7 +54,7 @@ static char *utf7_to_utf8 (const char *u7, size_t u7len, char **u8,
   char *buf, *p;
   int b, ch, k;
 
-  p = buf = mem_malloc (u7len + u7len / 8 + 1);
+  p = buf = p_new(char, u7len + u7len / 8 + 1);
 
   for (; u7len; u7++, u7len--) {
     if (*u7 == '&') {
@@ -119,7 +121,7 @@ static char *utf7_to_utf8 (const char *u7, size_t u7len, char **u8,
   return buf;
 
 bail:
-  mem_free (&buf);
+  p_delete(&buf);
   return 0;
 }
 
@@ -142,7 +144,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7,
    * In the worst case we convert 2 chars to 7 chars. For example:
    * "\x10&\x10&..." -> "&ABA-&-&ABA-&-...".
    */
-  p = buf = mem_malloc ((u8len / 2) * 7 + 6);
+  p = buf = p_new(char, (u8len / 2) * 7 + 6);
 
   while (u8len) {
     unsigned char c = *u8;
@@ -206,7 +208,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7,
   }
 
   if (u8len) {
-    mem_free (&buf);
+    p_delete(&buf);
     return 0;
   }
 
@@ -225,7 +227,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7,
   return buf;
 
 bail:
-  mem_free (&buf);
+  p_delete(&buf);
   return 0;
 }
 
@@ -236,10 +238,10 @@ void imap_utf7_encode (char **s)
 
     if (!mutt_convert_string (&t, Charset, "UTF-8", 0)) {
       char *u7 = utf8_to_utf7 (t, strlen (t), NULL, 0);
-      mem_free (s);
+      p_delete(s);
       *s = u7;
     }
-    mem_free (&t);
+    p_delete(&t);
   }
 }
 
@@ -249,7 +251,7 @@ void imap_utf7_decode (char **s)
     char *t = utf7_to_utf8 (*s, str_len (*s), 0, 0);
 
     if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0)) {
-      mem_free (s);
+      p_delete(s);
       *s = t;
     }
   }
index fa54de6..1025cea 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "config.h"
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mx.h"                 /* for M_IMAP */
 #include "ascii.h"
@@ -57,7 +59,7 @@ int imap_expand_path (char *path, size_t len)
   url.path = mx.mbox;
 
   rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD);
-  mem_free (&mx.mbox);
+  p_delete(&mx.mbox);
 
   return rc;
 }
@@ -100,7 +102,7 @@ int imap_parse_path (const char *path, IMAP_MBOX * mx)
 
   if (!(url.scheme == U_IMAP || url.scheme == U_IMAPS) ||
       mutt_account_fromurl (&mx->account, &url) < 0 || !*mx->account.host) {
-    mem_free (&c);
+    p_delete(&c);
     return -1;
   }
 
@@ -109,7 +111,7 @@ int imap_parse_path (const char *path, IMAP_MBOX * mx)
   if (url.scheme == U_IMAPS)
     mx->account.flags |= M_ACCT_SSL;
 
-  mem_free (&c);
+  p_delete(&c);
 
   if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
     mx->account.port = ImapsPort;
@@ -144,7 +146,7 @@ void imap_pretty_mailbox (char *path)
           if (target.mbox[hlen] == *delim)
             home_match = 1;
     }
-    mem_free (&home.mbox);
+    p_delete(&home.mbox);
   }
 
   /* do the '=' substitution */
@@ -165,7 +167,7 @@ void imap_pretty_mailbox (char *path)
     url_ciss_tostring (&url, path, 1024, 0);
   }
 
-  mem_free (&target.mbox);
+  p_delete(&target.mbox);
 }
 
 /* -- library functions -- */
@@ -198,10 +200,10 @@ void imap_free_idata (IMAP_DATA ** idata)
   if (!idata)
     return;
 
-  mem_free (&(*idata)->capstr);
+  p_delete(&(*idata)->capstr);
   mutt_free_list (&(*idata)->flags);
-  mem_free (&((*idata)->cmd.buf));
-  mem_free (idata);
+  p_delete(&((*idata)->cmd.buf));
+  p_delete(idata);
 }
 
 /*
@@ -430,7 +432,7 @@ void imap_munge_mbox_name (char *dest, size_t dlen, const char *src)
 
   imap_quote_string (dest, dlen, buf);
 
-  mem_free (&buf);
+  p_delete(&buf);
 }
 
 void imap_unmunge_mbox_name (char *s)
@@ -445,7 +447,7 @@ void imap_unmunge_mbox_name (char *s)
     strncpy (s, buf, str_len (s));
   }
 
-  mem_free (&buf);
+  p_delete(&buf);
 }
 
 /* imap_wordcasecmp: find word a in word list b */
@@ -500,7 +502,7 @@ void imap_keepalive (void)
         }
         imap_check_mailbox (ctx, NULL, 1);
         if (!idata->ctx)
-          mem_free (&ctx);
+          p_delete(&ctx);
       }
     }
 
diff --git a/init.c b/init.c
index 10c23d7..cb580c5 100644 (file)
--- a/init.c
+++ b/init.c
@@ -14,6 +14,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "ascii.h"
@@ -262,7 +264,7 @@ static void sys_to_string (char* dst, size_t dstlen,
 
   /* get some $muttng_ values dynamically */
   if (ascii_strcmp ("muttng_pwd", option->option) == 0) {
-    val = mem_malloc (_POSIX_PATH_MAX);
+    val = p_new(char, _POSIX_PATH_MAX);
     val = getcwd (val, _POSIX_PATH_MAX-1);
     clean = 1;
   } else if (ascii_strcmp ("muttng_folder_path", option->option) == 0 &&
@@ -295,7 +297,7 @@ static void sys_to_string (char* dst, size_t dstlen,
 
   snprintf (dst, dstlen, "%s=\"%s\"", option->option, NONULL (val));
   if (clean)
-    mem_free (&val);
+    p_delete(&val);
 }
 
 static int path_from_string (struct option_t* dst, const char* val,
@@ -306,7 +308,7 @@ static int path_from_string (struct option_t* dst, const char* val,
     return (0);
 
   if (!val || !*val) {
-    mem_free ((char**) dst->data);
+    p_delete((char**) dst->data);
     return (1);
   }
 
@@ -451,18 +453,18 @@ static int rx_from_string (struct option_t* dst, const char* val,
     s++;
   }
 
-  rx = mem_malloc (sizeof(regex_t));
+  rx = p_new(regex_t, 1);
 
   if ((e = REGCOMP (rx, s, flags)) != 0) {
     regerror (e, rx, errbuf, errlen);
     regfree (rx);
-    mem_free (&rx);
+    p_delete(&rx);
     return (0);
   }
 
   if (p->rx) {
     regfree (p->rx);
-    mem_free (&p->rx);
+    p_delete(&p->rx);
   }
 
   str_replace (&p->pattern, val);
@@ -539,7 +541,7 @@ int mutt_option_value (const char* val, char* dst, size_t dstlen) {
     *dst = '\0';
     return (0);
   }
-  tmp = mem_malloc (dstlen+1);
+  tmp = p_new(char, dstlen+1);
   FuncTable[DTYPE (option->type)].opt_to_string (tmp, dstlen, option);
 
   /* as we get things of type $var=value and don't want to bloat the
@@ -555,7 +557,7 @@ int mutt_option_value (const char* val, char* dst, size_t dstlen) {
     }
   }
   memcpy (dst, t, l+1);
-  mem_free (&tmp);
+  p_delete(&tmp);
   debug_print (1, ("stripped == '%s'\n", dst));
 
   return (1);
@@ -563,7 +565,7 @@ int mutt_option_value (const char* val, char* dst, size_t dstlen) {
 
 /* for synonym warning reports: adds synonym to end of list */
 static void syn_add (struct option_t* n, struct option_t* o) {
-  syn_t* tmp = mem_malloc (sizeof(syn_t));
+  syn_t* tmp = p_new(syn_t, 1);
   tmp->f = str_dup (CurRCFile);
   tmp->l = CurRCLine;
   tmp->n = n;
@@ -573,8 +575,8 @@ static void syn_add (struct option_t* n, struct option_t* o) {
 
 /* for synonym warning reports: free single item (for list_del()) */
 static void syn_del (void** p) {
-  mem_free(&(*(syn_t**) p)->f);
-  mem_free(p);
+  p_delete(&(*(syn_t**) p)->f);
+  p_delete(p);
 }
 
 void toggle_quadoption (int opt)
@@ -699,7 +701,7 @@ static int add_to_spam_list (SPAM_LIST ** list, const char *pat,
        * the template, and leaving t pointed at the current item.
        */
       t = last;
-      mem_free(t->template);
+      p_delete(&t->template);
       break;
     }
     if (!last->next)
@@ -751,8 +753,8 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
   if (spam->rx && !str_cmp (spam->rx->pattern, pat)) {
     *list = spam->next;
     rx_free (&spam->rx);
-    mem_free(&spam->template);
-    mem_free(&spam);
+    p_delete(&spam->template);
+    p_delete(&spam);
     return 1;
   }
 
@@ -761,8 +763,8 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
     if (!str_cmp (spam->rx->pattern, pat)) {
       prev->next = spam->next;
       rx_free (&spam->rx);
-      mem_free(spam->template);
-      mem_free(spam);
+      p_delete(&spam->template);
+      p_delete(&spam);
       spam = prev->next;
       ++nremoved;
     }
@@ -785,12 +787,12 @@ static void remove_from_list (LIST ** l, const char *str)
     last = NULL;
     while (p) {
       if (ascii_strcasecmp (str, p->data) == 0) {
-        mem_free (&p->data);
+        p_delete(&p->data);
         if (last)
           last->next = p->next;
         else
           (*l) = p->next;
-        mem_free (&p);
+        p_delete(&p);
       }
       else {
         last = p;
@@ -874,10 +876,10 @@ static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
   if (data == res) {
     if (mutt_parse_rc_line (tmp->data, &token, err) == -1) {
       mutt_error ("Error: %s", err->data);
-      mem_free (&token.data);
+      p_delete(&token.data);
       return (-1);
     }
-    mem_free (&token.data);
+    p_delete(&token.data);
   }
   return 0;
 }
@@ -995,10 +997,10 @@ static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data,
 
       /* Add to the spam list. */
       if (add_to_spam_list (&SpamList, buf->data, templ.data, err) != 0) {
-        mem_free (&templ.data);
+        p_delete(&templ.data);
         return -1;
       }
-      mem_free (&templ.data);
+      p_delete(&templ.data);
     }
 
     /* If not, try to remove from the nospam list. */
@@ -1103,7 +1105,7 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata,
     if (!buf->data || *buf->data == '\0')
       continue;
 
-    a = mem_malloc(sizeof(ATTACH_MATCH));
+    a = p_new(ATTACH_MATCH, 1);
 
     /* some cheap hacks that I expect to remove */
     if (!str_casecmp(buf->data, "any"))
@@ -1122,7 +1124,7 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata,
     }
 
     len = str_len (a->minor);
-    tmpminor = mem_malloc(len+3);
+    tmpminor = p_new(char, len + 3);
     strcpy(&tmpminor[1], a->minor); /* __STRCPY_CHECKED__ */
     tmpminor[0] = '^';
     tmpminor[len+1] = '$';
@@ -1131,12 +1133,12 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata,
     a->major_int = mutt_check_mime_type(a->major);
     regcomp(&a->minor_rx, tmpminor, REG_ICASE|REG_EXTENDED);
 
-    mem_free (&tmpminor);
+    p_delete(&tmpminor);
 
     debug_print (5, ("parse_attach_list: added %s/%s [%d]\n",
                      a->major, a->minor, a->major_int));
 
-    listp = mem_malloc(sizeof(LIST));
+    listp = p_new(LIST, 1);
     listp->data = (char *)a;
     listp->next = NULL;
     if (lastp) {
@@ -1188,7 +1190,7 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er
         debug_print(5, ("parse_unattach_list: removed %s/%s [%d]\n",
                         a->major, a->minor, a->major_int));
         regfree(&a->minor_rx);
-        mem_free(&a->major);
+        p_delete(&a->major);
 
         /* Relink backward */
         if (lastp)
@@ -1197,8 +1199,8 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er
           *ldata = lp->next;
 
         newlp = lp->next;
-        mem_free(&lp->data); /* same as a */
-        mem_free(&lp);
+        p_delete(&lp->data); /* same as a */
+        p_delete(&lp);
         lp = newlp;
         continue;
       }
@@ -1209,7 +1211,7 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er
   }
   while (MoreArgs (s));
 
-  mem_free (&tmp);
+  p_delete(&tmp);
   _attachments_clean();
   return 0;
 }
@@ -1534,7 +1536,7 @@ static int parse_my_hdr (BUFFER * buf, BUFFER * s, unsigned long data,
       /* see if there is already a field by this name */
       if (ascii_strncasecmp (buf->data, tmp->data, keylen) == 0) {
         /* replace the old value */
-        mem_free (&tmp->data);
+        p_delete(&tmp->data);
         tmp->data = buf->data;
         memset (buf, 0, sizeof(BUFFER));
         return 0;
@@ -1621,17 +1623,17 @@ static void del_option (void* p) {
   struct option_t* ptr = (struct option_t*) p;
   char* s = (char*) ptr->data;
   debug_print (1, ("removing option '%s' from table\n", NONULL (ptr->option)));
-  mem_free (&ptr->option);
-  mem_free (&s);
-  mem_free (&ptr->init);
-  mem_free (&ptr);
+  p_delete(&ptr->option);
+  p_delete(&s);
+  p_delete(&ptr->init);
+  p_delete(&ptr);
 }
 
 static int init_expand (char** dst, struct option_t* src) {
   BUFFER token, in;
   size_t len = 0;
 
-  mem_free (dst);
+  p_delete(dst);
 
   if (DTYPE(src->type) == DT_STR ||
       DTYPE(src->type) == DT_PATH) {
@@ -1641,7 +1643,7 @@ static int init_expand (char** dst, struct option_t* src) {
       memset (&token, 0, sizeof(BUFFER));
       memset (&in, 0, sizeof(BUFFER));
       len = str_len (src->init) + 2;
-      in.data = mem_malloc (len+1);
+      in.data = p_new(char, len + 1);
       snprintf (in.data, len, "\"%s\"", src->init);
       in.dptr = in.data;
       in.dsize = len;
@@ -1650,8 +1652,8 @@ static int init_expand (char** dst, struct option_t* src) {
         *dst = str_dup (token.data);
       else
         *dst = str_dup ("");
-      mem_free (&in.data);
-      mem_free (&token.data);
+      p_delete(&in.data);
+      p_delete(&token.data);
     } else
       *dst = str_dup ("");
   } else
@@ -1685,7 +1687,7 @@ static void mutt_restore_default (const char* name, void* p,
                ptr->option, NONULL (init), errbuf);
       exit (1);
     }
-    mem_free (&init);
+    p_delete(&init);
   }
 
   if (ptr->flags & R_INDEX)
@@ -1739,7 +1741,7 @@ static int check_dsn_notify (const char* option, unsigned long p,
       rc = 0;
       break;
     }
-  list_del (&list, (list_del_t*) _mem_free);
+  list_del (&list, (list_del_t*)xmemfree);
   return (rc);
 }
 
@@ -1976,7 +1978,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
             hash_delete (ConfigOptions, option->option,
                          option, del_option);
           else
-            mem_free ((void *) option->data);
+            p_delete((void **)&option->data);
           break;
         }
       }
@@ -2100,7 +2102,7 @@ static int source_rc (const char *rcfile, BUFFER * err)
       mutt_error (_("Error in %s, line %d: %s"), rcfile, line, err->data);
       if (--rc < -MAXERRS) {
         if (conv)
-          mem_free (&currentline);
+          p_delete(&currentline);
         break;
       }
     }
@@ -2109,10 +2111,10 @@ static int source_rc (const char *rcfile, BUFFER * err)
         rc = -1;
     }
     if (conv)
-      mem_free (&currentline);
+      p_delete(&currentline);
   }
-  mem_free (&token.data);
-  mem_free (&linebuf);
+  p_delete(&token.data);
+  p_delete(&linebuf);
   fclose (f);
   if (pid != -1)
     mutt_wait_filter (pid);
@@ -2199,7 +2201,7 @@ int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err)
   r = 0;
 finish:
   if (expn.destroy)
-    mem_free (&expn.data);
+    p_delete(&expn.data);
   return (r);
 }
 
@@ -2516,13 +2518,13 @@ int mutt_query_variables (LIST * queries)
     snprintf (command, sizeof(command), "set ?%s\n", p->data);
     if (mutt_parse_rc_line (command, &token, &err) == -1) {
       fprintf (stderr, "%s\n", err.data);
-      mem_free (&token.data);
+      p_delete(&token.data);
       return 1;
     }
     printf ("%s\n", err.data);
   }
 
-  mem_free (&token.data);
+  p_delete(&token.data);
   return 0;
 }
 
@@ -2558,11 +2560,11 @@ static int mutt_execute_commands (LIST * p)
   for (; p; p = p->next) {
     if (mutt_parse_rc_line (p->data, &token, &err) != 0) {
       fprintf (stderr, _("Error in command line: %s\n"), err.data);
-      mem_free (&token.data);
+      p_delete(&token.data);
       return (-1);
     }
   }
-  mem_free (&token.data);
+  p_delete(&token.data);
   return 0;
 }
 
@@ -2650,7 +2652,7 @@ void mutt_init (int skip_sys_rc, LIST * commands)
   else
 #endif /* DOMAIN */
   if (*DOMAIN != '@') {
-    Fqdn = mem_malloc (str_len (DOMAIN) + str_len (Hostname) + 2);
+    Fqdn = p_new(char, str_len(DOMAIN) + str_len(Hostname) + 2);
     sprintf (Fqdn, "%s.%s", NONULL (Hostname), DOMAIN); /* __SPRINTF_CHECKED__ */
   }
   else
@@ -2722,7 +2724,7 @@ void mutt_init (int skip_sys_rc, LIST * commands)
 
     memset (&token, 0, sizeof(token));
     parse_my_hdr (&token, &buf, 0, &err);
-    mem_free (&token.data);
+    p_delete(&token.data);
   }
 
   if ((p = getenv ("EMAIL")) != NULL)
@@ -2792,11 +2794,11 @@ void mutt_init (int skip_sys_rc, LIST * commands)
   }
   else {
     strfcpy (buffer, Muttrc, sizeof(buffer));
-    mem_free (&Muttrc);
+    p_delete(&Muttrc);
     mutt_expand_path (buffer, sizeof(buffer));
     Muttrc = str_dup (buffer);
   }
-  mem_free (&AliasFile);
+  p_delete(&AliasFile);
   AliasFile = str_dup (NONULL (Muttrc));
 
   /* Process the global rc file if it exists and the user hasn't explicity
diff --git a/init.h b/init.h
index 1d93b5a..bbab713 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2789,7 +2789,7 @@ struct option_t MuttVars[] = {
    ** This variable configures how often (in seconds) Mutt-ng should look for
    ** new mail.
    */
-  {"pop_delete", DT_QUAD, R_NONE, OPT_POPDELETE, "ask-no" },
+  {"pop_delete(", DT_QUAD, R_NONE, OPT_POPDELETE, "ask-no" },
   /*
    ** .pp
    ** Availability: POP
index 2508dff..d28ca0f 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "ascii.h"
@@ -93,15 +95,14 @@ int LastKey;
 
 struct keymap_t *Keymaps[MENU_MAX];
 
-static struct keymap_t *allocKeys (int len, keycode_t * keys)
+static struct keymap_t *allocKeys(int len, keycode_t *keys)
 {
-  struct keymap_t *p;
+    struct keymap_t *p;
 
-  p = mem_calloc (1, sizeof (struct keymap_t));
-  p->len = len;
-  p->keys = mem_malloc (len * sizeof (keycode_t));
-  memcpy (p->keys, keys, len * sizeof (keycode_t));
-  return (p);
+    p = mem_calloc (1, sizeof (struct keymap_t));
+    p->len  = len;
+    p->keys = p_dup(keys, len);
+    return p;
 }
 
 static int parse_fkey (char *s)
@@ -205,10 +206,10 @@ void km_bind (const char *s, int menu, int op, char *macro, char *descr)
       do {
         len = tmp->eq;
         next = tmp->next;
-        mem_free (&tmp->macro);
-        mem_free (&tmp->keys);
-        mem_free (&tmp->descr);
-        mem_free (&tmp);
+        p_delete(&tmp->macro);
+        p_delete(&tmp->keys);
+        p_delete(&tmp->descr);
+        p_delete(&tmp);
         tmp = next;
       }
       while (tmp && len >= pos);
@@ -712,7 +713,7 @@ static char *parse_keymap (int *menu, BUFFER * s, int maxmenus, int *nummenus,
     strfcpy (err->data, _("too few arguments"), err->dsize);
   }
 error:
-  mem_free (&buf.data);
+  p_delete(&buf.data);
   return (NULL);
 }
 
@@ -812,7 +813,7 @@ int mutt_parse_bind (BUFFER * buf, BUFFER * s, unsigned long data,
       }
     }
   }
-  mem_free (&key);
+  p_delete(&key);
   return (r);
 }
 
@@ -850,7 +851,7 @@ int mutt_parse_macro (BUFFER * buf, BUFFER * s, unsigned long data,
         }
       }
 
-      mem_free (&seq);
+      p_delete(&seq);
     }
     else {
       for (i = 0; i < nummenus; ++i) {
@@ -859,7 +860,7 @@ int mutt_parse_macro (BUFFER * buf, BUFFER * s, unsigned long data,
       }
     }
   }
-  mem_free (&key);
+  p_delete(&key);
   return (r);
 }
 
diff --git a/lib-lib/Makefile.am b/lib-lib/Makefile.am
new file mode 100644 (file)
index 0000000..8faa8ab
--- /dev/null
@@ -0,0 +1,6 @@
+noinst_LIBRARIES = liblib.a
+
+liblib_a_SOURCES = mem.c
+
+noinst_HEADERS = mem.h
+
diff --git a/lib-lib/mem.c b/lib-lib/mem.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/lib-lib/mem.h b/lib-lib/mem.h
new file mode 100644 (file)
index 0000000..c1eb0b1
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the Free
+ *  Software Foundation; either version 2 of the License, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author: Pierre Habouzit <madcoder@debian.org>
+ */
+
+#ifndef MUTT_LIB_LIB_MEM_H
+#define MUTT_LIB_LIB_MEM_H
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void *xmalloc(ssize_t size) {
+    void *mem;
+
+    if (size <= 0)
+        return NULL;
+
+    mem = calloc(size, 1);
+    if (!mem)
+        abort();
+    return mem;
+}
+
+static inline void *xrealloc(void *mem, ssize_t newsize) {
+    mem = realloc(mem, newsize);
+    if (!mem)
+        abort();
+    return mem;
+}
+
+static inline void *xmemdup(const void *src, ssize_t size) {
+    return memcpy(xmalloc(size), src, size);
+}
+
+static inline void *xmemdupstr(const void *src, ssize_t len) {
+    char *res = xmalloc(len + 1);
+    memcpy(res, src, len);
+    res[len] = '\0';
+    return res;
+}
+
+#define p_new(type, count)      ((type *)xmalloc(sizeof(type) * (count)))
+#define p_clear(p, count)       ((void)memset((p), 0, sizeof(*(p)) * (count)))
+#define p_dup(p, count)         xmemdup((p), sizeof(*(p)) * (count))
+#define p_dupstr(p, len)        xmemdupstr((p), (len))
+
+#ifdef __GNUC__
+
+#  define p_delete(mem_pp)                          \
+        ({                                          \
+            typeof(**(mem_pp)) **__ptr = (mem_pp);  \
+            free(*__ptr);                           \
+            *__ptr = NULL;                          \
+        })
+
+#else
+
+#  define p_delete(mem_p)                           \
+        do {                                        \
+            void *__ptr = (mem_p);                  \
+            free(*__ptr);                           \
+            *(void **)__ptr = NULL;                 \
+        } while (0)
+
+#endif
+
+static inline void xmemfree(void **ptr) {
+    p_delete(ptr);
+}
+
+#endif /* MUTT_LIB_LIB_MEM_H */
diff --git a/lib.c b/lib.c
index 4f1fee3..e683c6d 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -34,6 +34,8 @@
 #define EX_OK 0
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "lib.h"
 
 #include "lib/mem.h"
@@ -391,19 +393,19 @@ int mutt_rx_sanitize_string (char *dest, size_t destlen, const char *src)
  * If a line ends with "\", this char and the linefeed is removed,
  * and the next line is read too.
  */
-char *mutt_read_line (char *s, size_t * size, FILE * fp, int *line)
+char *mutt_read_line(char *s, size_t * size, FILE * fp, int *line)
 {
   size_t offset = 0;
   char *ch;
 
   if (!s) {
-    s = mem_malloc (STRING);
+    s = p_new(char, STRING);
     *size = STRING;
   }
 
   FOREVER {
     if (fgets (s + offset, *size - offset, fp) == NULL) {
-      mem_free (&s);
+      p_delete(&s);
       return NULL;
     }
     if ((ch = strchr (s + offset, '\n')) != NULL) {
index 9354a37..b6bc751 100644 (file)
@@ -7,9 +7,9 @@ AUTOMAKE_OPTIONS = foreign
 INCLUDES = -I$(top_srcdir) -I../intl
 
 noinst_LIBRARIES = libsane.a
-noinst_HEADERS = mem.h str.h exit.h intl.h list.h rx.h debug.h
+noinst_HEADERS = str.h exit.h intl.h list.h rx.h debug.h
 
-libsane_a_SOURCES = mem.c exit.c str.c list.c rx.h debug.h \
-                   mem.h exit.h str.h list.h rx.c debug.c intl.h
+libsane_a_SOURCES = mem.h exit.c str.c list.c rx.h debug.h \
+                   mem.c exit.h str.h list.h rx.c debug.c intl.h
 
 -include ../cflags.mk
index 1dd865f..207e336 100644 (file)
@@ -10,6 +10,8 @@
 #include <stddef.h>
 #include <string.h>
 
+#include <lib-lib/mem.h>
+
 #include "list.h"
 
 #include "mem.h"
@@ -26,8 +28,8 @@ void list_del (list2_t** l, list_del_t* del) {
   if (del)
     for (i = 0; i < (*l)->length; i++)
       del (&(*l)->data[i]);
-  mem_free(&(*l)->data);
-  mem_free(l);
+  p_delete(&(*l)->data);
+  p_delete(l);
 }
 
 void list_push_back (list2_t** l, void* p) {
@@ -77,15 +79,14 @@ void* list_pop_idx (list2_t* l, int c) {
   return (p);
 }
 
-list2_t* list_cpy (list2_t* l) {
-  list2_t* ret = NULL;
-  if (list_empty(l))
-    return (NULL);
-  ret = list_new ();
-  ret->length = l->length;
-  ret->data = mem_malloc (l->length*sizeof(void*));
-  memcpy (ret->data, l->data, l->length*sizeof(void*));
-  return (ret);
+list2_t *list_cpy(list2_t *l) {
+    list2_t* ret = NULL;
+    if (list_empty(l))
+        return NULL;
+    ret = list_new();
+    ret->length = l->length;
+    ret->data = p_dup(l->data, l->length);
+    return ret;
 }
 
 list2_t* list_dup (list2_t* l, void* (*dup) (void*)) {
@@ -95,7 +96,7 @@ list2_t* list_dup (list2_t* l, void* (*dup) (void*)) {
     return (NULL);
   ret = list_new ();
   ret->length = l->length;
-  ret->data = mem_malloc (l->length*sizeof(void*));
+  ret->data = p_new(void*, l->length);
   for (i = 0; i < l->length; i++)
     ret->data[i] = dup (l->data[i]);
   return (ret);
@@ -122,7 +123,7 @@ list2_t* list_from_str (const char* str, const char* delim) {
   for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) {
     list_push_back (&ret, str_dup (p));
   }
-  mem_free (&tmp);
+  p_delete(&tmp);
   return (ret);
 }
 
index 344b7cf..ab23acc 100644 (file)
--- a/lib/mem.c
+++ b/lib/mem.c
@@ -29,18 +29,6 @@ void *_mem_calloc (size_t nmemb, size_t size, int line, const char* fname) {
   return p;
 }
 
-void *_mem_malloc (size_t siz, int line, const char* fname) {
-  void *p;
-
-  if (siz == 0)
-    return 0;
-  if ((p = (void *) malloc (siz)) == 0) {       /* __MEM_CHECKED__ */
-    exit_fatal ("mem_malloc", _("Out of memory!"), line, fname, 1);
-    return (NULL);
-  }
-  return (p);
-}
-
 void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) {
   void *r;
   void **p = (void **) ptr;
@@ -65,12 +53,3 @@ void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) {
 
   *p = r;
 }
-
-void _mem_free (void *ptr) {
-  void **p = (void **) ptr;
-
-  if (*p) {
-    free (*p);                  /* __MEM_CHECKED__ */
-    *p = 0;
-  }
-}
index 251444e..e46f34d 100644 (file)
--- a/lib/mem.h
+++ b/lib/mem.h
@@ -8,14 +8,10 @@
 
 #include <sys/types.h>
 
-void* _mem_malloc (size_t, int, const char*);
 void* _mem_calloc (size_t, size_t, int, const char*);
 void _mem_realloc (void*, size_t, int, const char*);
-void _mem_free (void*);
 
-#define mem_malloc(s) _mem_malloc(s,__LINE__,__FILE__)
 #define mem_calloc(s,c) _mem_calloc(s,c,__LINE__,__FILE__)
 #define mem_realloc(p,c) _mem_realloc(p,c,__LINE__,__FILE__)
-#define mem_free(x) _mem_free(x)
 
 #endif /* !_LIB_MEM_H */
index c0f6982..772fa8d 100644 (file)
--- a/lib/rx.c
+++ b/lib/rx.c
@@ -8,6 +8,8 @@
 #include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "rx.h"
 
 #include "mem.h"
@@ -25,10 +27,10 @@ rx_t *rx_compile (const char *s, int flags) {
 }
 
 void rx_free (rx_t** p) {
-  mem_free(&(*p)->pattern);
+  p_delete(&(*p)->pattern);
   regfree ((*p)->rx);
-  mem_free(&(*p)->rx);
-  mem_free(p);
+  p_delete(&(*p)->rx);
+  p_delete(p);
 }
 
 int rx_compare (const rx_t* r1, const rx_t* r2) {
index 451b898..11c27b3 100644 (file)
--- a/lib/str.c
+++ b/lib/str.c
 #include <string.h>
 #include <ctype.h>
 
+#include <lib-lib/mem.h>
+
 #include "str.h"
 
 #include "mem.h"
 
 char *str_dup (const char *s)
 {
-  char *p;
-  size_t l;
-
-  if (!s || !*s) return NULL;
-  l = str_len (s) + 1;
-  p = (char *) mem_malloc (l);
-  memcpy (p, s, l);
-  return (p);
+  if (!s || !*s)
+      return NULL;
+  return p_dupstr(s, str_len(s));
 }
 
 char *str_cat (char *d, size_t l, const char *s)
@@ -98,7 +95,7 @@ int str_coll (const char *a, const char *b)
 
 void str_replace (char **p, const char *s)
 {
-  mem_free (p);
+  p_delete(p);
   *p = str_dup (s);
 }
 
@@ -137,20 +134,9 @@ char *str_substrcpy (char *dest, const char *beg, const char *end,
   return dest;
 }
 
-char *str_substrdup (const char *begin, const char *end)
+char *str_substrdup(const char *begin, const char *end)
 {
-  size_t len;
-  char *p;
-
-  if (end)
-    len = end - begin;
-  else
-    len = str_len (begin);
-
-  p = mem_malloc (len + 1);
-  memcpy (p, begin, len);
-  p[len] = 0;
-  return p;
+    return p_dupstr(begin, (end ? end - begin : strlen(begin)));
 }
 
 const char *str_isstr (const char *haystack, const char *needle)
diff --git a/list.c b/list.c
index eee8a4f..b40e97b 100644 (file)
--- a/list.c
+++ b/list.c
@@ -13,6 +13,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <lib-lib/mem.h>
+
 #include "list.h"
 #include "lib/mem.h"
 #include "lib/str.h"
@@ -21,7 +23,7 @@ LIST *mutt_copy_list (LIST * p) {
   LIST *t, *r = NULL, *l = NULL;
 
   for (; p; p = p->next) {
-    t = (LIST *) mem_malloc (sizeof (LIST));
+    t = p_new(LIST, 1);
     t->data = str_dup (p->data);
     t->next = NULL;
     if (l) {
@@ -46,12 +48,12 @@ LIST *mutt_add_list_n (LIST *head, const void *data, size_t len) {
   for (tmp = head; tmp && tmp->next; tmp = tmp->next);
 
   if (tmp) {
-    tmp->next = mem_malloc (sizeof (LIST));
+    tmp->next = p_new(LIST, 1);
     tmp = tmp->next;
   } else
-    head = tmp = mem_malloc (sizeof (LIST));
+    head = tmp = p_new(LIST, 1);
 
-  tmp->data = mem_malloc (len);
+  tmp->data = p_new(char, len);
   if (len)
     memcpy (tmp->data, data, len);
   tmp->next = NULL;
@@ -66,7 +68,7 @@ void mutt_free_list (LIST ** list) {
   while (*list) {
     p = *list;
     *list = (*list)->next;
-    mem_free (&p->data);
-    mem_free (&p);
+    p_delete(&p->data);
+    p_delete(&p);
   }
 }
diff --git a/main.c b/main.c
index 022d5ec..d703022 100644 (file)
--- a/main.c
+++ b/main.c
@@ -19,6 +19,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "keymap.h"
@@ -913,7 +915,7 @@ int main (int argc, char **argv)
             mutt_endwin (NULL);
           perror (tempfile);
           fclose (fin);
-          mem_free (&tempfile);
+          p_delete(&tempfile);
           exit (1);
         }
         if (fin)
@@ -926,7 +928,7 @@ int main (int argc, char **argv)
       }
     }
 
-    mem_free (&bodytext);
+    p_delete(&bodytext);
 
     if (attach) {
       LIST *t = attach;
@@ -1028,7 +1030,7 @@ int main (int argc, char **argv)
       if (option (OPTXTERMSETTITLES))
         mutt_xterm_set_title (NONULL (XtermLeave));
       if (Context)
-        mem_free (&Context);
+        p_delete(&Context);
     }
     mutt_endwin (Errorbuf);
   }
diff --git a/mbox.c b/mbox.c
index a7ee8e1..030b55b 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mx.h"
 #include "buffy.h"
@@ -824,8 +826,8 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
       ctx->hdrs[i]->index = j++;
     }
   }
-  mem_free (&newOffset);
-  mem_free (&oldOffset);
+  p_delete(&newOffset);
+  p_delete(&oldOffset);
   unlink (tempfile);            /* remove partial copy of the mailbox */
   mutt_unblock_signals ();
 
@@ -850,8 +852,8 @@ bail:                          /* Come here in case of disaster */
   mbox_unlock_mailbox (ctx);
 
   mutt_unblock_signals ();
-  mem_free (&newOffset);
-  mem_free (&oldOffset);
+  p_delete(&newOffset);
+  p_delete(&oldOffset);
 
   if ((ctx->fp = freopen (ctx->path, "r", ctx->fp)) == NULL) {
     mutt_error _("Could not reopen mailbox!");
@@ -930,11 +932,11 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint)
   if (ctx->subj_hash)
     hash_destroy (&ctx->subj_hash, NULL);
   mutt_clear_threads (ctx);
-  mem_free (&ctx->v2r);
+  p_delete(&ctx->v2r);
   if (ctx->readonly) {
     for (i = 0; i < ctx->msgcount; i++)
       mutt_free_header (&(ctx->hdrs[i]));       /* nothing to do! */
-    mem_free (&ctx->hdrs);
+    p_delete(&ctx->hdrs);
   }
   else {
     /* save the old headers */
@@ -980,7 +982,7 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint)
     /* free the old headers */
     for (j = 0; j < old_msgcount; j++)
       mutt_free_header (&(old_hdrs[j]));
-    mem_free (&old_hdrs);
+    p_delete(&old_hdrs);
 
     ctx->quiet = 0;
     return (-1);
@@ -1048,7 +1050,7 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint)
         msg_mod = 1;
       }
     }
-    mem_free (&old_hdrs);
+    p_delete(&old_hdrs);
   }
 
   ctx->quiet = 0;
diff --git a/menu.c b/menu.c
index d3f422e..d8f2baf 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mutt_curses.h"
@@ -150,7 +152,7 @@ void menu_pad_string (char *s, size_t n)
 {
   int shift = option (OPTARROWCURSOR) ? 3 : 0;
   int cols;
-  char *tmpbuf = mem_malloc (n);
+  char *tmpbuf = p_new(char, n);
 
   if (option (OPTMBOXPANE))
     cols = COLS - shift - SidebarWidth;
@@ -159,7 +161,7 @@ void menu_pad_string (char *s, size_t n)
   mutt_format_string (tmpbuf, n, cols, cols, 0, ' ', s, str_len (s), 1);
   tmpbuf[n - 1] = 0;
   snprintf (s, n, "%s", tmpbuf);        /* overkill */
-  mem_free (&tmpbuf);
+  p_delete(&tmpbuf);
 }
 
 void menu_redraw_full (MUTTMENU * menu)
@@ -658,16 +660,16 @@ void mutt_menuDestroy (MUTTMENU ** p)
 {
   int i;
 
-  mem_free (&(*p)->searchBuf);
+  p_delete(&(*p)->searchBuf);
 
   if ((*p)->dialog) {
     for (i = 0; i < (*p)->max; i++)
-      mem_free (&(*p)->dialog[i]);
+      p_delete(&(*p)->dialog[i]);
 
-    mem_free (&(*p)->dialog);
+    p_delete(&(*p)->dialog);
   }
 
-  mem_free (p);
+  p_delete(p);
 }
 
 #define M_SEARCH_UP   1
diff --git a/mh.c b/mh.c
index cfe7c36..90cf30a 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -17,6 +17,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mx.h"
 #include "mh.h"
@@ -93,7 +95,7 @@ static void mhs_alloc (struct mh_sequences *mhs, int i)
 
 static void mhs_free_sequences (struct mh_sequences *mhs)
 {
-  mem_free (&mhs->flags);
+  p_delete(&mhs->flags);
 }
 
 static short mhs_check (struct mh_sequences *mhs, int i)
@@ -175,7 +177,7 @@ static void mh_read_sequences (struct mh_sequences *mhs, const char *path)
     }
   }
 
-  mem_free (&buff);
+  p_delete(&buff);
   safe_fclose (&fp);
 }
 
@@ -216,7 +218,7 @@ static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
   }
 
   if ((*fp = fdopen (fd, "w")) == NULL) {
-    mem_free (tgt);
+    p_delete(tgt);
     close (fd);
     unlink (path);
     return (-1);
@@ -364,7 +366,7 @@ void mh_update_sequences (CONTEXT * ctx)
     unlink (tmpfname);
   }
 
-  mem_free (&tmpfname);
+  p_delete(&tmpfname);
 }
 
 static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
@@ -416,7 +418,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
     }
   }
   safe_fclose (&ofp);
-  mem_free (&buff);
+  p_delete(&buff);
 
   if (!unseen_done && unseen)
     fprintf (nfp, "%s: %d\n", NONULL (MhUnseen), n);
@@ -431,7 +433,7 @@ static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
   if (safe_rename (tmpfname, sequences) != 0)
     unlink (tmpfname);
 
-  mem_free (&tmpfname);
+  p_delete(&tmpfname);
 }
 
 static void mh_update_maildir (struct maildir *md, struct mh_sequences *mhs)
@@ -462,11 +464,11 @@ static void maildir_free_entry (struct maildir **md)
   if (!md || !*md)
     return;
 
-  mem_free (&(*md)->canon_fname);
+  p_delete(&(*md)->canon_fname);
   if ((*md)->h)
     mutt_free_header (&(*md)->h);
 
-  mem_free (md);
+  p_delete(md);
 }
 
 static void maildir_free_maildir (struct maildir **md)
@@ -527,7 +529,7 @@ static void maildir_parse_flags (HEADER * h, const char *path)
   }
 
   if (q == h->maildir_flags)
-    mem_free (&h->maildir_flags);
+    p_delete(&h->maildir_flags);
   else if (q)
     *q = '\0';
 }
@@ -904,7 +906,7 @@ void maildir_delayed_parsing (CONTEXT * ctx, struct maildir *md)
     else
       mutt_free_header (&p->h);
 #ifdef USE_HCACHE
-    mem_free (&data);
+    p_delete(&data);
 #endif
   }
 #ifdef USE_HCACHE
@@ -1068,7 +1070,7 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr
   }
 
   if ((msg->fp = fdopen (fd, "w")) == NULL) {
-    mem_free (&msg->path);
+    p_delete(&msg->path);
     close (fd);
     unlink (path);
     return (-1);
@@ -1133,7 +1135,7 @@ static int maildir_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr)
     if (safe_rename (msg->path, full) == 0) {
       if (hdr)
         str_replace (&hdr->path, path);
-      mem_free (&msg->path);
+      p_delete(&msg->path);
 
       /*
        * Adjust the mtime on the file to match the time at which this
@@ -1219,7 +1221,7 @@ static int _mh_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr,
     if (safe_rename (msg->path, path) == 0) {
       if (hdr)
         str_replace (&hdr->path, tmp);
-      mem_free (&msg->path);
+      p_delete(&msg->path);
       break;
     }
     else if (errno != EEXIST) {
@@ -1720,7 +1722,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint, int unused)
       safe_fclose (&fp);
       if (safe_rename (tmp, buf) == -1)
         unlink (tmp);
-      mem_free (&tmp);
+      p_delete(&tmp);
     }
   }
 
index 06c2ecd..1ad3b62 100644 (file)
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "charset.h"
@@ -74,8 +76,8 @@ int mutt_idna_to_local (const char *in, char **out, int flags)
       irrev = 1;
     }
 
-    mem_free (&t2);
-    mem_free (&tmp);
+    p_delete(&t2);
+    p_delete(&tmp);
 
     if (irrev)
       goto notrans;
@@ -84,7 +86,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags)
   return 0;
 
 notrans:
-  mem_free (out);
+  p_delete(out);
   *out = str_dup (in);
   return 1;
 }
@@ -106,9 +108,9 @@ int mutt_local_to_idna (const char *in, char **out)
   if (!rv && idna_to_ascii_8z (tmp, out, 1) != IDNA_SUCCESS)
     rv = -2;
 
-  mem_free (&tmp);
+  p_delete(&tmp);
   if (rv < 0) {
-    mem_free (out);
+    p_delete(out);
     *out = str_dup (in);
   }
   return rv;
@@ -160,9 +162,9 @@ int mutt_addrlist_to_idna (ADDRESS * a, char **err)
       sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp));       /* __SPRINTF_CHECKED__ */
     }
 
-    mem_free (&domain);
-    mem_free (&user);
-    mem_free (&tmp);
+    p_delete(&domain);
+    p_delete(&user);
+    p_delete(&tmp);
 
     if (e)
       return -1;
@@ -187,9 +189,9 @@ int mutt_addrlist_to_local (ADDRESS * a)
       sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp));       /* __SPRINTF_CHECKED__ */
     }
 
-    mem_free (&domain);
-    mem_free (&user);
-    mem_free (&tmp);
+    p_delete(&domain);
+    p_delete(&user);
+    p_delete(&tmp);
   }
 
   return 0;
@@ -206,22 +208,22 @@ const char *mutt_addr_for_display (ADDRESS * a)
   char *domain = NULL;
   char *user = NULL;
 
-  mem_free (&buff);
+  p_delete(&buff);
 
   if (mbox_to_udomain (a->mailbox, &user, &domain) != 0)
     return a->mailbox;
   if (mutt_idna_to_local (domain, &tmp, MI_MAY_BE_IRREVERSIBLE) != 0) {
-    mem_free (&user);
-    mem_free (&domain);
-    mem_free (&tmp);
+    p_delete(&user);
+    p_delete(&domain);
+    p_delete(&tmp);
     return a->mailbox;
   }
 
   mem_realloc (&buff, str_len (tmp) + str_len (user) + 2);
   sprintf (buff, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
-  mem_free (&tmp);
-  mem_free (&user);
-  mem_free (&domain);
+  p_delete(&tmp);
+  p_delete(&user);
+  p_delete(&domain);
   return buff;
 }
 
index 6263662..5524844 100644 (file)
@@ -14,6 +14,8 @@
 #include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "enter.h"
@@ -334,7 +336,7 @@ int mutt_libesmtp_invoke (ADDRESS * from,       /* the sender */
   /* Create hostname:port string and tell libesmtp */
   /* len = SmtpHost len + colon + max port (65536 => 5 chars) + terminator */
   hostportlen = str_len (SmtpHost) + 7;
-  hostportstr = mem_malloc (hostportlen);
+  hostportstr = p_new(char, hostportlen);
   snprintf (hostportstr, hostportlen, "%s:%d", SmtpHost, SmtpPort);
   if (!smtp_set_server (session, hostportstr))
     SMTPFAIL ("smtp_set_server");
@@ -397,7 +399,7 @@ Done:
   if (fp != NULL)
     fclose (fp);
   if (hostportstr != NULL)
-    mem_free (&hostportstr);
+    p_delete(&hostportstr);
   if (session != NULL)
     smtp_destroy_session (session);
   if (authctx != NULL)
index 6b6f0ea..da5ac5f 100644 (file)
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "account.h"
 #include "mutt_sasl.h"
@@ -331,9 +333,7 @@ int mutt_sasl_interact (sasl_interact_t * interaction)
       return SASL_FAIL;
 
     interaction->len = str_len (resp) + 1;
-    interaction->result = mem_malloc (interaction->len);
-    memcpy ((char*) interaction->result, resp, interaction->len);
-
+    interaction->result = p_dupstr(resp, interaction->len - 1);
     interaction++;
   }
 
@@ -358,7 +358,7 @@ int mutt_sasl_interact (sasl_interact_t * interaction)
  *   for the read/write methods. */
 void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn)
 {
-  SASL_DATA *sasldata = (SASL_DATA *) mem_malloc (sizeof (SASL_DATA));
+  SASL_DATA *sasldata = p_new(SASL_DATA, 1);
 
   sasldata->saslconn = saslconn;
   /* get ssf so we know whether we have to (en|de)code read/write */
@@ -452,7 +452,7 @@ static int mutt_sasl_cb_pass (sasl_conn_t * conn, void *context, int id,
 
   len = str_len (account->pass);
 
-  *psecret = (sasl_secret_t *) mem_malloc (sizeof (sasl_secret_t) + len);
+  *psecret = xmalloc(sizeof(sasl_secret_t) + len);
   (*psecret)->len = len;
   strcpy ((char*) (*psecret)->data, account->pass);     /* __STRCPY_CHECKED__ */
 
@@ -494,8 +494,8 @@ static int mutt_sasl_conn_close (CONNECTION * conn)
 
   /* release sasl resources */
   sasl_dispose (&sasldata->saslconn);
-  mem_free (&sasldata->buf);
-  mem_free (&sasldata);
+  p_delete(&sasldata->buf);
+  p_delete(&sasldata);
 
   /* call underlying close */
   rc = (conn->conn_close) (conn);
@@ -525,7 +525,7 @@ static int mutt_sasl_conn_read (CONNECTION * conn, char *buf, size_t len)
 
   conn->sockdata = sasldata->sockdata;
 
-  mem_free (&sasldata->buf);
+  p_delete(&sasldata->buf);
   sasldata->bpos = 0;
   sasldata->blen = 0;
 
@@ -590,7 +590,7 @@ static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf,
       }
 
       rc = (sasldata->msasl_write) (conn, pbuf, plen);
-      mem_free (&pbuf);
+      p_delete(&pbuf);
       if (rc != plen)
         goto fail;
 
index 9029b3e..90a8dde 100644 (file)
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "globals.h"
 #include "mutt_socket.h"
@@ -189,7 +191,7 @@ void mutt_socket_free (CONNECTION * conn)
   /* head is special case, doesn't need prev updated */
   if (iter == conn) {
     Connections = iter->next;
-    mem_free (&iter);
+    p_delete(&iter);
     return;
   }
 
@@ -197,7 +199,7 @@ void mutt_socket_free (CONNECTION * conn)
     if (iter->next == conn) {
       tmp = iter->next;
       iter->next = tmp->next;
-      mem_free (&tmp);
+      p_delete(&tmp);
       return;
     }
     iter = iter->next;
@@ -404,7 +406,7 @@ int raw_socket_open (CONNECTION * conn)
   rc = getaddrinfo (host_idna, port, &hints, &res);
 
 # ifdef HAVE_LIBIDN
-  mem_free (&host_idna);
+  p_delete(&host_idna);
 # endif
 
   if (rc) {
@@ -455,7 +457,7 @@ int raw_socket_open (CONNECTION * conn)
 
   if ((he = gethostbyname (host_idna)) == NULL) {
 # ifdef HAVE_LIBIDN
-    mem_free (&host_idna);
+    p_delete(&host_idna);
 # endif
     mutt_error (_("Could not find the host \"%s\""), conn->account.host);
 
@@ -463,7 +465,7 @@ int raw_socket_open (CONNECTION * conn)
   }
 
 # ifdef HAVE_LIBIDN
-  mem_free (&host_idna);
+  p_delete(&host_idna);
 # endif
 
   mutt_message (_("Connecting to %s..."), conn->account.host);
index 1fb7aa5..801da78 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <string.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_socket.h"
 #include "mutt_menu.h"
@@ -120,11 +122,11 @@ int mutt_ssl_starttls (CONNECTION * conn)
   return 0;
 
 bail_ssl:
-  mem_free (&ssldata->ssl);
+  p_delete(&ssldata->ssl);
 bail_ctx:
-  mem_free (&ssldata->ctx);
+  p_delete(&ssldata->ctx);
 bail_ssldata:
-  mem_free (&ssldata);
+  p_delete(&ssldata);
 bail:
   return -1;
 }
@@ -350,7 +352,7 @@ static int ssl_socket_close (CONNECTION * conn)
 #endif
     SSL_free (data->ssl);
     SSL_CTX_free (data->ctx);
-    mem_free (&conn->sockdata);
+    p_delete(&conn->sockdata);
   }
 
   return raw_socket_close (conn);
index 4028629..a6e2cf4 100644 (file)
@@ -20,6 +20,8 @@
 #include <gnutls/openssl.h>
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_socket.h"
 #include "mutt_curses.h"
@@ -161,7 +163,7 @@ static int tls_negotiate (CONNECTION * conn)
   conn->sockdata = data;
   err = gnutls_certificate_allocate_credentials (&data->xcred);
   if (err < 0) {
-    mem_free (&conn->sockdata);
+    p_delete(&conn->sockdata);
     mutt_error (_("gnutls_certificate_allocate_credentials: %s"),
                 gnutls_strerror (err));
     mutt_sleep (2);
@@ -258,7 +260,7 @@ static int tls_negotiate (CONNECTION * conn)
 fail:
   gnutls_certificate_free_credentials (data->xcred);
   gnutls_deinit (data->state);
-  mem_free (&conn->sockdata);
+  p_delete(&conn->sockdata);
   return -1;
 }
 
@@ -271,7 +273,7 @@ static int tls_socket_close (CONNECTION * conn)
 
     gnutls_certificate_free_credentials (data->xcred);
     gnutls_deinit (data->state);
-    mem_free(&conn->sockdata);
+    p_delete(&conn->sockdata);
   }
 
   return raw_socket_close (conn);
@@ -321,7 +323,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert)
   do {
     ret = gnutls_pem_base64_decode_alloc (NULL, &b64_data, &cert);
     if (ret != 0) {
-      mem_free (&b64_data_data);
+      p_delete(&b64_data_data);
       return 0;
     }
 
@@ -335,7 +337,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert)
       if (memcmp (cert.data, peercert->data, cert.size) == 0) {
         /* match found */
         gnutls_free (cert.data);
-        mem_free (&b64_data_data);
+        p_delete(&b64_data_data);
         return 1;
       }
     }
@@ -344,7 +346,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert)
   } while (ptr != NULL);
 
   /* no match found */
-  mem_free (&b64_data_data);
+  p_delete(&b64_data_data);
   return 0;
 }
 
@@ -417,7 +419,7 @@ static int tls_check_stored_hostname (const gnutls_datum * cert,
           if (str_cmp (linestr + pmatch[1].rm_so, hostname) == 0 &&
               str_cmp (linestr + pmatch[2].rm_so, buf) == 0) {
             regfree (&preg);
-            mem_free(&linestr);
+            p_delete(&linestr);
             fclose (fp);
             return 1;
           }
index 34a5789..6c5a7a3 100644 (file)
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_socket.h"
 #include "mutt_tunnel.h"
@@ -59,7 +61,7 @@ static int tunnel_socket_open (CONNECTION * conn)
   int rc;
   int pin[2], pout[2];
 
-  tunnel = (TUNNEL_DATA *) mem_malloc (sizeof (TUNNEL_DATA));
+  tunnel = p_new(TUNNEL_DATA, 1);
   conn->sockdata = tunnel;
 
   mutt_message (_("Connecting with \"%s\"..."), Tunnel);
@@ -129,7 +131,7 @@ static int tunnel_socket_close (CONNECTION * conn)
                NONULL(mutt_strsysexit(WEXITSTATUS(status))));
     mutt_sleep (2);
   }
-  mem_free (&conn->sockdata);
+  p_delete(&conn->sockdata);
   return 0;
 }
 
index 9c835d1..fd1cea5 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "buffer.h"
@@ -184,12 +186,12 @@ void mutt_free_body (BODY ** p)
     else if (b->filename)
       debug_print (1, ("not unlinking %s.\n", b->filename));
 
-    mem_free (&b->filename);
-    mem_free (&b->content);
-    mem_free (&b->xtype);
-    mem_free (&b->subtype);
-    mem_free (&b->description);
-    mem_free (&b->form_name);
+    p_delete(&b->filename);
+    p_delete(&b->content);
+    p_delete(&b->xtype);
+    p_delete(&b->subtype);
+    p_delete(&b->description);
+    p_delete(&b->form_name);
 
     if (b->hdr) {
       /* Don't free twice (b->hdr->content = b->parts) */
@@ -200,7 +202,7 @@ void mutt_free_body (BODY ** p)
     if (b->parts)
       mutt_free_body (&b->parts);
 
-    mem_free (&b);
+    p_delete(&b);
   }
 
   *p = 0;
@@ -212,11 +214,11 @@ void mutt_free_parameter (PARAMETER ** p)
   PARAMETER *o;
 
   while (t) {
-    mem_free (&t->attribute);
-    mem_free (&t->value);
+    p_delete(&t->attribute);
+    p_delete(&t->value);
     o = t;
     t = t->next;
-    mem_free (&o);
+    p_delete(&o);
   }
   *p = 0;
 }
@@ -236,16 +238,16 @@ void mutt_free_header (HEADER ** h)
     return;
   mutt_free_envelope (&(*h)->env);
   mutt_free_body (&(*h)->content);
-  mem_free (&(*h)->maildir_flags);
-  mem_free (&(*h)->tree);
-  mem_free (&(*h)->path);
+  p_delete(&(*h)->maildir_flags);
+  p_delete(&(*h)->tree);
+  p_delete(&(*h)->path);
 #ifdef MIXMASTER
   mutt_free_list (&(*h)->chain);
 #endif
 #if defined USE_POP || defined USE_IMAP || defined USE_NNTP
-  mem_free (&(*h)->data);
+  p_delete(&(*h)->data);
 #endif
-  mem_free (h);
+  p_delete(h);
 }
 
 /* returns true if the header contained in "s" is in list "t" */
@@ -591,26 +593,26 @@ void mutt_free_envelope (ENVELOPE ** p)
   rfc822_free_address (&(*p)->reply_to);
   rfc822_free_address (&(*p)->mail_followup_to);
 
-  mem_free (&(*p)->list_post);
-  mem_free (&(*p)->subject);
+  p_delete(&(*p)->list_post);
+  p_delete(&(*p)->subject);
   /* real_subj is just an offset to subject and shouldn't be freed */
-  mem_free (&(*p)->message_id);
-  mem_free (&(*p)->supersedes);
-  mem_free (&(*p)->date);
-  mem_free (&(*p)->x_label);
-  mem_free (&(*p)->organization);
+  p_delete(&(*p)->message_id);
+  p_delete(&(*p)->supersedes);
+  p_delete(&(*p)->date);
+  p_delete(&(*p)->x_label);
+  p_delete(&(*p)->organization);
 #ifdef USE_NNTP
-  mem_free (&(*p)->newsgroups);
-  mem_free (&(*p)->xref);
-  mem_free (&(*p)->followup_to);
-  mem_free (&(*p)->x_comment_to);
+  p_delete(&(*p)->newsgroups);
+  p_delete(&(*p)->xref);
+  p_delete(&(*p)->followup_to);
+  p_delete(&(*p)->x_comment_to);
 #endif
 
   mutt_buffer_free (&(*p)->spam);
   mutt_free_list (&(*p)->references);
   mutt_free_list (&(*p)->in_reply_to);
   mutt_free_list (&(*p)->userhdrs);
-  mem_free (p);
+  p_delete(p);
 }
 
 /* move all the headers from extra not present in base into base */
@@ -674,9 +676,9 @@ void mutt_free_alias (ALIAS ** p)
   while (*p) {
     t = *p;
     *p = (*p)->next;
-    mem_free (&t->name);
+    p_delete(&t->name);
     rfc822_free_address (&t->addr);
-    mem_free (&t);
+    p_delete(&t);
   }
 }
 
@@ -830,13 +832,13 @@ int mutt_check_overwrite (const char *attname, const char *path,
         str_replace (directory, fname);
         break;
       case 1:                  /* yes */
-        mem_free (directory);
+        p_delete(directory);
         break;
       case -1:                 /* abort */
-        mem_free (directory);
+        p_delete(directory);
         return -1;
       case 2:                  /* no */
-        mem_free (directory);
+        p_delete(directory);
         return 1;
       }
     }
@@ -1116,15 +1118,14 @@ void mutt_FormatString (char *dest,     /* output buffer */
     }
     else {
       unsigned int bar = mutt_skipchars (src, "%\\");
-      char *bar2 = mem_malloc (bar + 1);
+      char *bar2 = p_dupstr(src, bar);
 
-      strfcpy (bar2, src, bar + 1);
       while (bar--) {
         *wptr++ = *src++;
         wlen++;
       }
       col += mutt_strwidth (bar2);
-      mem_free (&bar2);
+      p_delete(&bar2);
     }
   }
   *wptr = 0;
@@ -1156,7 +1157,7 @@ FILE *mutt_open_read (const char *path, pid_t * thepid)
         s[len - 1] = 0;
         mutt_endwin (NULL);
         *thepid = mutt_create_filter (s, NULL, &f, NULL);
-        mem_free (&s);
+        p_delete(&s);
     } else {
         f = fopen (path, "r");
         if (!f)
@@ -1314,8 +1315,8 @@ void mutt_free_spam_list (SPAM_LIST ** list)
     p = *list;
     *list = (*list)->next;
     rx_free (&p->rx);
-    mem_free(&p->template);
-    mem_free(&p);
+    p_delete(&p->template);
+    p_delete(&p);
   }
 }
 
diff --git a/mx.c b/mx.c
index cb65b9f..e173aad 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffy.h"
 #include "ascii.h"
@@ -518,8 +520,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
   int rc;
 
   if (!ctx)
-    ctx = mem_malloc (sizeof (CONTEXT));
-  memset (ctx, 0, sizeof (CONTEXT));
+    ctx = p_new(CONTEXT, 1);
+  p_clear(ctx, 1);
   ctx->path = str_dup (path);
 
   ctx->msgnotreadyet = -1;
@@ -536,7 +538,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
     if (mx_open_mailbox_append (ctx, flags) != 0) {
       mx_fastclose_mailbox (ctx);
       if (!pctx)
-        mem_free (&ctx);
+        p_delete(&ctx);
       return NULL;
     }
     return ctx;
@@ -559,7 +561,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
   if (ctx->magic <= 0) {
     mx_fastclose_mailbox (ctx);
     if (!pctx)
-      mem_free (&ctx);
+      p_delete(&ctx);
     return (NULL);
   }
 
@@ -589,7 +591,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx)
   else {
     mx_fastclose_mailbox (ctx);
     if (!pctx)
-      mem_free (&ctx);
+      p_delete(&ctx);
   }
 
   unset_option (OPTFORCEREFRESH);
@@ -613,14 +615,14 @@ void mx_fastclose_mailbox (CONTEXT * ctx)
   mutt_clear_threads (ctx);
   for (i = 0; i < ctx->msgcount; i++)
     mutt_free_header (&ctx->hdrs[i]);
-  mem_free (&ctx->hdrs);
-  mem_free (&ctx->v2r);
+  p_delete(&ctx->hdrs);
+  p_delete(&ctx->v2r);
 #ifdef USE_COMPRESSED
   if (ctx->compressinfo)
     mutt_fast_close_compressed (ctx);
 #endif
-  mem_free (&ctx->path);
-  mem_free (&ctx->pattern);
+  p_delete(&ctx->path);
+  p_delete(&ctx->pattern);
   if (ctx->limit_pattern)
     mutt_pattern_free (&ctx->limit_pattern);
   safe_fclose (&ctx->fp);
@@ -1161,7 +1163,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags)
     }
   }
   else
-    mem_free (&msg);
+    p_delete(&msg);
 
   return msg;
 }
@@ -1212,7 +1214,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
       if (msg->fp == NULL) {
         mutt_perror (path);
         debug_print (1, ("fopen: %s: %s (errno %d).\n", path, strerror (errno), errno));
-        mem_free (&msg);
+        p_delete(&msg);
       }
     }
     break;
@@ -1221,7 +1223,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
   case M_IMAP:
     {
       if (imap_fetch_message (msg, ctx, msgno) != 0)
-        mem_free (&msg);
+        p_delete(&msg);
       break;
     }
 #endif /* USE_IMAP */
@@ -1230,7 +1232,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
   case M_POP:
     {
       if (pop_fetch_message (msg, ctx, msgno) != 0)
-        mem_free (&msg);
+        p_delete(&msg);
       break;
     }
 #endif /* USE_POP */
@@ -1239,14 +1241,14 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno)
   case M_NNTP:
     {
       if (nntp_fetch_message (msg, ctx, msgno) != 0)
-        mem_free (&msg);
+        p_delete(&msg);
       break;
     }
 #endif /* USE_NNTP */
 
   default:
     debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic));
-    mem_free (&msg);
+    p_delete(&msg);
     break;
   }
   return (msg);
@@ -1288,10 +1290,10 @@ int mx_close_message (MESSAGE ** msg)
   if ((*msg)->path) {
     debug_print (1, ("unlinking %s\n", (*msg)->path));
     unlink ((*msg)->path);
-    mem_free (&(*msg)->path);
+    p_delete(&(*msg)->path);
   }
 
-  mem_free (msg);
+  p_delete(msg);
   return (r);
 }
 
@@ -1353,7 +1355,7 @@ void mx_update_context (CONTEXT * ctx, int new_messages)
 
       h2 = hash_find (ctx->id_hash, h->env->supersedes);
 
-      /* mem_free (&h->env->supersedes); should I ? */
+      /* p_delete(&h->env->supersedes); should I ? */
       if (h2) {
         h2->superseded = 1;
         if (!ctx->counting && option (OPTSCORE))
index cd309ea..3d7196b 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <sys/stat.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "nntp.h"
 
index 898b148..3f707ab 100644 (file)
@@ -13,6 +13,8 @@
 #include <config.h>
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "sort.h"
@@ -87,7 +89,7 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line)
     nntp_add_to_list (news, data);
   }
   else
-    mem_free (&data->entries);
+    p_delete(&data->entries);
 
   data->rc = 1;
   data->entries = mem_calloc (x * 2, sizeof (NEWSRC_ENTRY));
@@ -149,10 +151,10 @@ static int slurp_newsrc (NNTP_SERVER * news)
     return -1;
   }
 
-  buf = mem_malloc (sb.st_size + 1);
+  buf = p_new(char, sb.st_size + 1);
   while (fgets (buf, sb.st_size + 1, fp))
     nntp_parse_newsrc_line (news, buf);
-  mem_free (&buf);
+  p_delete(&buf);
 
   mx_unlock_file (news->newsrc, fileno (fp), 0);
   fclose (fp);
@@ -200,7 +202,7 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news)
 
   set_option (OPTNEWSCACHE);
 
-  mem_free (&news->cache);
+  p_delete(&news->cache);
   snprintf (buf, sizeof (buf), "%s/.index", dir);
   if (!(index = safe_fopen (buf, "a+")))
     return 0;
@@ -305,7 +307,7 @@ int nntp_parse_url (const char *server, ACCOUNT * acct,
     ret = mutt_account_fromurl (acct, &url);
   }
 
-  mem_free (&c);
+  p_delete(&c);
   return ret;
 }
 
@@ -316,7 +318,7 @@ void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
   url.path = str_dup (line);
   mutt_account_tourl (acct, &url);
   url_ciss_tostring (&url, line, len, 0);
-  mem_free (&url.path);
+  p_delete(&url.path);
 }
 
 /*
@@ -354,11 +356,11 @@ NNTP_SERVER *mutt_select_newsserver (char *server)
   strcpy (p, server);
 
   if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
-    mem_free (&buf);
+    p_delete(&buf);
     mutt_error (_("%s is an invalid newsserver specification!"), server);
     return NULL;
   }
-  mem_free (&buf);
+  p_delete(&buf);
 
   conn = mutt_conn_find (NULL, &acct);
   if (!conn)
@@ -409,9 +411,9 @@ NNTP_SERVER *mutt_select_newsserver (char *server)
     for (list = serv->list; list; list = list->next)
       list->data = NULL;
     mutt_free_list (&serv->list);
-    mem_free (&serv->newsrc);
-    mem_free (&serv->cache);
-    mem_free (&serv);
+    p_delete(&serv->newsrc);
+    p_delete(&serv->cache);
+    p_delete(&serv);
     return NULL;
   }
   nntp_clear_cacheindex (serv);
@@ -773,7 +775,7 @@ int mutt_newsrc_update (NNTP_SERVER * news)
     news->size = st.st_size;
     news->mtime = st.st_mtime;
   }
-  mem_free (&buf);
+  p_delete(&buf);
   return r;
 }
 
@@ -980,7 +982,7 @@ void nntp_delete_cache (NNTP_DATA * data)
 
   nntp_cache_expand (buf, data->cache);
   unlink (buf);
-  mem_free (&data->cache);
+  p_delete(&data->cache);
   data->lastCached = 0;
   nntp_cache_expand (buf, ".index");
   mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
index 391d66e..84e106f 100644 (file)
@@ -13,6 +13,8 @@
 #include <config.h>
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "sort.h"
@@ -346,7 +348,7 @@ static int mutt_nntp_fetch (NNTP_DATA * nntp_data, const char *query, char *msg,
 
     ret = 0;
     line = 0;
-    inbuf = mem_malloc (sizeof (buf));
+    inbuf = p_new(char, sizeof(buf));
 
     FOREVER {
       chunk = mutt_socket_readln_d (buf, sizeof (buf), nntp_data->nserv->conn,
@@ -390,7 +392,7 @@ static int mutt_nntp_fetch (NNTP_DATA * nntp_data, const char *query, char *msg,
 
       mem_realloc (&inbuf, lenbuf + sizeof (buf));
     }
-    mem_free (&inbuf);
+    p_delete(&inbuf);
     funct (NULL, data);
   }
   while (!done);
@@ -512,7 +514,7 @@ static int parse_description (char *line, void *n)
   debug_print (2, ("group: %s, desc: %s\n", line, d));
   if ((data = (NNTP_DATA *) hash_find (news->newsgroups, line)) != NULL &&
       str_cmp (d, data->desc)) {
-    mem_free (&data->desc);
+    p_delete(&data->desc);
     data->desc = str_dup (d);
   }
   return 0;
@@ -598,7 +600,7 @@ static int nntp_parse_xover (CONTEXT * ctx, char *buf, HEADER * hdr)
       hdr->received = hdr->date_sent;
       break;
     case 4:
-      mem_free (&hdr->env->message_id);
+      p_delete(&hdr->env->message_id);
       hdr->env->message_id = str_dup (b);
       break;
     case 5:
@@ -613,7 +615,7 @@ static int nntp_parse_xover (CONTEXT * ctx, char *buf, HEADER * hdr)
       break;
     case 8:
       if (!hdr->read)
-        mem_free (&hdr->env->xref);
+        p_delete(&hdr->env->xref);
       b = b + 6;                /* skips the "Xref: " */
       hdr->env->xref = str_dup (b);
       nntp_parse_xref (ctx, nntp_data->group, b, hdr);
@@ -722,7 +724,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
 #ifdef DEBUG
       nntp_error ("nntp_fetch_headers()", buf);
 #endif
-      mem_free (&fc.messages);
+      p_delete(&fc.messages);
       return -1;
     }
   }
@@ -769,7 +771,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
   }
   num = last - first + 1;
   if (num <= 0) {
-    mem_free (&fc.messages);
+    p_delete(&fc.messages);
     return 0;
   }
 
@@ -792,7 +794,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
 #ifdef DEBUG
       nntp_error ("nntp_fetch_headers()", buf);
 #endif
-      mem_free (&fc.messages);
+      p_delete(&fc.messages);
       return -1;
     }
     /* fetched OK */
@@ -821,14 +823,14 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
       else
         mutt_free_header (&h);  /* skip it */
       if (ret == -1) {
-        mem_free (&fc.messages);
+        p_delete(&fc.messages);
         return -1;
       }
 
       if (current > nntp_data->lastLoaded)
         nntp_data->lastLoaded = current;
     }
-  mem_free (&fc.messages);
+  p_delete(&fc.messages);
   nntp_data->lastLoaded = last;
   mutt_clear_error ();
   return 0;
@@ -951,13 +953,13 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
 
   /* clear the previous entry */
   unlink (cache->path);
-  mem_free (&cache->path);
+  p_delete(&cache->path);
 
   cache->index = ctx->hdrs[msgno]->index;
   mutt_mktemp (path);
   cache->path = str_dup (path);
   if (!(msg->fp = safe_fopen (path, "w+"))) {
-    mem_free (&cache->path);
+    p_delete(&cache->path);
     return -1;
   }
 
@@ -983,7 +985,7 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
   if (ret) {
     fclose (msg->fp);
     unlink (path);
-    mem_free (&cache->path);
+    p_delete(&cache->path);
     return -1;
   }
 
@@ -1110,22 +1112,22 @@ static void nntp_free_acache (NNTP_DATA * data)
   for (i = 0; i < NNTP_CACHE_LEN; i++) {
     if (data->acache[i].path) {
       unlink (data->acache[i].path);
-      mem_free (&data->acache[i].path);
+      p_delete(&data->acache[i].path);
     }
   }
 }
 
 void nntp_delete_data (void *p)
 {
-  NNTP_DATA *data = (NNTP_DATA *) p;
+  NNTP_DATA *data = (NNTP_DATA *)p;
 
   if (!p)
     return;
-  mem_free (&data->entries);
-  mem_free (&data->desc);
-  mem_free (&data->cache);
+  p_delete(&data->entries);
+  p_delete(&data->desc);
+  p_delete(&data->cache);
   nntp_free_acache (data);
-  mem_free (p);
+  p_delete(&data);
 }
 
 int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2)
@@ -1292,7 +1294,7 @@ static int add_group (char *buf, void *serv)
   else
     nntp_data->allowed = 0;
   if (nntp_data->desc)
-    mem_free (&nntp_data->desc);
+    p_delete(&nntp_data->desc);
   if (*desc)
     nntp_data->desc = str_dup (desc);
   if (nntp_data->rc || nntp_data->lastCached)
@@ -1399,7 +1401,7 @@ int nntp_get_cache_all (NNTP_SERVER * serv)
     return 0;
   }
   else {
-    mem_free (&serv->cache);
+    p_delete(&serv->cache);
     return -1;
   }
 }
@@ -1527,9 +1529,9 @@ int nntp_check_children (CONTEXT * ctx, const char *msgid)
   cc.ctx = ctx;
   cc.num = 0;
   cc.max = 25;
-  cc.child = mem_malloc (sizeof (unsigned int) * 25);
+  cc.child = p_new(unsigned int, 25);
   if (mutt_nntp_fetch (nntp_data, buf, NULL, NULL, check_children, &cc, 0)) {
-    mem_free (&cc.child);
+    p_delete(&cc.child);
     return -1;
   }
   /* dont try to read the xover cache. check_children() already
@@ -1549,6 +1551,6 @@ int nntp_check_children (CONTEXT * ctx, const char *msgid)
   }
   if (tmp)
     set_option (OPTNEWSCACHE);
-  mem_free (&cc.child);
+  p_delete(&cc.child);
   return ret;
 }
diff --git a/pager.c b/pager.c
index d68d041..c3800df 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "mutt_curses.h"
@@ -353,8 +355,8 @@ static void cleanup_quote (struct q_class_t **QuoteList)
       cleanup_quote (&((*QuoteList)->down));
     ptr = (*QuoteList)->next;
     if ((*QuoteList)->prefix)
-      mem_free (&(*QuoteList)->prefix);
-    mem_free (QuoteList);
+      p_delete(&(*QuoteList)->prefix);
+    p_delete(QuoteList);
     *QuoteList = ptr;
   }
 
@@ -1158,7 +1160,7 @@ display_line (FILE * f, off_t *last_pos, struct line_t **lineInfo, int n,
       memset (&((*lineInfo)[ch]), 0, sizeof (struct line_t));
       (*lineInfo)[ch].type = -1;
       (*lineInfo)[ch].search_cnt = -1;
-      (*lineInfo)[ch].syntax = mem_malloc (sizeof (struct syntax_t));
+      (*lineInfo)[ch].syntax = p_new(struct syntax_t, 1);
       ((*lineInfo)[ch].syntax)[0].first = ((*lineInfo)[ch].syntax)[0].last =
         -1;
     }
@@ -1233,7 +1235,7 @@ display_line (FILE * f, off_t *last_pos, struct line_t **lineInfo, int n,
         mem_realloc (&((*lineInfo)[n].search),
                       ((*lineInfo)[n].search_cnt) * sizeof (struct syntax_t));
       else
-        (*lineInfo)[n].search = mem_malloc (sizeof (struct syntax_t));
+        (*lineInfo)[n].search = p_new(struct syntax_t, 1);
       pmatch[0].rm_so += offset;
       pmatch[0].rm_eo += offset;
       ((*lineInfo)[n].search)[(*lineInfo)[n].search_cnt - 1].first =
@@ -1470,12 +1472,12 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
     mutt_set_flag (Context, extra->hdr, M_READ, 1);
   }
 
-  lineInfo = mem_malloc (sizeof (struct line_t) * (maxLine = LINES));
+  lineInfo = p_new(struct line_t, maxLine = LINES);
   for (i = 0; i < maxLine; i++) {
     memset (&lineInfo[i], 0, sizeof (struct line_t));
     lineInfo[i].type = -1;
     lineInfo[i].search_cnt = -1;
-    lineInfo[i].syntax = mem_malloc (sizeof (struct syntax_t));
+    lineInfo[i].syntax = p_new(struct syntax_t, 1);
     (lineInfo[i].syntax)[0].first = (lineInfo[i].syntax)[0].last = -1;
   }
 
@@ -1553,7 +1555,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
         lines = Resize->line;
         redraw |= REDRAW_SIGWINCH;
 
-        mem_free (&Resize);
+        p_delete(&Resize);
       }
 #endif
 
@@ -1736,7 +1738,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
           lines++;
 
       if (flags & M_PAGER_RETWINCH) {
-        Resize = mem_malloc (sizeof (struct resize));
+        Resize = p_new(struct resize, 1);
 
         Resize->line = lines;
         Resize->SearchCompiled = SearchCompiled;
@@ -1756,7 +1758,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
 
           mem_realloc (&(lineInfo[i].syntax), sizeof (struct syntax_t));
           if (SearchCompiled && lineInfo[i].search)
-            mem_free (&(lineInfo[i].search));
+            p_delete(&(lineInfo[i].search));
         }
 
         lastLine = 0;
@@ -1932,7 +1934,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
         regfree (&SearchRE);
         for (i = 0; i < lastLine; i++) {
           if (lineInfo[i].search)
-            mem_free (&(lineInfo[i].search));
+            p_delete(&(lineInfo[i].search));
           lineInfo[i].search_cnt = -1;
         }
       }
@@ -1946,7 +1948,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
         for (i = 0; i < maxLine; i++) {
           /* cleanup */
           if (lineInfo[i].search)
-            mem_free (&(lineInfo[i].search));
+            p_delete(&(lineInfo[i].search));
           lineInfo[i].search_cnt = -1;
         }
         SearchFlag = 0;
@@ -2238,7 +2240,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
 
           mem_realloc (&(lineInfo[i].syntax), sizeof (struct syntax_t));
           if (SearchCompiled && lineInfo[i].search)
-            mem_free (&(lineInfo[i].search));
+            p_delete(&(lineInfo[i].search));
         }
 
         if (SearchCompiled) {
@@ -2627,15 +2629,15 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
   cleanup_quote (&QuoteList);
 
   for (i = 0; i < maxLine; i++) {
-    mem_free (&(lineInfo[i].syntax));
+    p_delete(&(lineInfo[i].syntax));
     if (SearchCompiled && lineInfo[i].search)
-      mem_free (&(lineInfo[i].search));
+      p_delete(&(lineInfo[i].search));
   }
   if (SearchCompiled) {
     regfree (&SearchRE);
     SearchCompiled = 0;
   }
-  mem_free (&lineInfo);
+  p_delete(&lineInfo);
   if (index)
     mutt_menuDestroy (&index);
   return (rc != -1 ? rc : 0);
diff --git a/parse.c b/parse.c
index 5b88380..23e6c86 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "enter.h"
@@ -112,7 +114,7 @@ LIST *mutt_parse_references (char *s, int in_reply_to)
     else if (o) {
       m = str_len (s);
       if (s[m - 1] == '>') {
-        new = mem_malloc (sizeof (char) * (n + m + 1));
+        new = p_new(char, n + m + 1);
         strcpy (new, o);        /* __STRCPY_CHECKED__ */
         strcpy (new + n, s);    /* __STRCPY_CHECKED__ */
       }
@@ -126,9 +128,9 @@ LIST *mutt_parse_references (char *s, int in_reply_to)
        */
       if (!(at = strchr (new, '@')) || strchr (at + 1, '@')
           || (in_reply_to && at - new <= 8))
-        mem_free (&new);
+        p_delete(&new);
       else {
-        t = (LIST *) mem_malloc (sizeof (LIST));
+        t = p_new(LIST, 1);
         t->data = new;
         t->next = lst;
         lst = t;
@@ -187,9 +189,7 @@ static PARAMETER *parse_parameters (const char *s)
 
       new = mutt_new_parameter ();
 
-      new->attribute = mem_malloc (i + 1);
-      memcpy (new->attribute, s, i);
-      new->attribute[i] = 0;
+      new->attribute = p_dupstr(s, i);
 
       /* remove whitespace from the end of the attribute name */
       while (ISSPACE (new->attribute[--i]))
@@ -307,7 +307,7 @@ void mutt_parse_content_type (char *s, BODY * ct)
   char *pc;
   char *subtype;
 
-  mem_free (&ct->subtype);
+  p_delete(&ct->subtype);
   mutt_free_parameter (&ct->parameter);
 
   /* First extract any existing parameters */
@@ -420,7 +420,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
 {
   BODY *p = mutt_new_body ();
   char *c;
-  char *line = mem_malloc (LONG_STRING);
+  char *line = p_new(char, LONG_STRING);
   size_t linelen = LONG_STRING;
 
   p->hdr_offset = ftello (fp);
@@ -478,7 +478,7 @@ BODY *mutt_read_mime_header (FILE * fp, int digest)
   else if (p->type == TYPEMESSAGE && !p->subtype)
     p->subtype = str_dup ("rfc822");
 
-  mem_free (&line);
+  p_delete(&line);
 
   return (p);
 }
@@ -911,19 +911,13 @@ time_t mutt_parse_date (const char *s, HEADER * h)
 }
 
 /* extract the first substring that looks like a message-id */
-static char *extract_message_id (const char *s)
+static char *extract_message_id(const char *s)
 {
-  const char *p;
-  char *r;
-  size_t l;
+    const char *p;
 
-  if ((s = strchr (s, '<')) == NULL || (p = strchr (s, '>')) == NULL)
-    return (NULL);
-  l = (size_t) (p - s) + 1;
-  r = mem_malloc (l + 1);
-  memcpy (r, s, l);
-  r[l] = 0;
-  return (r);
+    if ((s = strchr(s, '<')) == NULL || (p = strchr(s, '>')) == NULL)
+        return NULL;
+    return p_dupstr(s, (p - s));
 }
 
 void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur)
@@ -1092,7 +1086,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
 
           /* Take the first mailto URL */
           if (url_check_scheme (beg) == U_MAILTO) {
-            mem_free (&e->list_post);
+            p_delete(&e->list_post);
             e->list_post = str_substrdup (beg, end);
             break;
           }
@@ -1110,7 +1104,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
     }
     else if (!ascii_strcasecmp (line + 1, "essage-id")) {
       /* We add a new "Message-ID:" when building a message */
-      mem_free (&e->message_id);
+      p_delete(&e->message_id);
       e->message_id = extract_message_id (p);
       matched = 1;
     }
@@ -1131,7 +1125,7 @@ int mutt_parse_rfc822_line (ENVELOPE * e, HEADER * hdr, char *line, char *p,
 #ifdef USE_NNTP
   case 'n':
     if (!str_casecmp (line + 1, "ewsgroups")) {
-      mem_free (&e->newsgroups);
+      p_delete(&e->newsgroups);
       str_skip_trailws (p);
       e->newsgroups = str_dup (str_skip_initws (p));
       matched = 1;
@@ -1305,7 +1299,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
 {
   ENVELOPE *e = mutt_new_envelope ();
   LIST *last = NULL;
-  char *line = mem_malloc (LONG_STRING);
+  char *line = p_new(char, LONG_STRING);
   char *p;
   off_t loc;
   int matched;
@@ -1396,7 +1390,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
 
   }
 
-  mem_free (&line);
+  p_delete(&line);
 
   if (hdr) {
     hdr->content->hdr_offset = hdr->offset;
index c06f5f8..1ca87e4 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "buffer.h"
 #include "handler.h"
@@ -211,8 +213,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
       }
     }
 
-    blen = STRING;
-    buf = mem_malloc (blen);
+    buf = p_new(char, blen = STRING);
 
     /* search the file "fp" */
     while (lng > 0) {
@@ -228,7 +229,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
       lng -= str_len (buf);
     }
 
-    mem_free (&buf);
+    p_delete(&buf);
 
     mx_close_message (&msg);
 
@@ -267,15 +268,15 @@ int eat_regexp (pattern_t * pat, BUFFER * s, BUFFER * err)
 
   if (pat->stringmatch) {
     pat->str = str_dup (buf.data);
-    mem_free (&buf.data);
+    p_delete(&buf.data);
   } else {
-    pat->rx = mem_malloc (sizeof (regex_t));
+    pat->rx = p_new(regex_t, 1);
     r = REGCOMP (pat->rx, buf.data, REG_NEWLINE | REG_NOSUB | mutt_which_case (buf.data));
-    mem_free (&buf.data);
+    p_delete(&buf.data);
     if (r) {
       regerror (r, pat->rx, err->data, err->dsize);
       regfree (pat->rx);
-      mem_free (&pat->rx);
+      p_delete(&pat->rx);
       return (-1);
     }
   }
@@ -603,7 +604,7 @@ static int eat_date (pattern_t * pat, BUFFER * s, BUFFER * err)
     if (isdigit ((unsigned char) *pc)) {
       /* mininum date specified */
       if ((pc = getDate (pc, &min, err)) == NULL) {
-        mem_free (&buffer.data);
+        p_delete(&buffer.data);
         return (-1);
       }
       haveMin = TRUE;
@@ -636,7 +637,7 @@ static int eat_date (pattern_t * pat, BUFFER * s, BUFFER * err)
       max.tm_mday = min.tm_mday;
 
       if (!parse_date_range (pc, &min, &max, haveMin, &baseMin, err)) { /* bail out on any parsing error */
-        mem_free (&buffer.data);
+        p_delete(&buffer.data);
         return (-1);
       }
     }
@@ -648,7 +649,7 @@ static int eat_date (pattern_t * pat, BUFFER * s, BUFFER * err)
   pat->min = mutt_mktime (&min, 1);
   pat->max = mutt_mktime (&max, 1);
 
-  mem_free (&buffer.data);
+  p_delete(&buffer.data);
 
   return 0;
 }
@@ -689,12 +690,12 @@ void mutt_pattern_free (pattern_t ** pat)
 
     if (tmp->rx) {
       regfree (tmp->rx);
-      mem_free (&tmp->rx);
+      p_delete(&tmp->rx);
     }
-    mem_free (&tmp->str);
+    p_delete(&tmp->str);
     if (tmp->child)
       mutt_pattern_free (&tmp->child);
-    mem_free (&tmp);
+    p_delete(&tmp);
   }
 }
 
@@ -818,11 +819,11 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
       /* compile the sub-expression */
       buf = str_substrdup (ps.dptr + 1, p);
       if ((tmp = mutt_pattern_comp (buf, flags, err)) == NULL) {
-        mem_free (&buf);
+        p_delete(&buf);
         mutt_pattern_free (&curlist);
         return NULL;
       }
-      mem_free (&buf);
+      p_delete(&buf);
       if (last)
         last->next = tmp;
       else
@@ -1215,7 +1216,7 @@ int mutt_pattern_func (int op, char *prompt)
   err.data = error;
   err.dsize = sizeof (error);
   if ((pat = mutt_pattern_comp (buf, M_FULL_MSG, &err)) == NULL) {
-    mem_free (&simple);
+    p_delete(&simple);
     mutt_error ("%s", err.data);
     return (-1);
   }
@@ -1280,7 +1281,7 @@ int mutt_pattern_func (int op, char *prompt)
 
   if (op == M_LIMIT) {
     /* drop previous limit pattern */
-    mem_free (&Context->pattern);
+    p_delete(&Context->pattern);
     if (Context->limit_pattern)
       mutt_pattern_free (&Context->limit_pattern);
     if (Context->msgcount && !Context->vcount) {
@@ -1294,7 +1295,7 @@ int mutt_pattern_func (int op, char *prompt)
       Context->limit_pattern = mutt_pattern_comp (buf, M_FULL_MSG, &err);
     }
   }
-  mem_free (&simple);
+  p_delete(&simple);
   mutt_pattern_free (&pat);
   return 0;
 }
diff --git a/pgp.c b/pgp.c
index da199ce..4603a94 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -21,6 +21,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "ascii.h"
@@ -161,7 +163,7 @@ static int pgp_copy_checksig (FILE * fpin, FILE * fpout)
       fputs (line, fpout);
       fputc ('\n', fpout);
     }
-    mem_free (&line);
+    p_delete(&line);
   }
   else {
     debug_print (2, ("No pattern.\n"));
@@ -1142,7 +1144,7 @@ char *pgp_findKeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
           k_info = pgp_getkeybystr (keyID, KEYFLAG_CANENCRYPT, PGP_PUBRING);
       }
       else if (r == -1) {
-        mem_free (&keylist);
+        p_delete(&keylist);
         rfc822_free_address (&tmp);
         rfc822_free_address (&addr);
         return NULL;
@@ -1159,7 +1161,7 @@ char *pgp_findKeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
 
       if ((key = pgp_ask_for_key (buf, q->mailbox,
                                   KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) {
-        mem_free (&keylist);
+        p_delete(&keylist);
         rfc822_free_address (&tmp);
         rfc822_free_address (&addr);
         return NULL;
index a02a5f3..26d1d42 100644 (file)
@@ -25,6 +25,8 @@
 #include <fcntl.h>
 #include <time.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mutt_idna.h"
index 3804817..1136ee5 100644 (file)
--- a/pgpkey.c
+++ b/pgpkey.c
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "ascii.h"
@@ -625,7 +627,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s)
   }
 
   mutt_menuDestroy (&menu);
-  mem_free (&KeyTable);
+  p_delete(&KeyTable);
 
   set_option (OPTNEEDREDRAW);
 
@@ -661,7 +663,7 @@ pgp_key_t pgp_ask_for_key (char *tag, char *whatfor,
       if (l)
         str_replace (&l->dflt, resp);
       else {
-        l = mem_malloc (sizeof (struct pgp_cache));
+        l = p_new(struct pgp_cache, 1);
         l->next = id_defaults;
         id_defaults = l;
         l->what = str_dup (whatfor);
@@ -770,7 +772,7 @@ static LIST *pgp_add_string_to_hints (LIST * hints, const char *str)
       hints = mutt_add_list (hints, t);
   }
 
-  mem_free (&scratch);
+  p_delete(&scratch);
   return hints;
 }
 
index 26b029b..364f1a9 100644 (file)
--- a/pgplib.c
+++ b/pgplib.c
@@ -19,6 +19,8 @@
 #include <unistd.h>
 #include <time.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "lib.h"
 #include "pgplib.h"
@@ -116,7 +118,7 @@ void pgp_free_sig (pgp_sig_t ** sigp)
 
   for (sp = *sigp; sp; sp = q) {
     q = sp->next;
-    mem_free (&sp);
+    p_delete(&sp);
   }
 
   *sigp = NULL;
@@ -131,8 +133,8 @@ void pgp_free_uid (pgp_uid_t ** upp)
   for (up = *upp; up; up = q) {
     q = up->next;
     pgp_free_sig (&up->sigs);
-    mem_free (&up->addr);
-    mem_free (&up);
+    p_delete(&up->addr);
+    p_delete(&up);
   }
 
   *upp = NULL;
@@ -165,8 +167,8 @@ static void _pgp_free_key (pgp_key_t * kpp)
   kp = *kpp;
 
   pgp_free_uid (&kp->address);
-  mem_free (&kp->keyid);
-  mem_free (kpp);
+  p_delete(&kp->keyid);
+  p_delete(kpp);
 }
 
 pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
index 9d48470..7fd8962 100644 (file)
@@ -17,6 +17,8 @@
 #include <unistd.h>
 #include <time.h>
 
+#include <lib-lib/mem.h>
+
 #include "sha1.h"
 #include "lib.h"
 #include "pgplib.h"
@@ -65,8 +67,7 @@ unsigned char *pgp_read_packet (FILE * fp, size_t * len)
   startpos = ftello (fp);
 
   if (!plen) {
-    plen = CHUNKSIZE;
-    pbuf = mem_malloc (plen);
+    pbuf = p_new(char, plen = CHUNKSIZE);
   }
 
   if (fread (&ctb, 1, 1, fp) < 1) {
@@ -200,5 +201,5 @@ bail:
 void pgp_release_packet (void)
 {
   plen = 0;
-  mem_free (&pbuf);
+  p_delete(&pbuf);
 }
index baf5b16..9f2ee46 100644 (file)
@@ -26,6 +26,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "lib/mem.h"
 #include "lib/str.h"
 
@@ -252,7 +254,7 @@ static pgp_key_t pgp_parse_pgp2_key (unsigned char *buff, size_t l)
 
 bailout:
 
-  mem_free (&p);
+  p_delete(&p);
   return NULL;
 }
 
@@ -667,10 +669,7 @@ static pgp_key_t pgp_parse_keyblock (FILE * fp)
         if (!addr)
           break;
 
-        chr = mem_malloc (l);
-        memcpy (chr, buff + 1, l - 1);
-        chr[l - 1] = '\0';
-
+        chr = p_dupstr(buff + 1, l - 1);
 
         *addr = uid = mem_calloc (1, sizeof (pgp_uid_t));      /* XXX */
         uid->addr = chr;
@@ -744,10 +743,10 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
     size_t error_buf_len;
 
     error_buf_len = sizeof ("fopen: ") - 1 + str_len (ringfile) + 1;
-    error_buf = mem_malloc (error_buf_len);
+    error_buf = p_new(char, error_buf_len);
     snprintf (error_buf, error_buf_len, "fopen: %s", ringfile);
     perror (error_buf);
-    mem_free (&error_buf);
+    p_delete(&error_buf);
     return;
   }
 
@@ -764,10 +763,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
       keypos = pos;
     }
     else if (pt == PT_NAME) {
-      char *tmp = mem_malloc (l);
-
-      memcpy (tmp, buff + 1, l - 1);
-      tmp[l - 1] = '\0';
+      char *tmp = p_dupstr(buff + 1, l - 1);
 
       /* mutt_decode_utf8_string (tmp, chs); */
 
@@ -785,7 +781,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[],
         pgp_free_key (&p);
       }
 
-      mem_free (&tmp);
+      p_delete(&tmp);
     }
 
     FGETPOS (rfp, pos);
index 3262dca..822471e 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <sys/stat.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "pop.h"
 
index 34d1cc7..b8e9e06 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mx.h"
 #include "pop.h"
@@ -246,7 +248,7 @@ int pop_open_mailbox (CONTEXT * ctx)
   if (!conn)
     return -1;
 
-  mem_free (&ctx->path);
+  p_delete(&ctx->path);
   ctx->path = str_dup (buf);
 
   pop_data = mem_calloc (1, sizeof (POP_DATA));
@@ -291,7 +293,7 @@ static void pop_clear_cache (POP_DATA * pop_data)
   for (i = 0; i < POP_CACHE_LEN; i++) {
     if (pop_data->cache[i].path) {
       unlink (pop_data->cache[i].path);
-      mem_free (&pop_data->cache[i].path);
+      p_delete(&pop_data->cache[i].path);
     }
   }
 }
@@ -349,7 +351,7 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
     else {
       /* clear the previous entry */
       unlink (cache->path);
-      mem_free (&cache->path);
+      p_delete(&cache->path);
     }
   }
 
@@ -532,7 +534,7 @@ void pop_fetch_mail (void)
   strcpy (p, PopHost);          /* __STRCPY_CHECKED__ */
 
   ret = pop_parse_path (url, &acct);
-  mem_free (&url);
+  p_delete(&url);
   if (ret) {
     mutt_error (_("%s is an invalid POP path"), PopHost);
     return;
@@ -547,7 +549,7 @@ void pop_fetch_mail (void)
 
   if (pop_open_connection (pop_data) < 0) {
     mutt_socket_free (pop_data->conn);
-    mem_free (&pop_data);
+    p_delete(&pop_data);
     return;
   }
 
@@ -649,11 +651,11 @@ finish:
   if (pop_query (pop_data, buffer, sizeof (buffer)) == PQ_NOT_CONNECTED)
     goto fail;
   mutt_socket_close (conn);
-  mem_free (&pop_data);
+  p_delete(&pop_data);
   return;
 
 fail:
   mutt_error _("Server closed connection!");
   mutt_socket_close (conn);
-  mem_free (&pop_data);
+  p_delete(&pop_data);
 }
index c7b62a9..9382072 100644 (file)
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mx.h"
@@ -125,7 +127,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
       /* sasl_client_st(art|ep) allocate pc with malloc, expect me to 
        * free it */
 #ifndef USE_SASL
-      mem_free (&pc);
+      p_delete(&pc);
 #endif
     }
   }
@@ -161,7 +163,7 @@ void pop_apop_timestamp (POP_DATA * pop_data, char *buf)
 {
   char *p1, *p2;
 
-  mem_free (&pop_data->timestamp);
+  p_delete(&pop_data->timestamp);
 
   if ((p1 = strchr (buf, '<')) && (p2 = strchr (p1, '>'))) {
     p2[1] = '\0';
@@ -343,7 +345,7 @@ pop_query_status pop_authenticate (POP_DATA * pop_data)
       method = comma;
     }
 
-    mem_free (&methods);
+    p_delete(&methods);
   }
   else {
     /* Fall back to default: any authenticator */
index 4aa3409..603fa05 100644 (file)
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mx.h"
@@ -54,7 +56,7 @@ int pop_parse_path (const char *path, ACCOUNT * acct)
       ret = 0;
   }
 
-  mem_free (&c);
+  p_delete(&c);
   return ret;
 }
 
@@ -85,7 +87,7 @@ static int fetch_capa (char *line, void *data)
   char *c;
 
   if (!ascii_strncasecmp (line, "SASL", 4)) {
-    mem_free (&pop_data->auth_list);
+    p_delete(&pop_data->auth_list);
     c = line + 4;
     SKIPWS (c);
     pop_data->auth_list = str_dup (c);
@@ -112,10 +114,8 @@ static int fetch_auth (char *line, void *data)
   POP_DATA *pop_data = (POP_DATA *) data;
 
   if (!pop_data->auth_list) {
-    pop_data->auth_list = mem_malloc (strlen (line) + 1);
-    *pop_data->auth_list = '\0';
-  }
-  else {
+    pop_data->auth_list = p_new(char, strlen(line) + 1);
+  } else {
     mem_realloc (&pop_data->auth_list,
                   strlen (pop_data->auth_list) + strlen (line) + 2);
     strcat (pop_data->auth_list, " ");  /* __STRCAT_CHECKED__ */
@@ -149,7 +149,7 @@ static pop_query_status pop_capabilities (POP_DATA * pop_data, int mode)
     pop_data->resp_codes = 0;
     pop_data->expire = 1;
     pop_data->login_delay = 0;
-    mem_free (&pop_data->auth_list);
+    p_delete(&pop_data->auth_list);
   }
 
   /* Execute CAPA command */
@@ -444,7 +444,7 @@ pop_query_status pop_fetch_data (POP_DATA * pop_data, const char *query, progres
   if (ret != PQ_OK)
     return ret;
 
-  inbuf = mem_malloc (sizeof (buf));
+  inbuf = p_new(char, sizeof(buf));
 
   FOREVER {
     chunk =
@@ -480,7 +480,7 @@ pop_query_status pop_fetch_data (POP_DATA * pop_data, const char *query, progres
     mem_realloc (&inbuf, lenbuf + sizeof (buf));
   }
 
-  mem_free (&inbuf);
+  p_delete(&inbuf);
   return ret;
 }
 
index 0b1d689..f7d7328 100644 (file)
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "enter.h"
@@ -252,7 +254,7 @@ int mutt_get_postponed (CONTEXT * ctx, HEADER * hdr, HEADER ** cur, char *fcc,
   if (!PostContext->msgcount) {
     PostCount = 0;
     mx_close_mailbox (PostContext, NULL);
-    mem_free (&PostContext);
+    p_delete(&PostContext);
     mutt_error _("No postponed messages.");
 
     return (-1);
@@ -264,13 +266,13 @@ int mutt_get_postponed (CONTEXT * ctx, HEADER * hdr, HEADER ** cur, char *fcc,
   }
   else if ((h = select_msg ()) == NULL) {
     mx_close_mailbox (PostContext, NULL);
-    mem_free (&PostContext);
+    p_delete(&PostContext);
     return (-1);
   }
 
   if (mutt_prepare_template (NULL, PostContext, hdr, h, 0) < 0) {
     mx_fastclose_mailbox (PostContext);
-    mem_free (&PostContext);
+    p_delete(&PostContext);
     return (-1);
   }
 
@@ -289,7 +291,7 @@ int mutt_get_postponed (CONTEXT * ctx, HEADER * hdr, HEADER ** cur, char *fcc,
   mx_close_mailbox (PostContext, NULL);
   set_quadoption (OPT_DELETE, opt_delete);
 
-  mem_free (&PostContext);
+  p_delete(&PostContext);
 
   for (tmp = hdr->env->userhdrs; tmp;) {
     if (ascii_strncasecmp ("X-Mutt-References:", tmp->data, 18) == 0) {
@@ -528,8 +530,8 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr,
   newhdr->content->length = hdr->content->length;
   mutt_parse_part (fp, newhdr->content);
 
-  mem_free (&newhdr->env->message_id);
-  mem_free (&newhdr->env->mail_followup_to);        /* really? */
+  p_delete(&newhdr->env->message_id);
+  p_delete(&newhdr->env->mail_followup_to);        /* really? */
 
   /* decrypt pgp/mime encoded messages */
 
diff --git a/query.c b/query.c
index 1443bac..893d2db 100644 (file)
--- a/query.c
+++ b/query.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_menu.h"
 #include "mutt_idna.h"
@@ -126,7 +128,7 @@ static QUERY *run_query (char *s, int quiet)
       }
     }
   }
-  mem_free (&buf);
+  p_delete(&buf);
   fclose (fp);
   if (mutt_wait_filter (thepid)) {
     debug_print (1, ("Error: %s\n", msg));
@@ -310,14 +312,14 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf)
               queryp = results;
               while (queryp) {
                 rfc822_free_address (&queryp->addr);
-                mem_free (&queryp->name);
-                mem_free (&queryp->other);
+                p_delete(&queryp->name);
+                p_delete(&queryp->other);
                 results = queryp->next;
-                mem_free (&queryp);
+                p_delete(&queryp);
                 queryp = results;
               }
               results = newresults;
-              mem_free (&QueryTable);
+              p_delete(&QueryTable);
             }
             else {
               /* append */
@@ -473,13 +475,13 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf)
     queryp = results;
     while (queryp) {
       rfc822_free_address (&queryp->addr);
-      mem_free (&queryp->name);
-      mem_free (&queryp->other);
+      p_delete(&queryp->name);
+      p_delete(&queryp->other);
       results = queryp->next;
-      mem_free (&queryp);
+      p_delete(&queryp);
       queryp = results;
     }
-    mem_free (&QueryTable);
+    p_delete(&QueryTable);
 
     /* tell whoever called me to redraw the screen when I return */
     set_option (OPTNEEDREDRAW);
index d0272e3..a592e15 100644 (file)
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "enter.h"
@@ -62,7 +64,7 @@ static struct mapping_t AttachHelp[] = {
 
 static int mutt_extract_path (char *filename, char *path)
 {
-  char *tmp = mem_malloc (sizeof (char) * _POSIX_PATH_MAX);
+  char *tmp = p_new(char, _POSIX_PATH_MAX);
   char *help_ptr;
 
   help_ptr = tmp;
@@ -76,7 +78,7 @@ static int mutt_extract_path (char *filename, char *path)
     }
     *help_ptr++ = *filename++;
   }
-  mem_free (&tmp);
+  p_delete(&tmp);
   return 0;
 }
 
@@ -550,7 +552,7 @@ void mutt_save_attachment_list (FILE * fp, int tag, BODY * top, HEADER * hdr,
       break;
   }
 
-  mem_free (&directory);
+  p_delete(&directory);
 
   if (tag && menu) {
     menu->oldcurrent = menu->current;
@@ -1241,12 +1243,12 @@ void mutt_view_attachments (HEADER * hdr)
           hdr->attach_del = 1;
         if (idx[idxmax]->content)
           idx[idxmax]->content->aptr = NULL;
-        mem_free (&idx[idxmax]->tree);
-        mem_free (&idx[idxmax]);
+        p_delete(&idx[idxmax]->tree);
+        p_delete(&idx[idxmax]);
       }
       if (hdr->attach_del)
         hdr->changed = 1;
-      mem_free (&idx);
+      p_delete(&idx);
       idxmax = 0;
 
       if (WithCrypto && need_secured && secured) {
index 00029bb..8f59859 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "state.h"
@@ -153,7 +155,7 @@ void mutt_attach_bounce (FILE * fp, HEADER * hdr,
 
   if (mutt_addrlist_to_idna (adr, &err) < 0) {
     mutt_error (_("Bad IDN: '%s'"), err);
-    mem_free (&err);
+    p_delete(&err);
     rfc822_free_address (&adr);
     return;
   }
diff --git a/regex.c b/regex.c
index 3a5faa9..c3da5ce 100644 (file)
--- a/regex.c
+++ b/regex.c
@@ -3634,7 +3634,7 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs,
 
 /* Free everything we malloc.  */
 #ifdef MATCH_MAY_ALLOCATE
-#define mem_free_VAR(var) if (var) REGEX_mem_free (var); var = NULL
+#define mem_free_VAR(var) if (var) REGEX_p_delete(var); var = NULL
 #define mem_free_VARIABLES()                                                \
   do {                                                                        \
     REGEX_mem_free_STACK (fail_stack.stack);                                \
index 79d0c12..08dc174 100644 (file)
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "recvattach.h"
 #include "mutt_curses.h"
@@ -118,11 +120,11 @@ static REMAILER *mix_new_remailer (void)
 
 static void mix_free_remailer (REMAILER ** r)
 {
-  mem_free (&(*r)->shortname);
-  mem_free (&(*r)->addr);
-  mem_free (&(*r)->ver);
+  p_delete(&(*r)->shortname);
+  p_delete(&(*r)->addr);
+  p_delete(&(*r)->ver);
 
-  mem_free (r);
+  p_delete(r);
 }
 
 /* parse the type2.list as given by mixmaster -T */
@@ -212,7 +214,7 @@ static void mix_free_type2_list (REMAILER *** ttlp)
   for (i = 0; type2_list[i]; i++)
     mix_free_remailer (&type2_list[i]);
 
-  mem_free (type2_list);
+  p_delete(type2_list);
 }
 
 
@@ -661,8 +663,8 @@ void mix_make_chain (LIST ** chainp, int *redraw)
   }
 
   mix_free_type2_list (&type2_list);
-  mem_free (&coords);
-  mem_free (&chain);
+  p_delete(&coords);
+  p_delete(&chain);
 }
 
 /* some safety checks before piping the message to mixmaster */
index b02ab4d..c0397ad 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -21,6 +21,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "rfc1524.h"
@@ -274,7 +276,7 @@ static int rfc1524_mailcap_parse (BODY * a,
               /* a non-zero exit code means test failed */
               found = FALSE;
             }
-            mem_free (&test_command);
+            p_delete(&test_command);
           }
         }
       }                         /* while (ch) */
@@ -299,13 +301,13 @@ static int rfc1524_mailcap_parse (BODY * a,
       if (!found) {
         /* reset */
         if (entry) {
-          mem_free (&entry->command);
-          mem_free (&entry->composecommand);
-          mem_free (&entry->composetypecommand);
-          mem_free (&entry->editcommand);
-          mem_free (&entry->printcommand);
-          mem_free (&entry->nametemplate);
-          mem_free (&entry->convert);
+          p_delete(&entry->command);
+          p_delete(&entry->composecommand);
+          p_delete(&entry->composetypecommand);
+          p_delete(&entry->editcommand);
+          p_delete(&entry->printcommand);
+          p_delete(&entry->nametemplate);
+          p_delete(&entry->convert);
           entry->needsterminal = 0;
           entry->copiousoutput = 0;
         }
@@ -313,7 +315,7 @@ static int rfc1524_mailcap_parse (BODY * a,
     }                           /* while (!found && (buf = mutt_read_line ())) */
     fclose (fp);
   }                             /* if ((fp = fopen ())) */
-  mem_free (&buf);
+  p_delete(&buf);
   return found;
 }
 
@@ -326,14 +328,14 @@ void rfc1524_free_entry (rfc1524_entry ** entry)
 {
   rfc1524_entry *p = *entry;
 
-  mem_free (&p->command);
-  mem_free (&p->testcommand);
-  mem_free (&p->composecommand);
-  mem_free (&p->composetypecommand);
-  mem_free (&p->editcommand);
-  mem_free (&p->printcommand);
-  mem_free (&p->nametemplate);
-  mem_free (entry);
+  p_delete(&p->command);
+  p_delete(&p->testcommand);
+  p_delete(&p->composecommand);
+  p_delete(&p->composetypecommand);
+  p_delete(&p->editcommand);
+  p_delete(&p->printcommand);
+  p_delete(&p->nametemplate);
+  p_delete(entry);
 }
 
 /*
index e173254..ae4a52b 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -12,6 +12,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mime.h"
@@ -62,11 +64,11 @@ static size_t convert_string (const char *f, size_t flen,
   if (cd == (iconv_t) (-1))
     return (size_t) (-1);
   obl = 4 * flen + 1;
-  ob = buf = mem_malloc (obl);
+  ob = buf = p_new(char, obl);
   n = my_iconv(cd, &f, &flen, &ob, &obl);
   if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
     e = errno;
-    mem_free (&buf);
+    p_delete(&buf);
     iconv_close (cd);
     errno = e;
     return (size_t) (-1);
@@ -104,9 +106,7 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets,
         n > (ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 2 - 12))
       continue;
 
-    t = mem_malloc (n + 1);
-    memcpy (t, p, n);
-    t[n] = '\0';
+    t = p_dupstr(p, n);
 
     n = convert_string (u, ulen, fromcode, t, &s, &slen);
     if (n == (size_t) (-1))
@@ -114,21 +114,21 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets,
 
     if (!tocode || n < bestn) {
       bestn = n;
-      mem_free (&tocode);
+      p_delete(&tocode);
       tocode = t;
       if (d) {
-        mem_free (&e);
+        p_delete(&e);
         e = s;
       }
       else
-        mem_free (&s);
+        p_delete(&s);
       elen = slen;
       if (!bestn)
         break;
     }
     else {
-      mem_free (&t);
-      mem_free (&s);
+      p_delete(&t);
+      p_delete(&s);
     }
   }
   if (tocode) {
@@ -363,9 +363,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col,
   if (convert_string (d, dlen, fromcode, icode, &u, &ulen)) {
     ret = 1;
     icode = 0;
-    u = mem_malloc ((ulen = dlen) + 1);
-    memcpy (u, d, dlen);
-    u[ulen] = 0;
+    u = p_dupstr(d, ulen = dlen);
   }
 
   /* Find earliest and latest things we must encode. */
@@ -448,7 +446,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col,
 
   /* Initialise the output buffer with the us-ascii prefix. */
   buflen = 2 * ulen;
-  buf = mem_malloc (buflen);
+  buf = p_new(char, buflen);
   bufpos = t0 - u;
   memcpy (buf, u, t0 - u);
 
@@ -506,8 +504,8 @@ static int rfc2047_encode (const char *d, size_t dlen, int col,
   bufpos += wlen;
   memcpy (buf + bufpos, t1, u + ulen - t1);
 
-  mem_free (&tocode1);
-  mem_free (&u);
+  p_delete(&tocode1);
+  p_delete(&u);
 
   buf[buflen] = '\0';
 
@@ -533,7 +531,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col)
                   Charset, charsets, &e, &elen,
                   encode_specials ? RFC822Specials : NULL);
 
-  mem_free (pd);
+  p_delete(pd);
   *pd = e;
 }
 
@@ -557,7 +555,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
   int enc = 0, count = 0;
   char *charset = NULL;
 
-  pd = d0 = mem_malloc (str_len (s));
+  pd = d0 = p_new(char, str_len(s));
 
   for (pp = s; (pp1 = strchr (pp, '?')); pp = pp1 + 1) {
     count++;
@@ -567,9 +565,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
       t = pp1;
       if ((t1 = memchr (pp, '*', t - pp)))
         t = t1;
-      charset = mem_malloc (t - pp + 1);
-      memcpy (charset, pp, t - pp);
-      charset[t - pp] = '\0';
+      charset = p_dupstr(pp, t - pp);
       break;
     case 3:
       if (toupper ((unsigned char) *pp) == 'Q')
@@ -577,8 +573,8 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
       else if (toupper ((unsigned char) *pp) == 'B')
         enc = ENCBASE64;
       else {
-        mem_free (&charset);
-        mem_free (&d0);
+        p_delete(&charset);
+        p_delete(&d0);
         return (-1);
       }
       break;
@@ -625,8 +621,8 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
   if (charset)
     mutt_convert_string (&d0, charset, Charset, M_ICONV_HOOK_FROM);
   strfcpy (d, d0, len);
-  mem_free (&charset);
-  mem_free (&d0);
+  p_delete(&charset);
+  p_delete(&d0);
   return (0);
 }
 
@@ -714,7 +710,7 @@ void rfc2047_decode (char **pd)
     return;
 
   dlen = 4 * str_len (s);        /* should be enough */
-  d = d0 = mem_malloc (dlen + 1);
+  d = d0 = p_new(char, dlen + 1);
 
   while (*s && dlen > 0) {
     if (!(p = find_encoded_word (s, &q))) {
@@ -730,8 +726,7 @@ void rfc2047_decode (char **pd)
           char *t;
           size_t tlen;
 
-          t = mem_malloc (n + 1);
-          strfcpy (t, s, n + 1);
+          t = p_dupstr(s, n);
           if (mutt_convert_nonmime_string (&t) == 0) {
             tlen = str_len (t);
             strncpy (d, t, tlen);
@@ -741,7 +736,7 @@ void rfc2047_decode (char **pd)
             strncpy (d, s, n);
             d += n;
           }
-          mem_free (&t);
+          p_delete(&t);
           break;
         }
       }
@@ -789,7 +784,7 @@ void rfc2047_decode (char **pd)
   }
   *d = 0;
 
-  mem_free (pd);
+  p_delete(pd);
   *pd = d0;
   str_adjust (pd);
 }
index c3986a4..04f9515 100644 (file)
--- a/rfc2231.c
+++ b/rfc2231.c
@@ -21,6 +21,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mime.h"
@@ -146,7 +148,7 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
 
       p->attribute = NULL;
       p->value = NULL;
-      mem_free (&p);
+      p_delete(&p);
 
       rfc2231_list_insert (&conthead, conttmp);
     }
@@ -171,9 +173,9 @@ static struct rfc2231_parameter *rfc2231_new_parameter (void)
 static void rfc2231_free_parameter (struct rfc2231_parameter **p)
 {
   if (*p) {
-    mem_free (&(*p)->attribute);
-    mem_free (&(*p)->value);
-    mem_free (p);
+    p_delete(&(*p)->attribute);
+    p_delete(&(*p)->value);
+    p_delete(p);
   }
 }
 
@@ -331,7 +333,7 @@ int rfc2231_encode_string (char **pd)
       ++ext;
 
   if (encode) {
-    e = mem_malloc (dlen + 2 * ext + str_len (charset) + 3);
+    e = p_new(char, dlen + 2 * ext + str_len(charset) + 3);
     sprintf (e, "%s''", charset);       /* __SPRINTF_CHECKED__ */
     t = e + str_len (e);
     for (s = d, slen = dlen; slen; s++, slen--)
@@ -345,16 +347,16 @@ int rfc2231_encode_string (char **pd)
     *t = '\0';
 
     if (d != *pd)
-      mem_free (&d);
-    mem_free (pd);
+      p_delete(&d);
+    p_delete(pd);
     *pd = e;
   }
   else if (d != *pd) {
-    mem_free (pd);
+    p_delete(pd);
     *pd = d;
   }
 
-  mem_free (&charset);
+  p_delete(&charset);
 
   return encode;
 }
index f6ca099..d359f25 100644 (file)
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -20,6 +20,8 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "ascii.h"
@@ -136,7 +138,7 @@ static void print_flowed_line (char *line, STATE * s, int ql) {
 int rfc3676_handler (BODY * a, STATE * s) {
   int bytes = a->length;
   char buf[LONG_STRING];
-  char *curline = mem_malloc(1);
+  char *curline = p_new(char, 1);
   char *t = NULL;
   unsigned int curline_len = 1,
                quotelevel = 0, newql = 0;
@@ -222,7 +224,7 @@ int rfc3676_handler (BODY * a, STATE * s) {
     }
 
   }
-  mem_free (&curline);
+  p_delete(&curline);
   return (0);
 }
 
index 5dc33e2..18c980f 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
@@ -15,6 +15,8 @@
 #include <ctype.h>
 #include <stdlib.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mutt_idna.h"
@@ -71,9 +73,9 @@ void rfc822_free_address (ADDRESS ** p)
   while (*p) {
     t = *p;
     *p = (*p)->next;
-    mem_free (&t->personal);
-    mem_free (&t->mailbox);
-    mem_free (&t);
+    p_delete(&t->personal);
+    p_delete(&t->mailbox);
+    p_delete(&t);
   }
 }
 
@@ -390,7 +392,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS * top, const char *s)
       cur = rfc822_new_address ();
       if (phraselen) {
         if (cur->personal)
-          mem_free (&cur->personal);
+          p_delete(&cur->personal);
         /* if we get something like "Michael R. Elkins" remove the quotes */
         rfc822_dequote_comment (phrase);
         cur->personal = str_dup (phrase);
@@ -447,9 +449,9 @@ void rfc822_qualify (ADDRESS * addr, const char *host)
 
   for (; addr; addr = addr->next)
     if (!addr->group && addr->mailbox && strchr (addr->mailbox, '@') == NULL) {
-      p = mem_malloc (str_len (addr->mailbox) + str_len (host) + 2);
+      p = p_new(char, str_len(addr->mailbox) + str_len(host) + 2);
       sprintf (p, "%s@%s", addr->mailbox, host);        /* __SPRINTF_CHECKED__ */
-      mem_free (&addr->mailbox);
+      p_delete(&addr->mailbox);
       addr->mailbox = p;
     }
 }
diff --git a/score.c b/score.c
index 5d401dc..071b0fa 100644 (file)
--- a/score.c
+++ b/score.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "sort.h"
 #include "buffer.h"
@@ -71,7 +73,7 @@ int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data,
   memset (buf, 0, sizeof (BUFFER));
   mutt_extract_token (buf, s, 0);
   if (MoreArgs (s)) {
-    mem_free (&pattern);
+    p_delete(&pattern);
     strfcpy (err->data, _("score: too many arguments"), err->dsize);
     return (-1);
   }
@@ -83,7 +85,7 @@ int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data,
       break;
   if (!ptr) {
     if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
-      mem_free (&pattern);
+      p_delete(&pattern);
       return (-1);
     }
     ptr = mem_calloc (1, sizeof (SCORE));
@@ -141,7 +143,7 @@ int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
         last = tmp;
         tmp = tmp->next;
         mutt_pattern_free (&last->pat);
-        mem_free (&last);
+        p_delete(&last);
       }
       Score = NULL;
     }
@@ -153,7 +155,7 @@ int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
           else
             Score = tmp->next;
           mutt_pattern_free (&tmp->pat);
-          mem_free (&tmp);
+          p_delete(&tmp);
           /* there should only be one score per pattern, so we can stop here */
           break;
         }
diff --git a/send.c b/send.c
index 32370e3..d2a743a 100644 (file)
--- a/send.c
+++ b/send.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "ascii.h"
@@ -196,7 +198,7 @@ static int edit_address (ADDRESS ** a, const char *field)
       mutt_error (_("Error: '%s' is a bad IDN."), err);
       mutt_refresh ();
       mutt_sleep (2);
-      mem_free (&err);
+      p_delete(&err);
     }
   }
   while (idna_ok != 0);
@@ -217,7 +219,7 @@ static int edit_envelope (ENVELOPE * en, int flags)
       buf[0] = 0;
     if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) != 0)
       return (-1);
-    mem_free (&en->newsgroups);
+    p_delete(&en->newsgroups);
     en->newsgroups = str_dup (buf);
 
     if (en->followup_to)
@@ -227,7 +229,7 @@ static int edit_envelope (ENVELOPE * en, int flags)
     if (option (OPTASKFOLLOWUP)
         && mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) != 0)
       return (-1);
-    mem_free (&en->followup_to);
+    p_delete(&en->followup_to);
     en->followup_to = str_dup (buf);
 
     if (en->x_comment_to)
@@ -237,7 +239,7 @@ static int edit_envelope (ENVELOPE * en, int flags)
     if (option (OPTXCOMMENTTO) && option (OPTASKXCOMMENTTO)
         && mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) != 0)
       return (-1);
-    mem_free (&en->x_comment_to);
+    p_delete(&en->x_comment_to);
     en->x_comment_to = str_dup (buf);
   }
   else
@@ -649,8 +651,8 @@ void mutt_make_misc_reply_headers (ENVELOPE * env, CONTEXT * ctx,
    * been taken from a List-Post header.  Is that correct?
    */
   if (curenv->real_subj) {
-    mem_free (&env->subject);
-    env->subject = mem_malloc (str_len (curenv->real_subj) + 5);
+    p_delete(&env->subject);
+    env->subject = p_new(char, str_len(curenv->real_subj) + 5);
     sprintf (env->subject, "Re: %s", curenv->real_subj);        /* __SPRINTF_CHECKED__ */
   }
   else if (!env->subject)
@@ -964,7 +966,7 @@ static ADDRESS *set_reverse_name (ENVELOPE * env)
   if (tmp) {
     tmp = rfc822_cpy_adr_real (tmp);
     if (!option (OPTREVREAL))
-      mem_free (&tmp->personal);
+      p_delete(&tmp->personal);
     if (!tmp->personal)
       tmp->personal = str_dup (Realname);
   }
@@ -985,8 +987,7 @@ ADDRESS *mutt_default_from (void)
     adr = rfc822_cpy_adr_real (From);
   else if (option (OPTUSEDOMAIN)) {
     adr = rfc822_new_address ();
-    adr->mailbox =
-      mem_malloc (str_len (Username) + str_len (fqdn) + 2);
+    adr->mailbox = p_new(char, str_len(Username) + str_len(fqdn) + 2);
     sprintf (adr->mailbox, "%s@%s", NONULL (Username), NONULL (fqdn));  /* __SPRINTF_CHECKED__ */
   }
   else {
@@ -1197,7 +1198,7 @@ int ci_send_message (int flags, /* send mode */
     if (!(ctype = str_dup (ContentType)))
       ctype = str_dup ("text/plain");
     mutt_parse_content_type (ctype, msg->content);
-    mem_free (&ctype);
+    p_delete(&ctype);
 
     msg->content->unlink = 1;
     msg->content->use_disp = 0;
@@ -1578,7 +1579,7 @@ int ci_send_message (int flags, /* send mode */
 
   if (mutt_env_to_idna (msg->env, &tag, &err)) {
     mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
-    mem_free (&err);
+    p_delete(&err);
     if (!(flags & SENDBATCH))
       goto main_loop;
     else
@@ -1653,7 +1654,7 @@ int ci_send_message (int flags, /* send mode */
           mutt_protect (msg, pgpkeylist) == -1) {
         msg->content = mutt_remove_multipart (msg->content);
 
-        mem_free (&pgpkeylist);
+        p_delete(&pgpkeylist);
 
         decode_descriptions (msg->content);
         goto main_loop;
@@ -1817,7 +1818,7 @@ int ci_send_message (int flags, /* send mode */
 #endif
 
   if (WithCrypto && (msg->security & ENCRYPT))
-    mem_free (&pgpkeylist);
+    p_delete(&pgpkeylist);
 
   if (WithCrypto && free_clear_content)
     mutt_free_body (&clear_content);
@@ -1839,7 +1840,7 @@ cleanup:
 
   if ((WithCrypto & APPLICATION_PGP) && (flags & SENDPOSTPONED)) {
     if (signas) {
-      mem_free (&PgpSignAs);
+      p_delete(&PgpSignAs);
       PgpSignAs = signas;
     }
   }
index 7de69ea..0dca3d5 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "handler.h"
@@ -318,7 +320,7 @@ int mutt_write_mime_header (BODY * a, FILE * f)
           && !strcmp (buffer, tmp))
         snprintf (buffer, sizeof (buffer), "\"%s\"", tmp);
 
-      mem_free (&tmp);
+      p_delete(&tmp);
 
       tmplen = str_len (buffer) + str_len (p->attribute) + 1;
 
@@ -360,7 +362,7 @@ int mutt_write_mime_header (BODY * a, FILE * f)
       tmp = str_dup (t);
       encode = rfc2231_encode_string (&tmp);
       rfc822_cat (buffer, sizeof (buffer), tmp, MimeSpecials);
-      mem_free (&tmp);
+      p_delete(&tmp);
       fprintf (f, "; filename%s=%s", encode ? "*" : "", buffer);
     }
   }
@@ -709,10 +711,10 @@ static size_t convert_file_to (FILE * file, const char *fromcode,
       iconv_close (cd[i]);
 
   iconv_close (cd1);
-  mem_free (&cd);
-  mem_free (&infos);
-  mem_free (&score);
-  mem_free (&states);
+  p_delete(&cd);
+  p_delete(&infos);
+  p_delete(&score);
+  p_delete(&states);
 
   return ret;
 #else
@@ -751,7 +753,7 @@ static size_t convert_file_from_to (FILE * file,
   }
 
   /* Copy them */
-  tcode = mem_malloc (ncodes * sizeof (char *));
+  tcode = p_new(char *, ncodes);
   for (c = tocodes, i = 0; c; c = c1 ? c1 + 1 : 0, i++) {
     if ((c1 = strchr (c, ':')) == c)
       continue;
@@ -774,7 +776,7 @@ static size_t convert_file_from_to (FILE * file,
         tcode[cn] = 0;
         break;
       }
-      mem_free (&fcode);
+      p_delete(&fcode);
     }
   }
   else {
@@ -789,9 +791,9 @@ static size_t convert_file_from_to (FILE * file,
 
   /* Free memory */
   for (i = 0; i < ncodes; i++)
-    mem_free (&tcode[i]);
+    p_delete(&tcode[i]);
 
-  mem_free (tcode);
+  p_delete(tcode);
 
   return ret;
 }
@@ -846,7 +848,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
         mutt_set_parameter ("charset", chsbuf, &b->parameter);
       }
       b->file_charset = fromcode;
-      mem_free (&tocode);
+      p_delete(&tocode);
       safe_fclose (&fp);
       return info;
     }
@@ -1021,7 +1023,7 @@ void mutt_message_to_7bit (BODY * a, FILE * fp)
   mutt_write_mime_body (a->parts, fpout);
 
 cleanup:
-  mem_free (&line);
+  p_delete(&line);
 
   if (fpin && !fp)
     fclose (fpin);
@@ -1185,7 +1187,7 @@ void mutt_update_encoding (BODY * a)
   mutt_set_encoding (a, info);
   mutt_stamp_attachment (a);
 
-  mem_free (&a->content);
+  p_delete(&a->content);
   a->content = info;
 
 }
@@ -1448,7 +1450,7 @@ void mutt_write_references (LIST * r, FILE * f)
     fputs (ref[refcnt]->data, f);
   }
 
-  mem_free (&ref);
+  p_delete(&ref);
 }
 
 /* Note: all RFC2047 encoding should be done outside of this routine, except
@@ -1624,7 +1626,7 @@ int mutt_write_rfc822_header (FILE * fp, ENVELOPE * env, BODY * attach,
     fprintf (fp, "User-Agent: %s (%s)\n", mutt_make_version (0), os);
   }
 
-  list_del (&hdrs, (list_del_t*) _mem_free);
+  list_del (&hdrs, (list_del_t*)xmemfree);
 
   return (ferror (fp) == 0 ? 0 : -1);
 }
@@ -1653,7 +1655,7 @@ static void encode_headers (LIST * h)
 
     sprintf (h->data + i, ": %s", NONULL (tmp));        /* __SPRINTF_CHECKED__ */
 
-    mem_free (&tmp);
+    p_delete(&tmp);
   }
 }
 
@@ -1880,7 +1882,7 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
     }
     else if (pid == -1) {
       unlink (msg);
-      mem_free (tempfile);
+      p_delete(tempfile);
       _exit (S_ERR);
     }
 
@@ -1908,14 +1910,14 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
       st = WIFEXITED (st) ? WEXITSTATUS (st) : S_ERR;
       if (SendmailWait && st == (0xff & EX_OK)) {
         unlink (*tempfile);     /* no longer needed */
-        mem_free (tempfile);
+        p_delete(tempfile);
       }
     }
     else {
       st = (SendmailWait > 0 && errno == EINTR && SigAlrm) ? S_BKG : S_ERR;
       if (SendmailWait > 0) {
         unlink (*tempfile);
-        mem_free (tempfile);
+        p_delete(tempfile);
       }
     }
 
@@ -1926,7 +1928,7 @@ send_msg(const char *path, const char **args, const char *msg, char **tempfile)
     if (kill (ppid, 0) == -1 && errno == ESRCH) {
       /* the parent is already dead */
       unlink (*tempfile);
-      mem_free (tempfile);
+      p_delete(tempfile);
     }
 
     _exit (st);
@@ -2074,10 +2076,10 @@ static int mutt_invoke_sendmail (ADDRESS * from,        /* the sender */
   else
     unlink (childout);
 
-  mem_free (&childout);
-  mem_free (&path);
-  mem_free (&s);
-  mem_free (&args);
+  p_delete(&childout);
+  p_delete(&path);
+  p_delete(&s);
+  p_delete(&args);
 
   if (i == (EX_OK & 0xff))
     i = 0;
@@ -2139,7 +2141,7 @@ char *mutt_quote_string (const char *s)
   size_t rlen;
 
   rlen = str_len (s) + 3;
-  pr = r = (char *) mem_malloc (rlen);
+  pr = r = p_new(char, rlen);
   *pr++ = '"';
   while (*s) {
     if (INVALID_CHAR (*s)) {
index 48ec9df..ea4f458 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -12,6 +12,8 @@
  * please see the file GPL in the top level source directory.
  */
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_menu.h"
 #include "mutt_curses.h"
@@ -74,7 +76,7 @@ static char *shortened_hierarchy (char *box, int maxlen)
 
   if (last_dot) {
     ++last_dot;
-    new_box = mem_malloc (maxlen + 1);
+    new_box = p_new(char, maxlen + 1);
     new_box[0] = box[0];
     for (i = 1, j = 1; j < maxlen && i < len; ++i) {
       if (strchr (SidebarBoundary, box[i])) {
@@ -236,7 +238,7 @@ int make_sidebar_entry (char* box, int idx, size_t len)
   addnstr (entry, len);
 
   if (shortened)
-    mem_free(&box);
+    p_delete(&box);
 
   return (1);
 }
diff --git a/smime.c b/smime.c
index cba7100..95083df 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -13,6 +13,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "enter.h"
 #include "handler.h"
@@ -455,14 +457,14 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public)
       }
     }
     if (hash) {
-      fname = mem_malloc (13); /* Hash + '.' + Suffix + \0 */
+      fname = p_new(char, 13); /* Hash + '.' + Suffix + \0 */
       sprintf (fname, "%.8x.%i", Table[cur].hash, Table[cur].suffix);
     }
     else
       fname = NULL;
 
     mutt_menuDestroy (&menu);
-    mem_free (&Table);
+    p_delete(&Table);
     set_option (OPTNEEDREDRAW);
 
     if (fname)
@@ -649,7 +651,7 @@ void _smime_getkeys (char *mailbox)
     /* the key used last time. */
     if (*SmimeKeyToUse &&
         !str_casecmp (k, SmimeKeyToUse + str_len (SmimeKeys) + 1)) {
-      mem_free (&k);
+      p_delete(&k);
       return;
     }
     else
@@ -664,7 +666,7 @@ void _smime_getkeys (char *mailbox)
     if (str_casecmp (k, SmimeDefaultKey))
       smime_void_passphrase ();
 
-    mem_free (&k);
+    p_delete(&k);
     return;
   }
 
@@ -766,7 +768,7 @@ char *smime_findKeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
     }
     if (!keyID) {
       mutt_message (_("No (valid) certificate found for %s."), q->mailbox);
-      mem_free (&keylist);
+      p_delete(&keylist);
       rfc822_free_address (&tmp);
       rfc822_free_address (&addr);
       return NULL;
@@ -1091,7 +1093,7 @@ void smime_invoke_import (char *infile, char *mailbox)
     mutt_wait_filter (thepid);
 
     mutt_unlink (certfile);
-    mem_free (&certfile);
+    p_delete(&certfile);
   }
 
   fflush (fpout);
@@ -1150,7 +1152,7 @@ int smime_verify_sender (HEADER * h)
       else
         retval = 0;
       mutt_unlink (certfile);
-      mem_free (&certfile);
+      p_delete(&certfile);
     }
     else
       mutt_any_key_to_continue (_("no certfile"));
@@ -1567,7 +1569,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
       if (linelen && !str_casecmp (line, "verification successful"))
         badsig = 0;
 
-      mem_free (&line);
+      p_delete(&line);
     }
   }
 
@@ -1780,7 +1782,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile)
     line = mutt_read_line (line, &linelen, smimeerr, &lineno);
     if (linelen && !str_casecmp (line, "verification successful"))
       m->goodsig = 1;
-    mem_free (&line);
+    p_delete(&line);
   }
   else {
     m->goodsig = p->goodsig;
@@ -1935,7 +1937,7 @@ int smime_send_menu (HEADER * msg, int *redraw)
             break;
 
           case 4: /* (c)lear */
-            mem_free (&SmimeCryptAlg);
+            p_delete(&SmimeCryptAlg);
             /* fallback */
           case -1: /* Ctrl-G or Enter */
             choice = 0;
index aa94a86..f95eb32 100644 (file)
--- a/status.c
+++ b/status.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_menu.h"
 #include "mutt_curses.h"
index 2aa421d..57b1bcb 100644 (file)
--- a/thread.c
+++ b/thread.c
@@ -11,6 +11,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "sort.h"
 #include "thread.h"
@@ -129,7 +131,7 @@ static void calculate_visibility (CONTEXT * ctx, int *max_depth)
 
     tree->subtree_visible = 0;
     if (tree->message) {
-      mem_free (&tree->message->tree);
+      p_delete(&tree->message->tree);
       if (VISIBLE (tree->message, ctx)) {
         tree->deep = 1;
         tree->visible = 1;
@@ -221,8 +223,8 @@ void mutt_draw_tree (CONTEXT * ctx)
    * From now on we can simply ignore invisible subtrees
    */
   calculate_visibility (ctx, &max_depth);
-  pfx = mem_malloc (width * max_depth + 2);
-  arrow = mem_malloc (width * max_depth + 2);
+  pfx = p_new(char, width * max_depth + 2);
+  arrow = p_new(char, width * max_depth + 2);
   while (tree) {
     if (depth) {
       myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * width;
@@ -240,7 +242,7 @@ void mutt_draw_tree (CONTEXT * ctx)
       if (tree->visible) {
         myarrow[width] = M_TREE_RARROW;
         myarrow[width + 1] = 0;
-        new_tree = mem_malloc ((2 + depth * width));
+        new_tree = p_new(char, (2 + depth * width));
         if (start_depth > 1) {
           strncpy (new_tree, pfx, (start_depth - 1) * width);
           strfcpy (new_tree + (start_depth - 1) * width,
@@ -307,8 +309,8 @@ void mutt_draw_tree (CONTEXT * ctx)
     while (!tree->deep);
   }
 
-  mem_free (&pfx);
-  mem_free (&arrow);
+  p_delete(&pfx);
+  p_delete(&arrow);
 }
 
 /* since we may be trying to attach as a pseudo-thread a THREAD that
@@ -405,7 +407,7 @@ static THREAD *find_subject (CONTEXT * ctx, THREAD * cur)
 
     oldlist = subjects;
     subjects = subjects->next;
-    mem_free (&oldlist);
+    p_delete(&oldlist);
   }
   return (last);
 }
@@ -639,7 +641,7 @@ THREAD *mutt_sort_subthreads (THREAD * thread, int init)
       }
       else {
         Sort ^= SORT_REVERSE;
-        mem_free (&array);
+        p_delete(&array);
         return (top);
       }
     }
diff --git a/url.c b/url.c
index eb9d7f6..df231f3 100644 (file)
--- a/url.c
+++ b/url.c
@@ -15,6 +15,8 @@
 # include "config.h"
 #endif
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "ascii.h"
 #include "mapping.h"
@@ -257,6 +259,6 @@ int url_parse_mailto (ENVELOPE * e, char **body, const char *src)
     }
   }
 
-  mem_free (&tmp);
+  p_delete(&tmp);
   return 0;
 }