commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-586-g177423b


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-586-g177423b
Date: Sun, 25 Mar 2012 15:34:42 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=177423b53793e3ad5dc6fd787f75b3ff4038aedf

The branch, master has been updated
       via  177423b53793e3ad5dc6fd787f75b3ff4038aedf (commit)
       via  bf4c4a43ac942d8d81d0d276fe15ae3217f0e5a9 (commit)
      from  9f9d7b0b7cdb586b34ff08bfa7c752d05088a720 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 177423b53793e3ad5dc6fd787f75b3ff4038aedf
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun Mar 25 18:02:18 2012 +0300

    Revise some memory allocation routines.
    
    * examples/aclck.c: Check return values from strdup.
    * libmailutils/base/usremail.c: Likewise.
    * libmailutils/mailbox/bodystruct.c: Likewise.
    * lib/mailcap.c: Likewise.
    * libmailutils/mailbox/mbx_default.c: Likewise.
    * libmailutils/server/acl.c: Likewise.
    * libmailutils/stream/logstream.c: Likewise.
    * libmailutils/stream/message_stream.c: Likewise.
    * libmu_argp/mu_argp.c: Likewise.
    * libmu_auth/ldap.c: Likewise.
    * libmu_auth/pam.c: Likewise.
    * libmu_auth/sql.c: Likewise.
    * libmu_sieve/comparator.c: Likewise.
    * libmu_sieve/conf.c: Likewise.
    * libmu_sieve/extensions/list.c: Likewise.
    * libmu_sieve/extensions/vacation.c: Likewise.
    * libproto/mailer/prog.c: Likewise.
    * libproto/mailer/smtp_io.c: Likewise.
    * maidag/lmtp.c: Likewise.
    * python/libmu_py/address.c: Likewise.
    * sql/odbc.c
    
    * examples/sfrom.c (main): Avoid unnecessary memory allocation.
    * libmailutils/mailbox/mailbox.c: Likewise.
    
    * frm/frm.h: Include mailutils/alloc.h, remove xalloc.h
    * mh/mh.h: Likewise.
    
    * imap4d/imap4d.h: Remove xalloc.h
    * mail/mail.h: Likewise.
    * mimeview/mimeview.h: Likewise.
    * mu/acl.c: Likewise.
    * readmsg/readmsg.c: Likewise.
    
    * include/mailutils/locker.h (mu_locker_set_default_external_program):
    Change returned type.
    * include/mailutils/mailbox.h (mu_set_folder_directory): Change
    returned type.
    * libmailutils/base/locker.c (mu_locker_set_default_external_program):
    Return int (error code).
    * libmailutils/base/tilde.c: Add extra checks
    * libmailutils/mime/mimehdr.c (_mime_header_parse): Bugfix.
    * mail/folders.c: Don't use alloca, use mu_alloc instead. It
    was the only use of that function in Mailutils, so this change
    allows to withdraw the alloca module.
    
    * gnulib.modules (alloca, malloc)
    (realloc, xalloc): Remove.
    
    * frm/common.c: Use mu_alloc and friends instead of xmalloc.
    * frm/from.c: Likewise.
    * imap4d/append.c: Likewise.
    * imap4d/auth_gsasl.c: Likewise.
    * imap4d/authenticate.c: Likewise.
    * imap4d/fetch.c: Likewise.
    * imap4d/imap4d.c: Likewise.
    * imap4d/io.c: Likewise.
    * imap4d/list.c: Likewise.
    * imap4d/namespace.c: Likewise.
    * imap4d/parsebuf.c: Likewise.
    * imap4d/preauth.c: Likewise.
    * imap4d/rename.c: Likewise.
    * imap4d/search.c: Likewise.
    * imap4d/util.c: Likewise.
    * libmu_argp/muinit.c: Likewise.
    * mail/alias.c: Likewise.
    * mail/alt.c: Likewise.
    * mail/copy.c: Likewise.
    * mail/decode.c: Likewise.
    * mail/escape.c: Likewise.
    * mail/file.c: Likewise.
    * mail/from.c: Likewise.
    * mail/mail.c: Likewise.
    * mail/mailline.c: Likewise
    * mail/mailvar.c: Likewise
    * mail/msgset.y: Likewise
    * mail/page.c: Likewise
    * mail/send.c: Likewise
    * mail/shell.c: Likewise
    * mail/unset.c: Likewise
    * mail/util.c: Likewise
    * mh/folder.c: Likewise
    * mh/mh_alias.l: Likewise
    * mh/mh_alias.y: Likewise
    * mh/mh_fmtgram.y: Likewise
    * mh/mh_format.c: Likewise
    * mh/mh_global.c: Likewise
    * mh/mh_init.c: Likewise
    * mh/mh_list.c: Likewise
    * mh/mh_whatnow.c: Likewise
    * mh/mh_whom.c: Likewise
    * mh/mhn.c: Likewise
    * mh/pick.y: Likewise
    * mh/prompter-rl.c: Likewise
    * mh/refile.c: Likewise
    * mh/repl.c: Likewise
    * mh/send.c: Likewise
    * mh/sortm.c: Likewise
    * mimeview/mimetypes.y: Likewise
    * mu/dbm.c: Likewise
    * mu/dispatch.c: Likewise
    * mu/imap.c: Likewise
    * mu/pop.c: Likewise
    * mu/shell.c: Likewise
    * pop3d/apop.c: Likewise
    * pop3d/bulletin.c: Likewise
    * pop3d/popauth.c: Likewise
    * pop3d/user.c: Likewise

commit bf4c4a43ac942d8d81d0d276fe15ae3217f0e5a9
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Mar 24 10:55:04 2012 +0200

    Minor changes.

-----------------------------------------------------------------------

Summary of changes:
 examples/aclck.c                     |   17 +++++++--
 examples/sfrom.c                     |   14 +++----
 frm/common.c                         |   14 ++++----
 frm/frm.h                            |    2 +-
 frm/from.c                           |    2 +-
 gnulib.modules                       |    6 +---
 imap4d/append.c                      |    2 +-
 imap4d/auth_gsasl.c                  |    8 ++--
 imap4d/authenticate.c                |    5 +--
 imap4d/fetch.c                       |    8 +---
 imap4d/imap4d.c                      |   14 ++++++--
 imap4d/imap4d.h                      |    2 -
 imap4d/io.c                          |    8 ++---
 imap4d/list.c                        |    4 +-
 imap4d/namespace.c                   |    2 +-
 imap4d/parsebuf.c                    |    4 +--
 imap4d/preauth.c                     |    4 +-
 imap4d/rename.c                      |    4 +--
 imap4d/search.c                      |   10 ++----
 imap4d/util.c                        |    6 +--
 include/mailutils/locker.h           |    2 +-
 include/mailutils/mailbox.h          |    2 +-
 include/mailutils/stream.h           |    3 +-
 lib/mailcap.c                        |    3 +-
 libmailutils/base/locker.c           |    8 +++-
 libmailutils/base/tilde.c            |    2 +
 libmailutils/base/usremail.c         |    5 +++
 libmailutils/mailbox/bodystruct.c    |   11 ++++++-
 libmailutils/mailbox/fsfolder.c      |    2 +-
 libmailutils/mailbox/mailbox.c       |    2 +-
 libmailutils/mailbox/mbx_default.c   |   27 ++++++++++-----
 libmailutils/mime/mimehdr.c          |    2 +-
 libmailutils/server/acl.c            |   25 +++++++++-----
 libmailutils/stream/logstream.c      |    6 +++-
 libmailutils/stream/message_stream.c |    2 +
 libmu_argp/mu_argp.c                 |    3 +-
 libmu_argp/muinit.c                  |    6 +--
 libmu_auth/ldap.c                    |   57 +++++++++++++++++++++-----------
 libmu_auth/pam.c                     |    8 ++++-
 libmu_auth/sql.c                     |    2 +
 libmu_sieve/comparator.c             |    2 +
 libmu_sieve/conf.c                   |    6 +++-
 libmu_sieve/extensions/list.c        |    3 +-
 libmu_sieve/extensions/vacation.c    |    7 ++++
 libproto/mailer/prog.c               |    5 +++
 libproto/mailer/smtp_io.c            |    7 +++-
 maidag/lmtp.c                        |    6 +++
 mail/alias.c                         |    2 +-
 mail/alt.c                           |    2 +-
 mail/copy.c                          |    2 +-
 mail/decode.c                        |    4 +-
 mail/escape.c                        |    6 ++--
 mail/file.c                          |    8 ++--
 mail/folders.c                       |   15 +++------
 mail/from.c                          |   18 ++++++----
 mail/mail.c                          |    4 +-
 mail/mail.h                          |    6 +---
 mail/mailline.c                      |   20 ++++++------
 mail/mailvar.c                       |    6 ++--
 mail/msgset.y                        |   20 +++++------
 mail/page.c                          |    2 +-
 mail/send.c                          |   10 +++---
 mail/shell.c                         |    6 ++--
 mail/unset.c                         |    2 +-
 mail/util.c                          |   22 ++++++------
 mh/folder.c                          |   20 ++++++------
 mh/mh.h                              |    2 +-
 mh/mh_alias.l                        |   10 +++---
 mh/mh_alias.y                        |   12 +++---
 mh/mh_fmtgram.y                      |    4 +-
 mh/mh_format.c                       |   18 +++++-----
 mh/mh_global.c                       |    2 +-
 mh/mh_init.c                         |   18 +++++-----
 mh/mh_list.c                         |   10 +++---
 mh/mh_whatnow.c                      |    4 +-
 mh/mh_whom.c                         |    4 +-
 mh/mhn.c                             |   60 +++++++++++++++++-----------------
 mh/pick.y                            |    6 ++--
 mh/prompter-rl.c                     |    2 +-
 mh/refile.c                          |    2 +-
 mh/repl.c                            |    2 +-
 mh/send.c                            |   10 +++---
 mh/sortm.c                           |    6 ++--
 mimeview/mimetypes.y                 |    2 +-
 mimeview/mimeview.h                  |    1 -
 mu/acl.c                             |    1 -
 mu/dbm.c                             |   21 ++++++------
 mu/dispatch.c                        |    4 +-
 mu/imap.c                            |    9 ++---
 mu/pop.c                             |   13 +++----
 mu/shell.c                           |   13 +++----
 pop3d/apop.c                         |    2 +-
 pop3d/bulletin.c                     |    4 +-
 pop3d/popauth.c                      |    5 +--
 pop3d/user.c                         |    4 +--
 python/libmu_py/address.c            |    6 +++-
 readmsg/readmsg.c                    |    1 -
 sql/odbc.c                           |    6 ++--
 98 files changed, 430 insertions(+), 359 deletions(-)

diff --git a/examples/aclck.c b/examples/aclck.c
index 041b100..7cf01c5 100644
--- a/examples/aclck.c
+++ b/examples/aclck.c
@@ -105,6 +105,7 @@ read_rules (FILE *fp)
          continue;
        }
 
+      rc = 0;
       switch (action)
        {
        case mu_acl_accept:
@@ -115,12 +116,20 @@ read_rules (FILE *fp)
        case mu_acl_exec:
        case mu_acl_ifexec:
          data = strdup (ws.ws_wordv[2]);
+         if (!data)
+           {
+              rc = ENOMEM;
+              mu_error ("%d: %s", line, mu_strerror (rc));
+           }
        }
 
-      rc = mu_acl_append (acl, action, data, &cidr);
-      if (rc)
-       mu_error ("%d: cannot append acl entry: %s", line,
-                 mu_strerror (rc));
+      if (rc == 0)
+        {
+          rc = mu_acl_append (acl, action, data, &cidr);
+          if (rc)
+            mu_error ("%d: cannot append acl entry: %s", line,
+                     mu_strerror (rc));
+        }
     }
   mu_wordsplit_free (&ws);
 }
diff --git a/examples/sfrom.c b/examples/sfrom.c
index 8924509..1e19132 100644
--- a/examples/sfrom.c
+++ b/examples/sfrom.c
@@ -28,8 +28,6 @@
 int
 main (int argc, const char **argv)
 {
-  char *from;
-  char *subject;
   mu_mailbox_t mbox;
   size_t msgno, total = 0;
   int status;
@@ -62,6 +60,8 @@ main (int argc, const char **argv)
     {
       mu_message_t msg;
       mu_header_t hdr;
+      const char *from;
+      const char *subject;
 
       if ((status = mu_mailbox_get_message (mbox, msgno, &msg)) != 0
           || (status = mu_message_get_header (msg, &hdr)) != 0)
@@ -70,15 +70,13 @@ main (int argc, const char **argv)
           exit (EXIT_FAILURE);
         }
 
-      if (mu_header_aget_value (hdr, MU_HEADER_FROM, &from))
-        from = strdup ("(NO FROM)");
+      if (mu_header_sget_value (hdr, MU_HEADER_FROM, &from))
+        from = "(NO FROM)";
 
-      if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &subject))
-        subject = strdup ("(NO SUBJECT)");
+      if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &subject))
+        subject = "(NO SUBJECT)";
 
       printf ("%s\t%s\n", from, subject);
-      free (from);
-      free (subject);
     }
 
   status = mu_mailbox_close (mbox);
diff --git a/frm/common.c b/frm/common.c
index a51184e..e171c50 100644
--- a/frm/common.c
+++ b/frm/common.c
@@ -78,7 +78,7 @@ get_charset ()
        }
       
       if (!output_charset)
-       output_charset = xstrdup ("ASCII");
+       output_charset = mu_strdup ("ASCII");
     }
   return output_charset;
 }
@@ -109,9 +109,9 @@ size_t logical_size;
 void
 alloc_logical (size_t size)
 {
-  logical = xmalloc (size * sizeof (logical[0]));
+  logical = mu_alloc (size * sizeof (logical[0]));
   logical_size = size;
-  outstring = xmalloc (size);
+  outstring = mu_alloc (size);
 }
 
 void
@@ -144,7 +144,7 @@ puts_bidi (char *string)
       if (len + 1 > visual_size)
        {
          visual_size = len + 1;
-         visual = xrealloc (visual, visual_size * sizeof *visual);
+         visual = mu_realloc (visual, visual_size * sizeof *visual);
        }
       
       /* Create a bidi string. */
@@ -324,7 +324,7 @@ init_output (size_t s)
          
   /* Allocate the line buffer */
   linemax = s * MB_LEN_MAX + 1;
-  linebuf = xmalloc (linemax);
+  linebuf = mu_alloc (linemax);
   alloc_logical (s);
          
   /* Set up column widths */
@@ -362,7 +362,7 @@ rfc2047_decode_wrapper (const char *buf, size_t buflen)
   const char *charset = get_charset ();
   
   if (strcmp (charset, "ASCII") == 0)
-    return strdup (buf);
+    return mu_strdup (buf);
 
   rc = mu_rfc2047_decode (charset, buf, &tmp);
   if (rc)
@@ -370,7 +370,7 @@ rfc2047_decode_wrapper (const char *buf, size_t buflen)
       if (frm_debug)
        mu_error (_("cannot decode line `%s': %s"),
                  buf, mu_strerror (rc));
-      return strdup (buf);
+      return mu_strdup (buf);
     }
 
   return tmp;
diff --git a/frm/frm.h b/frm/frm.h
index ef522e8..0f13d29 100644
--- a/frm/frm.h
+++ b/frm/frm.h
@@ -38,13 +38,13 @@
 #endif
 
 #include <mbswidth.h>
-#include <xalloc.h>
 
 #ifdef HAVE_FRIBIDI_FRIBIDI_H
 # include <fribidi/fribidi.h>
 #endif
 
 #include <mailutils/address.h>
+#include <mailutils/alloc.h>
 #include <mailutils/attribute.h>
 #include <mailutils/debug.h>
 #include <mailutils/errno.h>
diff --git a/frm/from.c b/frm/from.c
index 4c6befc..36794c6 100644
--- a/frm/from.c
+++ b/frm/from.c
@@ -132,7 +132,7 @@ main (int argc, char **argv)
          exit (1);
        }
 
-      mailbox_name = xmalloc (strlen (argv[c]) + 2);
+      mailbox_name = mu_alloc (strlen (argv[c]) + 2);
       mailbox_name[0] = '%';
       strcpy (mailbox_name + 1, argv[c]);
     }
diff --git a/gnulib.modules b/gnulib.modules
index b161796..d9354b5 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -3,7 +3,6 @@
 
 # FIXME: fnmatch, regex and glob are used by libmailutils...
 
-alloca
 autobuild
 argp
 crypto/des
@@ -12,13 +11,10 @@ gettext
 gitlog-to-changelog
 intprops
 inttostr
-malloc
 mbchar
 mbiter
 mbslen
 mbswidth
 obstack
-realloc
 setenv
-stdint
-xalloc
+stdint
\ No newline at end of file
diff --git a/imap4d/append.c b/imap4d/append.c
index edc8139..365c246 100644
--- a/imap4d/append.c
+++ b/imap4d/append.c
@@ -162,7 +162,7 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char 
*date_time, char *text,
        }
 
       if (!tenv.sender)
-       tenv.sender = strdup ("GNU-imap4d");
+       tenv.sender = mu_strdup ("GNU-imap4d");
     }
       
   imap4d_enter_critical ();
diff --git a/imap4d/auth_gsasl.c b/imap4d/auth_gsasl.c
index 63a85d5..5727bd7 100644
--- a/imap4d/auth_gsasl.c
+++ b/imap4d/auth_gsasl.c
@@ -225,7 +225,7 @@ retrieve_password (Gsasl *ctx, Gsasl_session *sctx)
   const char *authid = gsasl_property_get (sctx, GSASL_AUTHID);
   
   if (username && *username == 0)
-    *username = strdup (authid);
+    *username = mu_strdup (authid);
 
   if (mu_gsasl_module_data.cram_md5_pwd
       && access (mu_gsasl_module_data.cram_md5_pwd, R_OK) == 0)
@@ -272,7 +272,7 @@ cb_validate (Gsasl *ctx, Gsasl_session *sctx)
   if (!pass)
     return GSASL_NO_PASSWORD;
   
-  *username = strdup (authid);
+  *username = mu_strdup (authid);
   
   auth = mu_get_auth_by_name (*username);
 
@@ -329,7 +329,7 @@ callback (Gsasl *ctx, Gsasl_session *sctx, Gsasl_property 
prop)
          char **username = gsasl_callback_hook_get (ctx);
          mu_diag_output (MU_DIAG_INFO, _("anonymous user %s logged in"),
                          gsasl_property_get (sctx, GSASL_ANONYMOUS_TOKEN));
-         *username = strdup (mu_gsasl_module_data.anon_user);
+         *username = mu_strdup (mu_gsasl_module_data.anon_user);
        }
       else
        {
@@ -341,7 +341,7 @@ callback (Gsasl *ctx, Gsasl_session *sctx, Gsasl_property 
prop)
     case GSASL_VALIDATE_GSSAPI:
       {
        char **username = gsasl_callback_hook_get (ctx);
-       *username = strdup (gsasl_property_get(sctx, GSASL_AUTHZID));
+       *username = mu_strdup (gsasl_property_get(sctx, GSASL_AUTHZID));
        break;
       }
       
diff --git a/imap4d/authenticate.c b/imap4d/authenticate.c
index 3137bae..3cec356 100644
--- a/imap4d/authenticate.c
+++ b/imap4d/authenticate.c
@@ -35,10 +35,7 @@ comp (const void *item, const void *data)
 void
 auth_add (char *name, imap4d_auth_handler_fp handler)
 {
-  struct imap_auth *p = malloc (sizeof (*p));
-
-  if (!p)
-    imap4d_bye (ERR_NO_MEM);
+  struct imap_auth *p = mu_alloc (sizeof (*p));
 
   p->name = name;
   p->handler = handler;
diff --git a/imap4d/fetch.c b/imap4d/fetch.c
index 9ace4fc..0ab9876 100644
--- a/imap4d/fetch.c
+++ b/imap4d/fetch.c
@@ -854,9 +854,7 @@ fetch_io (mu_stream_t stream, size_t start, size_t size, 
size_t max)
          return RESP_BAD;
        }
       
-      p = buffer = malloc (size + 1);
-      if (!p)
-       imap4d_bye (ERR_NO_MEM);
+      p = buffer = mu_alloc (size + 1);
 
       rc = mu_stream_seek (rfc, start, MU_SEEK_SET, NULL);
       if (rc)
@@ -1298,9 +1296,7 @@ _do_fetch (void *item, void *data)
 static void
 append_ffc (struct fetch_parse_closure *p, struct fetch_function_closure *ffc)
 {
-  struct fetch_function_closure *new_ffc = malloc (sizeof (*new_ffc));
-  if (!new_ffc)
-    imap4d_bye (ERR_NO_MEM);
+  struct fetch_function_closure *new_ffc = mu_alloc (sizeof (*new_ffc));
   *new_ffc = *ffc;
   mu_list_append (p->fnlist, new_ffc);
 }
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 98957c5..04fe4d5 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -208,7 +208,7 @@ cb_preauth (void *data, mu_config_value_t *val)
     return parse_preauth_scheme (val->v.string, NULL);
   else if (val->v.string[0] == '/')
     {
-      preauth_program = xstrdup (val->v.string);
+      preauth_program = mu_strdup (val->v.string);
       preauth_mode = preauth_prog;
     }
   else
@@ -349,7 +349,7 @@ imap4d_session_setup0 ()
          mu_error (_("expanding %s yields empty string"), expr);
          return 1;
        }
-      imap4d_homedir = strdup (ws.ws_wordv[0]);
+      imap4d_homedir = mu_strdup (ws.ws_wordv[0]);
       if (!imap4d_homedir)
        {
          mu_error ("%s", mu_strerror (errno));
@@ -357,7 +357,7 @@ imap4d_session_setup0 ()
        }
     }
   else
-    imap4d_homedir = strdup (real_homedir);
+    imap4d_homedir = mu_strdup (real_homedir);
 
   if (strcmp (imap4d_homedir, real_homedir)
       && imap4d_check_home_dir (imap4d_homedir,
@@ -627,6 +627,12 @@ imap4d_master_signal (int signo)
   longjmp (master_jmp, signo);
 }
 
+static void
+imap4d_alloc_die ()
+{
+  imap4d_bye (ERR_NO_MEM);
+}
+
 
 int
 main (int argc, char **argv)
@@ -673,6 +679,8 @@ main (int argc, char **argv)
   mu_m_server_set_timeout (server, 1800);  /* RFC2060: 30 minutes. */
   mu_m_server_set_strexit (server, mu_strexit);
   
+  mu_alloc_die_hook = imap4d_alloc_die;
+
   mu_log_syslog = 1;
 
   if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, 
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index edf7cf3..bca33df 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -68,8 +68,6 @@
 #endif
 #include <sysexits.h>
 
-#include "xalloc.h"
-
 #include <mailutils/address.h>
 #include <mailutils/attribute.h>
 #include <mailutils/body.h>
diff --git a/imap4d/io.c b/imap4d/io.c
index 47bb048..7adcbf1 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -194,7 +194,7 @@ io_send_qstring (const char *buffer)
     {
       char *s;
       int ret;
-      char *b = strdup (buffer);
+      char *b = mu_strdup (buffer);
       while ((s = strchr (b, '\n')) || (s = strchr (b, '\r')))
        *s = ' ';
       ret = io_send_literal (b);
@@ -390,9 +390,7 @@ struct imap4d_tokbuf
 struct imap4d_tokbuf *
 imap4d_tokbuf_init ()
 {
-  struct imap4d_tokbuf *tok = malloc (sizeof (tok[0]));
-  if (!tok)
-    imap4d_bye (ERR_NO_MEM);
+  struct imap4d_tokbuf *tok = mu_alloc (sizeof (tok[0]));
   memset (tok, 0, sizeof (*tok));
   return tok;
 }
@@ -647,7 +645,7 @@ struct imap4d_tokbuf *
 imap4d_tokbuf_from_string (char *str)
 {
   struct imap4d_tokbuf *tok = imap4d_tokbuf_init ();
-  tok->buffer = strdup (str);
+  tok->buffer = mu_strdup (str);
   if (!tok->buffer)
     imap4d_bye (ERR_NO_MEM);
   tok->level = strlen (str);
diff --git a/imap4d/list.c b/imap4d/list.c
index c1d8bf0..160bf62 100644
--- a/imap4d/list.c
+++ b/imap4d/list.c
@@ -195,14 +195,14 @@ imap4d_list (struct imap4d_command *command, 
imap4d_tokbuf_t tok)
              }
            else
              {
-               ref = strdup (wcard);
+               ref = mu_strdup (wcard);
                wcard += strlen (wcard);
              }
          }
          break;
 
        default:
-         ref = strdup (ref);
+         ref = mu_strdup (ref);
        }
 
       /* Move any directory not containing a wildcard into the reference
diff --git a/imap4d/namespace.c b/imap4d/namespace.c
index 8af8905..7a9164f 100644
--- a/imap4d/namespace.c
+++ b/imap4d/namespace.c
@@ -231,7 +231,7 @@ namespace_getfullpath (const char *name, int *nspace)
   char *ret;
   if (mu_c_strcasecmp (name, "INBOX") == 0 && auth_data->change_uid)
     {
-      ret = strdup (auth_data->mailbox);
+      ret = mu_strdup (auth_data->mailbox);
       if (nspace)
        *nspace = NS_PRIVATE;
     }
diff --git a/imap4d/parsebuf.c b/imap4d/parsebuf.c
index 0c67cfc..f098966 100644
--- a/imap4d/parsebuf.c
+++ b/imap4d/parsebuf.c
@@ -33,9 +33,7 @@ imap4d_parsebuf_exit (struct imap4d_parsebuf *p, char *text)
 static char *
 pbcopy (const char *str, size_t len)
 {
-  char *p = malloc (len + 1);
-  if (!p)
-    imap4d_bye (ERR_NO_MEM);
+  char *p = mu_alloc (len + 1);
   memcpy (p, str, len);
   p[len] = 0;
   return p;
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index d753736..2c0d19b 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -26,7 +26,7 @@ static char *
 do_preauth_stdio ()
 {
   struct passwd *pw = getpwuid (getuid ());
-  return pw ? strdup (pw->pw_name) : NULL;
+  return pw ? mu_strdup (pw->pw_name) : NULL;
 }
 
 
@@ -378,7 +378,7 @@ do_preauth_ident (struct sockaddr *clt_sa, struct sockaddr 
*srv_sa)
   else
     {
       mu_diag_output (MU_DIAG_INFO, "USERNAME %s", name);
-      name = strdup (name);
+      name = mu_strdup (name);
     }
   
   free (buf);
diff --git a/imap4d/rename.c b/imap4d/rename.c
index 5aaf3f0..3bc2040 100644
--- a/imap4d/rename.c
+++ b/imap4d/rename.c
@@ -27,9 +27,7 @@ make_interdir (const char *name, int delim, int perms)
   size_t namelen = 0;
   char delimbuf[2];
   
-  namebuf = malloc (strlen (name) + 1);
-  if (!namebuf)
-    imap4d_bye (ERR_NO_MEM);
+  namebuf = mu_alloc (strlen (name) + 1);
   if (name[0] == '/')
     namebuf[namelen++] = name[0];
 
diff --git a/imap4d/search.c b/imap4d/search.c
index d053476..14559d1 100644
--- a/imap4d/search.c
+++ b/imap4d/search.c
@@ -401,9 +401,7 @@ parse_regmem (struct parsebuf *pb, void *mem, void (*f) 
(void*))
 {
   struct mem_chain *mp;
 
-  mp = malloc (sizeof(*mp));
-  if (!mp)
-    imap4d_bye (ERR_NO_MEM);
+  mp = mu_alloc (sizeof(*mp));
   mp->next = pb->alloc;
   pb->alloc = mp;
   mp->mem = mem;
@@ -415,9 +413,7 @@ parse_regmem (struct parsebuf *pb, void *mem, void (*f) 
(void*))
 void *
 parse_alloc (struct parsebuf *pb, size_t size)
 {
-  void *p = malloc (size);
-  if (!p)
-    imap4d_bye (ERR_NO_MEM);
+  void *p = mu_alloc (size);
   return parse_regmem (pb, p, NULL);
 }
 
@@ -425,7 +421,7 @@ parse_alloc (struct parsebuf *pb, size_t size)
 char *
 parse_strdup (struct parsebuf *pb, char *s)
 {
-  s = strdup (s);
+  s = mu_strdup (s);
   if (!s)
     imap4d_bye (ERR_NO_MEM);
   return parse_regmem (pb, s, NULL);
diff --git a/imap4d/util.c b/imap4d/util.c
index 0d85cf0..badb7db 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -26,9 +26,7 @@ util_getfullpath (const char *name)
   if (*exp != MU_HIERARCHY_DELIMITER)
     {
       char *p, *s =
-       malloc (strlen (imap4d_homedir) + 1 + strlen (exp) + 1);
-      if (!s)
-       imap4d_bye (ERR_NO_MEM);
+       mu_alloc (strlen (imap4d_homedir) + 1 + strlen (exp) + 1);
       p = mu_stpcpy (s, imap4d_homedir);
       *p++ = MU_HIERARCHY_DELIMITER;
       strcpy (p, exp);
@@ -244,7 +242,7 @@ util_localname ()
          if (hp)
            {
              free (name);
-             name = strdup ((char *) hp->h_name);
+             name = mu_strdup ((char *) hp->h_name);
            }
        }
       localname = name;
diff --git a/include/mailutils/locker.h b/include/mailutils/locker.h
index df16ca4..79ecf07 100644
--- a/include/mailutils/locker.h
+++ b/include/mailutils/locker.h
@@ -103,7 +103,7 @@ extern int mu_locker_set_default_flags (int flags, enum 
mu_locker_set_mode mode)
 extern void mu_locker_set_default_retry_timeout (time_t to);
 extern void mu_locker_set_default_retry_count (size_t n);
 extern void mu_locker_set_default_expire_timeout (time_t t);
-extern void mu_locker_set_default_external_program (char *path);
+extern int mu_locker_set_default_external_program (char *path);
 
 /* A flags of 0 means that the default will be used. */
 extern int mu_locker_create (mu_locker_t *, const char *filename, int flags);
diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h
index b4b0ae4..1468244 100644
--- a/include/mailutils/mailbox.h
+++ b/include/mailutils/mailbox.h
@@ -31,7 +31,7 @@ extern char *mu_ticket_file;
   
 int mu_set_mail_directory (const char *p);
 int mu_set_mailbox_pattern (const char *pat);
-void mu_set_folder_directory (const char *p);
+int mu_set_folder_directory (const char *p);
 const char *mu_mailbox_url (void);
 const char *mu_folder_directory (void);
 int mu_construct_user_mailbox_url (char **pout, const char *name);
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index bbf9ec3..695d3d7 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -74,8 +74,7 @@ enum mu_buffer_type
 #define MU_IOCTL_SYSLOGSTREAM    10 /* Syslog stream (see below) */
 #define MU_IOCTL_FILTER          11 /* Filter streams (see below) */
 #define MU_IOCTL_TOPSTREAM       12 /* Same as MU_IOCTL_SUBSTREAM, but
-                                      always returns the topmost substream,
-                                      traversing stream chains if necessary.
+                                      always returns the topmost substream.
                                    */
   
   /* Opcodes common for various families */
diff --git a/lib/mailcap.c b/lib/mailcap.c
index 261ec11..4308785 100644
--- a/lib/mailcap.c
+++ b/lib/mailcap.c
@@ -18,7 +18,6 @@
 # include <config.h>
 #endif
 #include <mailutils/mailutils.h>
-#include <xalloc.h>
 #include <fnmatch.h>
 #define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
@@ -87,7 +86,7 @@ mime_context_fill (struct mime_context *ctx, const char *file,
 
   ctx->content_type = ws.ws_wordv[0];
   ws.ws_wordv[0] = NULL;
-  ctx->temp_file = file ? strdup (file) : NULL; 
+  ctx->temp_file = file ? mu_strdup (file) : NULL; 
   ctx->unlink_temp_file = 0;
 
   if (interactive)
diff --git a/libmailutils/base/locker.c b/libmailutils/base/locker.c
index 940e382..cef329b 100644
--- a/libmailutils/base/locker.c
+++ b/libmailutils/base/locker.c
@@ -241,11 +241,15 @@ mu_locker_set_default_expire_timeout (time_t t)
   mu_locker_expire_timeout = t;
 }
 
-void
+int
 mu_locker_set_default_external_program (char *path)
 {
+  char *p = strdup (path);
+  if (!p)
+    return ENOMEM;
   free (mu_locker_external_program);
-  mu_locker_external_program = strdup (path);
+  mu_locker_external_program = p;
+  return 0;
 }
 
 int
diff --git a/libmailutils/base/tilde.c b/libmailutils/base/tilde.c
index 5d365e0..1ee4252 100644
--- a/libmailutils/base/tilde.c
+++ b/libmailutils/base/tilde.c
@@ -39,6 +39,8 @@ mu_tilde_expansion (const char *ref, int delim, const char 
*homedir)
   size_t proto_len = 0;
   char *p;
 
+  if (!base)
+    return NULL;
   for (p = base; *p && mu_isascii (*p) && mu_isalnum (*p); p++)
     ;
   
diff --git a/libmailutils/base/usremail.c b/libmailutils/base/usremail.c
index 2d8b1aa..d44c6c6 100644
--- a/libmailutils/base/usremail.c
+++ b/libmailutils/base/usremail.c
@@ -163,6 +163,11 @@ mu_get_user_email (const char *name)
       name = tmpname = strdup(auth->name);
       if (auth)
        mu_auth_data_free (auth);
+      if (!name)
+        {
+          errno = ENOMEM;
+          return NULL;
+        }
     }
 
   status = mu_get_user_email_domain (&domainpart);
diff --git a/libmailutils/mailbox/bodystruct.c 
b/libmailutils/mailbox/bodystruct.c
index accaad6..28b9cc1 100644
--- a/libmailutils/mailbox/bodystruct.c
+++ b/libmailutils/mailbox/bodystruct.c
@@ -154,12 +154,21 @@ bodystructure_fill (mu_message_t msg, struct 
mu_bodystructure *bs)
        return ENOMEM;
       bs->body_subtype = strdup ("PLAIN");
       if (!bs->body_subtype)
-       return ENOMEM;
+        {
+          free (bs->body_type);
+         return ENOMEM;
+       }
       rc = mu_mime_param_assoc_create (&bs->body_param);
       if (rc)
        return rc;
       memset (&param, 0, sizeof (param));
       param.value = strdup ("US-ASCII");
+      if (!param.value)
+        {
+          free (bs->body_type);
+          free (bs->body_subtype);
+          return ENOMEM;
+        }
       rc = mu_assoc_install (bs->body_param, "CHARSET", &param);
       if (rc)
        {
diff --git a/libmailutils/mailbox/fsfolder.c b/libmailutils/mailbox/fsfolder.c
index ba24e1c..388b01a 100644
--- a/libmailutils/mailbox/fsfolder.c
+++ b/libmailutils/mailbox/fsfolder.c
@@ -86,7 +86,7 @@ get_pathname (const char *dirname, const char *basename)
   
   /* null basename gives dirname.  */
   if (basename == NULL)
-    pathname = (dirname) ? strdup (dirname) : strdup (".");
+    pathname = strdup (dirname ? dirname : ".");
   /* Absolute.  */
   else if (basename[0] == '/')
     pathname = strdup (basename);
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index 9bb4c0a..1461af5 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -841,7 +841,7 @@ mu_mailbox_get_uidls (mu_mailbox_t mbox, mu_list_t *plist)
              break;
            }
          uidl->msgno = i;
-         strncpy (uidl->uidl, strdup (buf), MU_UIDL_BUFFER_SIZE);
+         strncpy (uidl->uidl, buf, MU_UIDL_BUFFER_SIZE);
          status = mu_list_append (list, uidl);
          if (status)
            {
diff --git a/libmailutils/mailbox/mbx_default.c 
b/libmailutils/mailbox/mbx_default.c
index 4ef6d9e..41356a5 100644
--- a/libmailutils/mailbox/mbx_default.c
+++ b/libmailutils/mailbox/mbx_default.c
@@ -97,23 +97,32 @@ mu_set_mail_directory (const char *p)
 int
 mu_set_mailbox_pattern (const char *pat)
 {
-  if (_mu_mailbox_pattern)
-    free (_mu_mailbox_pattern);
-  if (!pat)
+  char *p;
+
+  if (pat)
     {
-      _mu_mailbox_pattern = NULL;
-      return 0;
+      p = strdup (pat);
+      if (!p)
+        return ENOMEM;
     }
-  _mu_mailbox_pattern = strdup (pat);
-  return _mu_mailbox_pattern ? 0 : ENOMEM;
+  else
+    p = NULL;
+  if (_mu_mailbox_pattern)
+    free (_mu_mailbox_pattern);
+  _mu_mailbox_pattern = p;
+  return 0;
 }
 
-void
+int
 mu_set_folder_directory (const char *p)
 {
+  char *fdir = strdup (p);
+  if (!fdir)
+    return ENOMEM;
   if (_mu_folder_dir != _default_folder_dir)
     free (_mu_folder_dir);
-  _mu_folder_dir = strdup (p);
+  _mu_folder_dir = fdir;
+  return 0;
 }
 
 const char *
diff --git a/libmailutils/mime/mimehdr.c b/libmailutils/mime/mimehdr.c
index a475159..e90be72 100644
--- a/libmailutils/mime/mimehdr.c
+++ b/libmailutils/mime/mimehdr.c
@@ -309,7 +309,7 @@ _mime_header_parse (const char *text, char **pvalue,
     {
       if (!pvalue)
        return MU_ERR_OUT_PTR_NULL;
-      *pvalue = strdup (ws.ws_wordv[i]);
+      *pvalue = strdup (ws.ws_wordv[0]);
       mu_wordsplit_free (&ws);
       if (!*pvalue)
        return ENOMEM;
diff --git a/libmailutils/server/acl.c b/libmailutils/server/acl.c
index 6f3e4df..e714a6e 100644
--- a/libmailutils/server/acl.c
+++ b/libmailutils/server/acl.c
@@ -278,14 +278,18 @@ _acl_match (struct _mu_acl_entry *ent, struct run_closure 
*rp)
                                                              
   if (mu_debug_level_p (MU_DEBCAT_ACL, MU_DEBUG_TRACE9))
     {
-      char *s;
-
-      if (ent->cidr.len == 0)
-       s = strdup ("any");
-      mu_cidr_format (&ent->cidr, 0, &s);
+      char *s = NULL;
+      int rc;
+      
+      if (ent->cidr.len && (rc = mu_cidr_format (&ent->cidr, 0, &s)))
+        {
+          mu_debug (MU_DEBCAT_ACL, MU_DEBUG_ERROR,
+                    ("mu_cidr_format: %s", mu_strerror (rc)));
+          return 1;
+        }
       if (!rp->addrstr)
-       mu_cidr_format (&rp->addr, MU_CIDR_FMT_ADDRONLY, &rp->addrstr);
-      mu_debug_log_begin ("Does %s match %s? ", s, rp->addrstr);
+        mu_cidr_format (&rp->addr, MU_CIDR_FMT_ADDRONLY, &rp->addrstr);
+      mu_debug_log_begin ("Does %s match %s? ", s ? s : "any", rp->addrstr);
       free (s);
     }
 
@@ -402,8 +406,11 @@ spawn_prog (const char *cmdline, int *pstatus, struct 
run_closure *rp)
   pid_t pid;
 
   if (expand_arg (cmdline, rp, &s))
-    s = strdup (cmdline);
-
+    {
+      s = strdup (cmdline);
+      if (!s)
+        return ENOMEM;
+    }
   pid = fork ();
   if (pid == 0)
     {
diff --git a/libmailutils/stream/logstream.c b/libmailutils/stream/logstream.c
index 81b9f65..d7d8d91 100644
--- a/libmailutils/stream/logstream.c
+++ b/libmailutils/stream/logstream.c
@@ -482,7 +482,11 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, 
void *arg)
              newp->logmode = sp->logmode;
              newp->sevmask = sp->sevmask;
              if (sp->locus.mu_file)
-               newp->locus.mu_file = strdup (sp->locus.mu_file);
+                {
+                 newp->locus.mu_file = strdup (sp->locus.mu_file);
+                 if (!newp->locus.mu_file)
+                   return ENOMEM;
+               }
              newp->locus.mu_line = sp->locus.mu_line;
              newp->locus.mu_col = sp->locus.mu_col;
              *(mu_stream_t*) arg = str;
diff --git a/libmailutils/stream/message_stream.c 
b/libmailutils/stream/message_stream.c
index 505f82c..e05ac6e 100644
--- a/libmailutils/stream/message_stream.c
+++ b/libmailutils/stream/message_stream.c
@@ -298,6 +298,8 @@ _message_open (mu_stream_t stream)
          tm = gmtime (&t);
          mu_strftime (date, sizeof (date), MU_DATETIME_FROM, tm);
          env_date = strdup (date);
+         if (!env_date)
+           return ENOMEM;
        }
       
       str->from = env_from;
diff --git a/libmu_argp/mu_argp.c b/libmu_argp/mu_argp.c
index bb64c28..671eefd 100644
--- a/libmu_argp/mu_argp.c
+++ b/libmu_argp/mu_argp.c
@@ -53,7 +53,8 @@ mu_register_argp_capa (const char *name, struct argp_child 
*child)
   for (i = 0; i < MU_MAX_CAPA; i++)
     if (mu_argp_capa[i].capability == NULL)
       {
-       mu_argp_capa[i].capability = strdup (name);
+        if ((mu_argp_capa[i].capability = strdup (name)) == NULL)
+          return ENOMEM;
        mu_argp_capa[i].child = child;
        return 0;
       }
diff --git a/libmu_argp/muinit.c b/libmu_argp/muinit.c
index 676baaa..06a764b 100644
--- a/libmu_argp/muinit.c
+++ b/libmu_argp/muinit.c
@@ -21,10 +21,10 @@
 #include "cmdline.h"
 #include <unistd.h>
 #include <stdlib.h>
+#include <mailutils/alloc.h>
 #include <mailutils/stream.h>
 #include <mailutils/io.h>
 #include <mailutils/stdstream.h>
-#include "xalloc.h"
 #include <string.h>
 #ifdef MU_ALPHA_RELEASE
 # include <git-describe.h>
@@ -82,9 +82,7 @@ get_canonical_name ()
       !(p = strchr (argp_program_version, ' ')))
     return strdup (mu_program_name);
   len = p - argp_program_version;
-  name = malloc (len + 1);
-  if (!name)
-    abort ();
+  name = mu_alloc (len + 1);
   memcpy (name, argp_program_version, len);
   name[len] = 0;
   return name;
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 05624cb..c454910 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -369,7 +369,11 @@ _construct_attr_array (size_t *pargc, char ***pargv)
     {
       char **str;
       mu_iterator_current (itr, (void**) &str); 
-      argv[i] = strdup (*str);
+      if ((argv[i] = strdup (*str)) == NULL)
+        {
+          mu_argcv_free (i, argv);
+          return ENOMEM;
+        }
     }
   mu_iterator_destroy (&itr);
   argv[i] = NULL;
@@ -418,6 +422,33 @@ _free_partial_auth_data (struct mu_auth_data *d)
 }
 
 static int
+_assign_partial_auth_data (struct mu_auth_data *d, const char *key,
+                          const char *val)
+{
+  int rc = 0;
+  
+  if (strcmp (key, MU_AUTH_NAME) == 0)
+    rc = (d->name = strdup (val)) ? 0 : errno;
+  else if (strcmp (key, MU_AUTH_PASSWD) == 0)
+    rc = (d->passwd = strdup (val)) ? 0 : errno;
+  else if (strcmp (key, MU_AUTH_UID) == 0)
+    d->uid = atoi (val);
+  else if (strcmp (key, MU_AUTH_GID) == 0)
+    d->gid = atoi (val);
+  else if (strcmp (key, MU_AUTH_GECOS) == 0)
+    rc = (d->gecos = strdup (val)) ? 0 : errno;
+  else if (strcmp (key, MU_AUTH_DIR) == 0)
+    rc = (d->dir = strdup (val)) ? 0 : errno;
+  else if (strcmp (key, MU_AUTH_SHELL) == 0)   
+    rc = (d->shell = strdup (val)) ? 0 : errno;
+  else if (strcmp (key, MU_AUTH_MAILBOX) == 0)
+    rc = (d->mailbox = strdup (val)) ? 0 : errno;
+  else if (strcmp (key, MU_AUTH_QUOTA) == 0)   
+    get_quota (&d->quota, val);
+  return rc;
+}
+
+static int
 _mu_entry_to_auth_data (LDAP *ld, LDAPMessage *msg,
                        struct mu_auth_data **return_data)
 {
@@ -456,26 +487,14 @@ _mu_entry_to_auth_data (LDAP *ld, LDAPMessage *msg,
          return MU_ERR_READ;
        }
       
-      if (strcmp (key, MU_AUTH_NAME) == 0)
-       d.name = strdup (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_PASSWD) == 0)
-       d.passwd = strdup (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_UID) == 0)
-       d.uid = atoi (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_GID) == 0)
-       d.gid = atoi (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_GECOS) == 0)
-       d.gecos = strdup (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_DIR) == 0)
-       d.dir = strdup (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_SHELL) == 0)   
-       d.shell = strdup (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_MAILBOX) == 0)
-       d.mailbox = strdup (values[0]->bv_val);
-      else if (strcmp (key, MU_AUTH_QUOTA) == 0)   
-       get_quota (&d.quota, values[0]->bv_val);
+      rc = _assign_partial_auth_data (&d, key, values[0]->bv_val);
       
       ldap_value_free_len (values);
+      if (rc)
+       {
+         _free_partial_auth_data (&d);
+         return rc;
+       }
     }
   
   rc = mu_auth_data_alloc (return_data,
diff --git a/libmu_auth/pam.c b/libmu_auth/pam.c
index 6edcd8a..a34d27b 100644
--- a/libmu_auth/pam.c
+++ b/libmu_auth/pam.c
@@ -192,7 +192,13 @@ mu_pam_module_init (enum mu_gocs_op op, void *data)
   if (op == mu_gocs_op_set && data)
     {
       struct mu_gocs_pam *p = data;
-      mu_pam_service = p->service ? strdup (p->service) : p->service;
+      if (p->service)
+        {
+          if ((mu_pam_service = strdup (p->service)) == NULL)
+            return ENOMEM;
+        }
+      else
+        mu_pam_service = NULL;
     }
   return 0;
 }
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index b0ce961..782508e 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -247,6 +247,8 @@ decode_tuple_new (mu_sql_connection_t conn, int n,
     {
     case 0:
       mailbox_name = strdup (mailbox_name);
+      if (!mailbox_name)
+        return ENOMEM;
       break;
       
     case MU_ERR_NOENT:
diff --git a/libmu_sieve/comparator.c b/libmu_sieve/comparator.c
index 1d88c99..a58080d 100644
--- a/libmu_sieve/comparator.c
+++ b/libmu_sieve/comparator.c
@@ -431,6 +431,8 @@ i_ascii_casemap_matches (const char *pattern, const char 
*text)
 #else
   int rc;
   char *p = strdup (text);
+  if (!p)
+    return 0;
   _pattern_upcase (p, NULL);
   rc = fnmatch (pattern, p, 0) == 0;
   free (p);
diff --git a/libmu_sieve/conf.c b/libmu_sieve/conf.c
index b871411..75ae47e 100644
--- a/libmu_sieve/conf.c
+++ b/libmu_sieve/conf.c
@@ -39,6 +39,7 @@ static int
 _path_append (void *item, void *data)
 {
   mu_list_t *plist = data;
+  char *p;
   if (!*plist)
     {
       int rc = mu_list_create (plist);
@@ -49,7 +50,10 @@ _path_append (void *item, void *data)
        }
       mu_list_set_destroy_item (*plist, mu_list_free_item);
     }
-  return mu_list_append (*plist, strdup (item));
+  p = strdup (item);
+  if (!p)
+    return ENOMEM;
+  return mu_list_append (*plist, p);
 }
 
 int
diff --git a/libmu_sieve/extensions/list.c b/libmu_sieve/extensions/list.c
index 29030fc..ec10b79 100644
--- a/libmu_sieve/extensions/list.c
+++ b/libmu_sieve/extensions/list.c
@@ -119,7 +119,8 @@ list_retrieve_header (void *item, void *data, int idx, char 
**pval)
       else
        p = hc->valv[hc->vali++];
   
-      *pval = strdup (p);
+      if ((*pval = strdup (p)) == NULL)
+        return 1;
       return 0;
     }
   
diff --git a/libmu_sieve/extensions/vacation.c 
b/libmu_sieve/extensions/vacation.c
index 2bc590e..f731ebd 100644
--- a/libmu_sieve/extensions/vacation.c
+++ b/libmu_sieve/extensions/vacation.c
@@ -644,6 +644,13 @@ sieve_action_vacation (mu_sieve_machine_t mach, mu_list_t 
args, mu_list_t tags)
     {
       /* Debugging hook: :sender sets fake reply address */
       from = strdup (val->v.string);
+      if (!from)
+        {
+          mu_sieve_error (mach, "%lu: %s",
+                          (unsigned long) mu_sieve_get_message_num (mach),
+                          mu_strerror (ENOMEM));
+          mu_sieve_abort (mach);
+        }
     }
   else if (mu_sieve_get_message_sender (msg, &from))
     {
diff --git a/libproto/mailer/prog.c b/libproto/mailer/prog.c
index b3ed030..3a17d6a 100644
--- a/libproto/mailer/prog.c
+++ b/libproto/mailer/prog.c
@@ -332,6 +332,11 @@ url_to_argv (mu_url_t url, mu_message_t msg,
        argv[i+1] = strdup ("");
       else
        argv[i+1] = strdup (ws.ws_wordv[0]);
+      if (!argv[i+1])
+        {
+          mu_argcv_free(i, argv);
+          return ENOMEM;
+        }
       wsflags |= MU_WRDSF_REUSE;
     }
   argv[i+1] = NULL;
diff --git a/libproto/mailer/smtp_io.c b/libproto/mailer/smtp_io.c
index 1d983eb..da46f77 100644
--- a/libproto/mailer/smtp_io.c
+++ b/libproto/mailer/smtp_io.c
@@ -96,6 +96,8 @@ mu_smtp_response (mu_smtp_t smtp)
       MU_SMTP_CHECK_ERROR (smtp, rc);
       do
        {
+          char *p;
+
          rc = mu_stream_getline (smtp->carrier, &smtp->rdbuf, &smtp->rdsize,
                                  &n);
          MU_SMTP_CHECK_ERROR (smtp, rc);
@@ -108,7 +110,10 @@ mu_smtp_response (mu_smtp_t smtp)
                              "received invalid reply from SMTP server");
              MU_SMTP_CHECK_ERROR (smtp, MU_ERR_BADREPLY);
            }
-         mu_list_append (smtp->mlrepl, strdup (smtp->rdbuf + 4));
+         p = strdup (smtp->rdbuf + 4);
+         if (!p)
+            MU_SMTP_CHECK_ERROR (smtp, ENOMEM);
+         mu_list_append (smtp->mlrepl, p);
        }
       while (smtp->rdbuf[3] == '-');
     }
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index ff47e75..49b478f 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -464,6 +464,12 @@ cfun_lhlo (mu_stream_t iostr, char *arg)
       return 1;
     }
   lhlo_domain = strdup (arg);
+  if (!lhlo_domain)
+    {
+      lmtp_reply (iostr, "410", "4.0.0",
+                  "Local error; please try again later");
+      return 1;
+    }
   lmtp_reply (iostr, "250", NULL, "Hello\n");
   lmtp_reply (iostr, "250", NULL, capa_str);
   return 0;
diff --git a/mail/alias.c b/mail/alias.c
index 8b60b1a..85540de 100644
--- a/mail/alias.c
+++ b/mail/alias.c
@@ -225,7 +225,7 @@ alias_iterate_first (const char *prefix, alias_iterator_t 
*pc)
   if (mu_assoc_get_iterator (aliases, &itr))
     return NULL;
   mu_iterator_first (itr);
-  atr = xmalloc (sizeof *atr);
+  atr = mu_alloc (sizeof *atr);
   atr->prefix = prefix;
   atr->prefixlen = strlen (prefix);
   atr->pos = 0;
diff --git a/mail/alt.c b/mail/alt.c
index dbdca0f..536f012 100644
--- a/mail/alt.c
+++ b/mail/alt.c
@@ -65,7 +65,7 @@ mail_set_my_name (char *name)
        }
       name = pw->pw_name;
     }
-  my_name = strdup (name);
+  my_name = mu_strdup (name);
   my_email = mu_get_user_email (name);
   if (!my_email)
     {
diff --git a/mail/copy.c b/mail/copy.c
index 12e1be7..f1dba8c 100644
--- a/mail/copy.c
+++ b/mail/copy.c
@@ -44,7 +44,7 @@ mail_copy0 (int argc, char **argv, int mark)
   else if (argc >= 2)
     filename = mail_expand_name (argv[--argc]);
   else
-    filename = strdup ("mbox");
+    filename = mu_strdup ("mbox");
 
   if (msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT, &msglist))
     {
diff --git a/mail/decode.c b/mail/decode.c
index 27996d5..bbe684d 100644
--- a/mail/decode.c
+++ b/mail/decode.c
@@ -183,7 +183,7 @@ mime_descend (struct mime_descend_closure *closure,
   mu_message_get_header (closure->message, &hdr);
   util_get_hdr_value (hdr, MU_HEADER_CONTENT_TYPE, &type);
   if (type == NULL)
-    type = xstrdup ("text/plain");
+    type = mu_strdup ("text/plain");
   get_content_encoding (hdr, &encoding);
 
   closure->type = type;
@@ -346,7 +346,7 @@ get_content_encoding (mu_header_t hdr, char **value)
     {
       if (encoding)
        free (encoding);
-      encoding = strdup ("7bit"); /* Default.  */
+      encoding = mu_strdup ("7bit"); /* Default.  */
     }
   *value = encoding;
   return 0;
diff --git a/mail/escape.c b/mail/escape.c
index 0005112..c0c0dcb 100644
--- a/mail/escape.c
+++ b/mail/escape.c
@@ -112,8 +112,8 @@ parse_headers (mu_stream_t input, compose_env_t *env)
                  *p++ = 0;
                  while (*p && mu_isspace (*p))
                    p++;
-                 value = strdup (p);
-                 name = strdup (buf);
+                 value = mu_strdup (p);
+                 name = mu_strdup (buf);
                }
              else
                {
@@ -435,7 +435,7 @@ void
 reread_header (compose_env_t *env, char *hdr, char *prompt)
 {
   char *p;
-  p = strdup (compose_header_get (env, hdr, ""));
+  p = mu_strdup (compose_header_get (env, hdr, ""));
   ml_reread (prompt, &p);
   compose_header_set (env, hdr, p, COMPOSE_REPLACE);
   free (p);
diff --git a/mail/file.c b/mail/file.c
index dd3c131..8f40e0c 100644
--- a/mail/file.c
+++ b/mail/file.c
@@ -41,7 +41,7 @@ mail_expand_name (const char *name)
          return NULL;
        }
       else
-       name = xstrdup (prev_name);
+       name = mu_strdup (prev_name);
       break;
          
     case '&':
@@ -49,7 +49,7 @@ mail_expand_name (const char *name)
       if (!name)
        mu_error (_("MBOX environment variable not set"));
       else
-       name = xstrdup (name);
+       name = mu_strdup (name);
       break;
          
     case '+':
@@ -57,7 +57,7 @@ mail_expand_name (const char *name)
       break;
 
     default:
-      name = xstrdup (name);
+      name = mu_strdup (name);
       break;
     }
   return (char*) name;
@@ -100,7 +100,7 @@ mail_file (int argc, char **argv)
       page_invalidate (1); /* Invalidate current page map */
       
       mu_mailbox_get_url (mbox, &url);
-      pname = strdup (mu_url_to_string (url));
+      pname = mu_strdup (mu_url_to_string (url));
       if (mail_mbox_close ())
        {
          if (pname)
diff --git a/mail/folders.c b/mail/folders.c
index 1c73c6a..fecc00c 100644
--- a/mail/folders.c
+++ b/mail/folders.c
@@ -31,20 +31,15 @@ mail_folders (int argc MU_ARG_UNUSED, char **argv 
MU_ARG_UNUSED)
 
   if (path[0] != '/' && path[0] != '~')
     {
-      char *tmp = alloca (strlen (path) + 3);
-      if (!tmp)
-       {
-         mu_error (_("Not enough memory"));
-         return 1;
-       } 
-
+      char *tmp = mu_alloc (strlen (path) + 3);
       tmp[0] = '~';
       tmp[1] = '/';
       strcpy (tmp + 2, path);
-      path = tmp;
+      path = util_fullpath (tmp);
+      free (tmp);
     }
-  
-  path = util_fullpath (path);
+  else
+    path = util_fullpath (path);
   
   util_do_command("! %s '%s'", getenv ("LISTER"), path);
   free (path);
diff --git a/mail/from.c b/mail/from.c
index 85e4933..dafd631 100644
--- a/mail/from.c
+++ b/mail/from.c
@@ -45,7 +45,7 @@ header_ensure_space (struct header_call_args *args, size_t 
size)
 {
   if (size > args->size)
     {
-      args->buf = xrealloc (args->buf, size);
+      args->buf = mu_realloc (args->buf, size);
       args->size = size;
     }
 }
@@ -280,7 +280,7 @@ hdr_from (struct header_call_args *args, void *data)
       
       if (mu_message_get_envelope (args->msg, &env) == 0)
        mu_envelope_sget_sender (env, &sender);
-      from = strdup (sender);
+      from = mu_strdup (sender);
     }
 
   header_buf_string (args, from);
@@ -387,7 +387,7 @@ new_header_segment (int align, size_t width,
                    void *data,
                    char *(*get) (struct header_call_args *, void *))
 {
-  struct header_segm *seg = xmalloc (sizeof (*seg));
+  struct header_segm *seg = mu_alloc (sizeof (*seg));
   seg->next = NULL;
   seg->align = align;
   seg->width = width;
@@ -428,7 +428,7 @@ compile_headline (const char *str)
        len = p - str;
       if (len)
        {
-         text = xmalloc (len + 1);
+         text = mu_alloc (len + 1);
          memcpy (text, str, len);
          text[len] = 0;
          seg = new_header_segment (ALIGN_LEFT, 0, text, hdr_text);
@@ -460,7 +460,7 @@ compile_headline (const char *str)
       switch (*str++)
        {
        case '%':
-         seg = new_header_segment (ALIGN_LEFT, 0, xstrdup ("%"), hdr_text);
+         seg = new_header_segment (ALIGN_LEFT, 0, mu_strdup ("%"), hdr_text);
          break;
          
        case 'a': /* Message attributes. */
@@ -509,17 +509,19 @@ compile_headline (const char *str)
          /* FIXME: %t    The position in threaded/sorted order. */
          
        case '>': /* A `>' for the current message, otherwise ` ' */
-         seg = new_header_segment (ALIGN_STRING, width, xstrdup (">"), 
hdr_cur);
+         seg = new_header_segment (ALIGN_STRING, width, mu_strdup (">"), 
+                                   hdr_cur);
          break;
          
        case '<': /* A `<' for the current message, otherwise ` ' */
-         seg = new_header_segment (ALIGN_STRING, width, xstrdup ("<"), 
hdr_cur);
+         seg = new_header_segment (ALIGN_STRING, width, mu_strdup ("<"),
+                                   hdr_cur);
          break;
 
        default:
          mu_error (_("unknown escape: %%%c"), str[-1]);
          len = str - p;
-         text = xmalloc (len);
+         text = mu_alloc (len);
          memcpy (text, p, len-1);
          text[len-1] = 0;
          seg = new_header_segment (ALIGN_STRING, width, text, hdr_text);
diff --git a/mail/mail.c b/mail/mail.c
index 38adda2..045745c 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -371,7 +371,7 @@ main (int argc, char **argv)
   
   /* Set the default mailer to sendmail.  */
   mailvar_set ("sendmail",
-              xstrdup ("sendmail:" PATH_SENDMAIL), mailvar_type_string,
+              mu_strdup ("sendmail:" PATH_SENDMAIL), mailvar_type_string,
               MOPTF_OVERWRITE);
 
   args.argc = 0;
@@ -539,7 +539,7 @@ mail_mainloop (char *(*input) (void *, int),
              break;
            }
          command[len-1] = '\0';
-         buf = xmalloc ((len + strlen (command2)) * sizeof (char));
+         buf = mu_alloc ((len + strlen (command2)) * sizeof (char));
          strcpy (buf, command);
          strcat (buf, command2);
          free (command);
diff --git a/mail/mail.h b/mail/mail.h
index 4be04f6..2dbe8d1 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -26,9 +26,6 @@
 # include <dmalloc.h>
 #endif
 
-#ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
 #include <errno.h>
 #include <limits.h>
 #ifndef _GNU_SOURCE
@@ -48,14 +45,13 @@
 
 #include <confpaths.h>
 
-#include <xalloc.h>
-
 #ifdef HAVE_READLINE_READLINE_H
 # include <readline/readline.h>
 # include <readline/history.h>
 #endif
 
 #include <mailutils/address.h>
+#include <mailutils/alloc.h>
 #include <mailutils/assoc.h>
 #include <mailutils/attribute.h>
 #include <mailutils/body.h>
diff --git a/mail/mailline.c b/mail/mailline.c
index 1d206ae..04610d5 100644
--- a/mail/mailline.c
+++ b/mail/mailline.c
@@ -255,7 +255,7 @@ ml_command_generator (const char *text, int state)
        name = cp->shortname;
       i++;
       if (strncmp (name, text, len) == 0)
-       return strdup (name);
+       return mu_strdup (name);
     }
 
   return NULL;
@@ -323,7 +323,7 @@ file_generator (const char *text, int state,
       mu_folder_t folder;
       size_t count;
 
-      wcard = xmalloc (strlen (text) + 2);
+      wcard = mu_alloc (strlen (text) + 2);
       strcat (strcpy (wcard, text), "*");
 
       if (mu_folder_create (&folder, path))
@@ -365,7 +365,7 @@ file_generator (const char *text, int state,
              size_t len = strlen (resp->name + pathlen);
              char *ptr;
 
-             ret = xmalloc (len + (repl ? 1 : 0) + 1);
+             ret = mu_alloc (len + (repl ? 1 : 0) + 1);
              ptr = ret;
              if (repl)
                *ptr++ = repl;
@@ -373,7 +373,7 @@ file_generator (const char *text, int state,
              ptr[len] = 0;
            }
          else
-           ret = xstrdup (resp->name);
+           ret = mu_strdup (resp->name);
          return ret;
        }
     }
@@ -493,7 +493,7 @@ header_generator (const char *text, int state)
     {
       i++;
       if (mu_c_strncasecmp (hdr, text, len) == 0)
-       return strdup (hdr);
+       return mu_strdup (hdr);
     }
 
   return NULL;
@@ -594,13 +594,13 @@ dir_generator (const char *text, int state)
          /* else FIXME! */
 
        case '/':
-         path = strdup (text);
+         path = mu_strdup (text);
          pathlen = 0;
          repl = 0;
          break;
 
        default:
-         path = strdup ("./");
+         path = mu_strdup ("./");
          pathlen = 2;
          repl = 0;
        }
@@ -643,7 +643,7 @@ alias_generator (const char *text, int state)
       alias_iterate_end (&itr);
       return NULL;
     }
-  return strdup (p);
+  return mu_strdup (p);
 }
 
 char **
@@ -744,7 +744,7 @@ exec_generator (const char *text, int state)
              if (rc == 0
                  && strlen (ent->d_name) >= prefix_len
                  && strncmp (ent->d_name, text, prefix_len) == 0)
-               return strdup (ent->d_name);
+               return mu_strdup (ent->d_name);
            }
        }
 
@@ -889,7 +889,7 @@ ml_reread (const char *prompt, char **text)
       line = strdup (*text);
       if (line)
        {
-         pos = strlen(line);
+         pos = strlen (line);
          line_size = pos + 1;
        }
     }
diff --git a/mail/mailvar.c b/mail/mailvar.c
index dd6c92a..e0d1306 100644
--- a/mail/mailvar.c
+++ b/mail/mailvar.c
@@ -378,8 +378,8 @@ mailvar_find_variable (const char *name, int create)
            return 0;
          else
            {
-             p = xmalloc (sizeof *p);
-             p->name = xstrdup (name);
+             p = mu_alloc (sizeof *p);
+             p->name = mu_strdup (name);
              mu_list_prepend (mailvar_list, p);
            }
        }
@@ -662,7 +662,7 @@ mailvar_iterate_next (struct mailvar_iterator *itr)
 const char *
 mailvar_iterate_first (int set, const char *prefix, struct mailvar_iterator 
**pitr)
 {
-  struct mailvar_iterator *itr = xmalloc (sizeof *itr);
+  struct mailvar_iterator *itr = mu_alloc (sizeof *itr);
   itr->prefix = prefix;
   itr->prefixlen = strlen (prefix);
   itr->varlist = mailvar_list_copy (set);
diff --git a/mail/msgset.y b/mail/msgset.y
index afbcd0a..e17485b 100644
--- a/mail/msgset.y
+++ b/mail/msgset.y
@@ -21,8 +21,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <xalloc.h>
-
 /* Defined in <limits.h> on some systems, but redefined in <regex.h>
    if we are using GNU's regex. So, undef it to avoid duplicate definition
    warnings. */
@@ -287,7 +285,7 @@ yylex()
       while (*cur_p && *cur_p != ',' && *cur_p != ':') 
        cur_p++;
       len = cur_p - p + 1;
-      yylval.string = xmalloc (len);
+      yylval.string = mu_alloc (len);
       memcpy (yylval.string, p, len-1);
       yylval.string[len-1] = 0;
       if (*cur_p == ':')
@@ -307,7 +305,7 @@ yylex()
        cur_p++;
       len = cur_p - p + 1;
       cur_p++;
-      yylval.string = xmalloc (len);
+      yylval.string = mu_alloc (len);
       memcpy (yylval.string, p, len-1);
       yylval.string[len-1] = 0;
       return REGEXP;
@@ -325,7 +323,7 @@ yylex()
            cur_p++;
          len = cur_p - p + 1;
          cur_p++;
-         yylval.string = xmalloc (len);
+         yylval.string = mu_alloc (len);
          memcpy (yylval.string, p, len-1);
          yylval.string[len-1] = 0;
          return BODY;
@@ -395,10 +393,10 @@ msgset_make_1 (size_t number)
 
   if (number == 0)
     return NULL;
-  mp = xmalloc (sizeof (*mp));
+  mp = mu_alloc (sizeof (*mp));
   mp->next = NULL;
   mp->npart = 1;
-  mp->msg_part = xmalloc (sizeof mp->msg_part[0]);
+  mp->msg_part = mu_alloc (sizeof mp->msg_part[0]);
   mp->msg_part[0] = number;
   return mp;
 }
@@ -407,10 +405,10 @@ msgset_t *
 msgset_dup (const msgset_t *set)
 {
   msgset_t *mp;
-  mp = xmalloc (sizeof (*mp));
+  mp = mu_alloc (sizeof (*mp));
   mp->next = NULL;
   mp->npart = set->npart;
-  mp->msg_part = xcalloc (mp->npart, sizeof mp->msg_part[0]);
+  mp->msg_part = mu_calloc (mp->npart, sizeof mp->msg_part[0]);
   memcpy (mp->msg_part, set->msg_part, mp->npart * sizeof mp->msg_part[0]);
   return mp;
 }
@@ -494,10 +492,10 @@ msgset_expand (msgset_t *set, msgset_t *expand_by)
   for (i = set; i; i = i->next)
     for (j = expand_by; j; j = j->next)
       {
-       mp = xmalloc (sizeof *mp);
+       mp = mu_alloc (sizeof *mp);
        mp->next = NULL;
        mp->npart = i->npart + j->npart;
-       mp->msg_part = xcalloc (mp->npart, sizeof mp->msg_part[0]);
+       mp->msg_part = mu_calloc (mp->npart, sizeof mp->msg_part[0]);
        memcpy (mp->msg_part, i->msg_part, i->npart * sizeof i->msg_part[0]);
        memcpy (mp->msg_part + i->npart, j->msg_part,
                j->npart * sizeof j->msg_part[0]);
diff --git a/mail/page.c b/mail/page.c
index 4c65357..628dcba 100644
--- a/mail/page.c
+++ b/mail/page.c
@@ -58,7 +58,7 @@ check_page_map ()
   if (!page_map)
     {
       page_size = util_screen_lines ();
-      page_map = xrealloc (page_map, sizeof (page_map[0]) * page_size);
+      page_map = mu_realloc (page_map, sizeof (page_map[0]) * page_size);
       page_avail = 0;
     }
   if (page_avail == 0)
diff --git a/mail/send.c b/mail/send.c
index 7bf0714..4d2ce20 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -71,7 +71,7 @@ add_header (char *name, char *value, int mode)
        }
     }
 
-  hp = xmalloc (sizeof (*hp));
+  hp = mu_alloc (sizeof (*hp));
   hp->mode = mode;
   hp->name = name;
   hp->value = value;
@@ -92,19 +92,19 @@ send_append_header (char *text)
       return;
     }
   len = p - text;
-  name = xmalloc (len + 1);
+  name = mu_alloc (len + 1);
   memcpy (name, text, len);
   name[len] = 0;
   for (p++; *p && mu_isspace (*p); p++)
     ;
 
-  add_header (name, strdup (p), COMPOSE_APPEND);
+  add_header (name, mu_strdup (p), COMPOSE_APPEND);
 }
 
 void
 send_append_header2 (char *name, char *value, int mode)
 {
-  add_header (strdup (name), strdup (value), mode);
+  add_header (mu_strdup (name), mu_strdup (value), mode);
 }
 
 int
@@ -124,7 +124,7 @@ mail_sendheader (int argc, char **argv)
       size_t len = strlen (argv[1]);
       if (len > 0 && argv[1][len - 1] == ':') 
        argv[1][len - 1] = 0;
-      add_header (strdup (argv[1]), strdup (argv[2]), COMPOSE_APPEND);
+      add_header (mu_strdup (argv[1]), mu_strdup (argv[2]), COMPOSE_APPEND);
     }
   return 0;
 }
diff --git a/mail/shell.c b/mail/shell.c
index e260197..bceda14 100644
--- a/mail/shell.c
+++ b/mail/shell.c
@@ -30,7 +30,7 @@ expand_bang (char **pbuf, const char *arg, const char *last)
 
   if (count == 0)
     {
-      *pbuf = xstrdup (arg);
+      *pbuf = mu_strdup (arg);
       return;
     }
 
@@ -40,7 +40,7 @@ expand_bang (char **pbuf, const char *arg, const char *last)
       return;
     }
 
-  tmp = xmalloc (strlen (arg) + count * (strlen (last) - 1) + 1);
+  tmp = mu_alloc (strlen (arg) + count * (strlen (last) - 1) + 1);
   for (p = arg, q = tmp; *p; )
     {
       if (*p == '!')
@@ -75,7 +75,7 @@ mail_execute (int shell, char *progname, int argc, char 
**argv)
   xargc = argc;
   if (shell && argc < 3)
     xargc = 3;
-  xargv = xcalloc (xargc + 1, sizeof (xargv[0]));
+  xargv = mu_calloc (xargc + 1, sizeof (xargv[0]));
   
   /* Expand arguments if required */
   if (mailvar_get (NULL, "bang", mailvar_type_boolean, 0) == 0)
diff --git a/mail/unset.c b/mail/unset.c
index cf5b41b..f732100 100644
--- a/mail/unset.c
+++ b/mail/unset.c
@@ -34,7 +34,7 @@ mail_unset (int argc, char **argv)
       int status = 0, i = 1;
       for (i = 1; i < argc; i++)
        {
-         char *buf = xmalloc ((7+strlen (argv[i])) * sizeof (char));
+         char *buf = mu_alloc ((7+strlen (argv[i])) * sizeof (char));
          strcpy (buf, "set no");
          strcat (buf, argv[i]);
          if (!util_do_command ("%s", buf))
diff --git a/mail/util.c b/mail/util.c
index e98eb7b..8f0023c 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -66,7 +66,7 @@ util_do_command (const char *fmt, ...)
             according to the POSIX spec. Note, that this applies
             to interactive state only. */
          if (interactive)
-           cmd = strdup ("next");
+           cmd = mu_strdup ("next");
          else
            return 0;
        }
@@ -124,7 +124,7 @@ util_do_command (const char *fmt, ...)
          argc++;
          argv--;
          argv[0] = argv[1];
-         argv[1] = xstrdup (p);
+         argv[1] = mu_strdup (p);
          *p = 0;
          /* Register the new entry in WS */
          ws.ws_wordc++;
@@ -495,15 +495,15 @@ util_folder_path (const char *name)
   if (folder[0] != '/' && folder[0] != '~')
     {
       char *home = mu_get_homedir ();
-      tmp  = xmalloc (strlen (home) + 1 +
-                     strlen (folder) + 1 +
-                     strlen (name) + 1);
+      tmp  = mu_alloc (strlen (home) + 1 +
+                      strlen (folder) + 1 +
+                      strlen (name) + 1);
       sprintf (tmp, "%s/%s/%s", home, folder, name);
     }
   else
     {
-      tmp  = xmalloc (strlen (folder) + 1 +
-                     strlen (name) + 1);
+      tmp  = mu_alloc (strlen (folder) + 1 +
+                      strlen (name) + 1);
       sprintf (tmp, "%s/%s", folder, name);
     }
   p = util_fullpath (tmp);
@@ -613,7 +613,7 @@ util_slist_add (mu_list_t *plist, char *value)
     }
   else
     list = *plist;
-  mu_list_append (list, xstrdup (value));
+  mu_list_append (list, mu_strdup (value));
 }
 
 void
@@ -654,7 +654,7 @@ void
 util_strcat (char **dest, const char *str)
 {
   if (!*dest)
-    *dest = strdup (str);
+    *dest = mu_strdup (str);
   else
     {
       int dlen = strlen (*dest) + 1;
@@ -700,7 +700,7 @@ util_outfolder_name (char *str)
 
     }
 
-  return strdup (str);
+  return mu_strdup (str);
 }
 
 /* Save an outgoing message. The SAVEFILE argument overrides the setting
@@ -816,7 +816,7 @@ util_get_content_type (mu_header_t hdr, char **value, char 
**args)
     {
       if (type)
        free (type);
-      type = strdup ("text/plain"); /* Default.  */
+      type = mu_strdup ("text/plain"); /* Default.  */
     }
   else
     {
diff --git a/mh/folder.c b/mh/folder.c
index 3d1bb89..2d5efea 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -247,9 +247,9 @@ int name_prefix_len;              /* Length of the 
mu_path_folder_dir */
 void
 install_folder_info (const char *name, struct folder_info *info)
 {
-  struct folder_info *new_info = xmalloc (sizeof (*new_info));
+  struct folder_info *new_info = mu_alloc (sizeof (*new_info));
   *new_info = *info;
-  new_info->name = strdup (new_info->name + name_prefix_len);
+  new_info->name = mu_strdup (new_info->name + name_prefix_len);
   mu_list_append (folder_info_list, new_info);
   message_count += info->message_count;
 }
@@ -328,7 +328,7 @@ _scan (const char *name, size_t depth)
     }
   
   memset (&info, 0, sizeof (info));
-  info.name = strdup (name);
+  info.name = mu_strdup (name);
   while ((entry = readdir (dir)))
     {
       if (entry->d_name[0] == '.')
@@ -566,14 +566,14 @@ push_val (int *pc, char ***pv, const char *val)
   c++;
   if (c == 1)
     {
-      v = xcalloc (c + 1, sizeof (*v));
+      v = mu_calloc (c + 1, sizeof (*v));
     }
   else
     {
-      v = xrealloc (v, (c + 1) * sizeof (*v));
+      v = mu_realloc (v, (c + 1) * sizeof (*v));
       memmove (&v[1], &v[0], c * sizeof (*v));
     }
-  v[0] = xstrdup (val);
+  v[0] = mu_strdup (val);
 
   *pv = v;
   *pc = c;
@@ -612,7 +612,7 @@ action_push ()
   else 
     {
       char *t = v[0];
-      v[0] = xstrdup (mh_current_folder ());
+      v[0] = mu_strdup (mh_current_folder ());
       mh_set_current_folder (t);
       free (t);
     }
@@ -842,7 +842,7 @@ fixup_private (const char *name, const char *value, void 
*data)
   if (nlen > 0 && strcmp (name + nlen, fd->folder_dir) == 0)
     {
       int rc;
-      char *s = xmalloc (nlen);
+      char *s = mu_alloc (nlen);
       memcpy (s, name, nlen - 1);
       s[nlen-1] = 0;
       rc = _fixup (s, value, fd, SEQ_PRIVATE);
@@ -867,8 +867,8 @@ action_pack ()
       mu_error (_("cannot read input mailbox: %s"), mu_strerror (errno));
       return 1;
     }
-  pack_tab = xcalloc (count, sizeof pack_tab[0]); /* Never freed. No use to
-                                                    try to. */
+  pack_tab = mu_calloc (count, sizeof pack_tab[0]); /* Never freed. No use to
+                                                      try to. */
 
   /* Populate it with message numbers */
   if (verbose)
diff --git a/mh/mh.h b/mh/mh.h
index 8be802e..b20b9eb 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -24,11 +24,11 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <mh_getopt.h>
-#include <xalloc.h>
 #include <mailutils/io.h>
 
 #include <string.h>
 
+#include <mailutils/alloc.h>
 #include <mailutils/cctype.h>
 #include <mailutils/cstr.h>
 #include <mailutils/parse822.h>
diff --git a/mh/mh_alias.l b/mh/mh_alias.l
index 7a78082..53a46b9 100644
--- a/mh/mh_alias.l
+++ b/mh/mh_alias.l
@@ -201,7 +201,7 @@ xunput (int c)
     {
       char *putback;
       current_buffer.pb_size += LEX_PUTBACK_SIZE;
-      putback = xmalloc (current_buffer.pb_size);
+      putback = mu_alloc (current_buffer.pb_size);
       memcpy (putback, current_buffer.putback,
              current_buffer.pb_level);
       free (current_buffer.putback);
@@ -283,7 +283,7 @@ push_source (const char *name, int fail)
   /* Push current context */
   if (ali_filename)
     {
-      ctx = xmalloc (sizeof (*ctx));
+      ctx = mu_alloc (sizeof (*ctx));
       ctx->filename = ali_filename;
       ctx->line = ali_line_num;
       ctx->i_node = ali_source_inode;
@@ -354,10 +354,10 @@ SPEC [,:;+=\*]
                    for (p = yytext; p < yytext + yyleng; p++)
                     if (!mu_isspace (*p))
                       break;
-                  yylval.string = strdup (p);
+                  yylval.string = mu_strdup (p);
                   return STRING;}
 {WS}           ;
-{WORD}         { yylval.string = strdup (yytext); return STRING;}
+{WORD}         { yylval.string = mu_strdup (yytext); return STRING;}
 ^{WS}?"<"{WS}?{WORD} {
                  char *p;
                  for (p = yytext; p < yytext + yyleng && mu_isblank(*p); p++)
@@ -368,7 +368,7 @@ SPEC [,:;+=\*]
                  push_source (p, 1); }
 {SPEC}         return yytext[0];
 <VERBATIM>[^ \t\n,:;+=\*][^\n,]* {
-                    yylval.string = xmalloc (yyleng + 1);
+                    yylval.string = mu_alloc (yyleng + 1);
                    memcpy(yylval.string, yytext, yyleng);
                    yylval.string[yyleng] = 0;
                    return STRING;}
diff --git a/mh/mh_alias.y b/mh/mh_alias.y
index 936d22e..50608f0 100644
--- a/mh/mh_alias.y
+++ b/mh/mh_alias.y
@@ -68,7 +68,7 @@ ali_list_to_string (mu_list_t *plist)
          length += strlen (s) + 1;
        }
   
-      string = xmalloc (length + 1);
+      string = mu_alloc (length + 1);
       p = string;
       for (mu_iterator_first (itr); !mu_iterator_is_done (itr); 
mu_iterator_next(itr))
        {
@@ -133,7 +133,7 @@ nl           : '\n'
 alias        : STRING ':' { ali_verbatim (1); } address_group
                {
                 ali_verbatim (0);
-                $$ = xmalloc (sizeof (*$$));
+                $$ = mu_alloc (sizeof (*$$));
                 $$->name = $1;
                 $$->rcpt_list = $4;
                 $$->inclusive = 0;
@@ -141,7 +141,7 @@ alias        : STRING ':' { ali_verbatim (1); } 
address_group
              | STRING ';' { ali_verbatim (1); } address_group
                {
                 ali_verbatim (0);
-                $$ = xmalloc (sizeof (*$$));
+                $$ = mu_alloc (sizeof (*$$));
                 $$->name = $1;
                 $$->rcpt_list = $4;
                 $$->inclusive = 1;
@@ -445,7 +445,7 @@ unix_group_to_list (char *name)
       char **p;
 
       for (p = grp->gr_mem; *p; p++)
-       mu_list_append (lst, strdup (*p));
+       mu_list_append (lst, mu_strdup (*p));
     }      
   
   return lst;
@@ -464,7 +464,7 @@ unix_gid_to_list (char *name)
       while ((pw = getpwent ()))
        {
          if (pw->pw_gid == grp->gr_gid)
-           mu_list_append (lst, strdup (pw->pw_name));
+           mu_list_append (lst, mu_strdup (pw->pw_name));
        }
       endpwent();
     }
@@ -481,7 +481,7 @@ unix_passwd_to_list ()
   while ((pw = getpwent ()))
     {
       if (pw->pw_uid > 200)
-       mu_list_append (lst, strdup (pw->pw_name));
+       mu_list_append (lst, mu_strdup (pw->pw_name));
     }
   endpwent();
   return lst;
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index 37ebfa7..ac67415 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -557,8 +557,8 @@ prog_reserve (size_t count)
     {
       size_t inc = (count + 1) / FORMAT_INC + 1;
       format.progsize += inc * FORMAT_INC;
-      format.prog = xrealloc (format.prog,
-                             format.progsize * sizeof format.prog[0]);
+      format.prog = mu_realloc (format.prog,
+                               format.progsize * sizeof format.prog[0]);
     }
 }
 
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 093d869..fc51edf 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -55,7 +55,7 @@ strobj_create (strobj_t *lvalue, const char *str)
   else
     {
       lvalue->size = strlen (str) + 1;
-      lvalue->ptr = xmalloc (lvalue->size);
+      lvalue->ptr = mu_alloc (lvalue->size);
       memcpy (lvalue->ptr, str, lvalue->size);
     }
 }
@@ -97,14 +97,14 @@ strobj_realloc (strobj_t *obj, size_t length)
   if (strobj_is_static (obj))
     {
       char *value = strobj_ptr (obj);
-      obj->ptr = xmalloc (length);
+      obj->ptr = mu_alloc (length);
       strncpy (obj->ptr, value, length-1);
       obj->ptr[length-1] = 0;
       obj->size = length;
     }
   else
     {
-      obj->ptr = xrealloc (obj->ptr, length);
+      obj->ptr = mu_realloc (obj->ptr, length);
       obj->ptr[length-1] = 0;
       obj->size = length;
     }
@@ -513,7 +513,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
         the LC_BASE mh_profile variable to the desired base part.
       */
       const char *lc_base = mh_global_profile_get ("LC_BASE", "en_US");
-      char *locale = xmalloc (strlen (lc_base) + 1 + strlen (charset) + 1);
+      char *locale = mu_alloc (strlen (lc_base) + 1 + strlen (charset) + 1);
       strcpy (locale, lc_base);
       strcat (locale, ".");
       strcat (locale, charset);
@@ -615,7 +615,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
            if (size > rest)
              size = rest;
 
-           mach.arg_str.ptr = xmalloc (size+1);
+           mach.arg_str.ptr = mu_alloc (size+1);
            mach.arg_str.size = size;
            
            str_off = 0;
@@ -679,7 +679,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
   if (pret)
     {
       obstack_1grow (&mach.stk, 0);
-      *pret = strdup (obstack_finish (&mach.stk));
+      *pret = mu_strdup (obstack_finish (&mach.stk));
     }
   obstack_free (&mach.stk, NULL);
   return mach.ind;
@@ -1868,8 +1868,8 @@ builtin_unre (struct mh_machine *mach)
   int rc = mu_unre_subject (strobj_ptr (&mach->arg_str), &p);
   if (rc == 0 && p != strobj_ptr (&mach->arg_str))
     {
-      char *q = strdup (p); /* Create a copy, since strobj_create will
-                              destroy p */
+      char *q = mu_strdup (p); /* Create a copy, since strobj_create will
+                                 destroy p */
       strobj_free (&mach->arg_str);
       strobj_create (&mach->arg_str, q);
       free (q);
@@ -1983,7 +1983,7 @@ builtin_printhdr (struct mh_machine *mach)
   if (!strobj_is_null (&mach->arg_str))
     {
       s = strobj_len (&mach->arg_str);
-      tmp = strdup (strobj_ptr (&mach->arg_str));
+      tmp = mu_strdup (strobj_ptr (&mach->arg_str));
     }
   
   if (!strobj_is_null (&mach->reg_str))
diff --git a/mh/mh_global.c b/mh/mh_global.c
index db7dc77..4bb4dcc 100644
--- a/mh/mh_global.c
+++ b/mh/mh_global.c
@@ -30,7 +30,7 @@ mh_read_property_file (char *name, int ro)
   struct mu_mh_prop *mhprop;
   int rc;
   
-  mhprop = xzalloc (sizeof (mhprop[0]));
+  mhprop = mu_zalloc (sizeof (mhprop[0]));
   mhprop->filename = name;
   mhprop->ro = ro;
   rc = mu_property_create_init (&prop, mu_mh_property_init, mhprop);
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 0e419e8..8af3c2e 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -94,7 +94,7 @@ mh_read_formfile (char *name, char **pformat)
     }
   free (file_name);
   
-  format_str = xmalloc (st.st_size+1);
+  format_str = mu_alloc (st.st_size+1);
   while ((ptr = fgets (format_str + off, st.st_size - off + 1, fp)) != NULL)
     {
       int len = strlen (ptr);
@@ -147,7 +147,7 @@ mh_get_my_name (char *name)
       name = pw->pw_name;
     }
 
-  my_name = strdup (name);
+  my_name = mu_strdup (name);
   my_email = mu_get_user_email (name);
 }
 
@@ -170,7 +170,7 @@ mh_is_my_name (const char *name)
   char *pname, *p;
   int rc = 0;
   
-  pname = strdup (name);
+  pname = mu_strdup (name);
   p = strchr (pname, '@');
   if (p)
     for (p++; *p; p++)
@@ -210,7 +210,7 @@ mh_is_my_name (const char *name)
              while (len > 0 && mu_isspace (p[len-1]))
                len--;
 
-             pat = xmalloc (len + 1);
+             pat = mu_alloc (len + 1);
              memcpy (pat, p, len);
              pat[len] = 0;
              rc = emailcmp (pat, pname) == 0;
@@ -234,7 +234,7 @@ static int
 make_dir_hier (const char *p, mode_t perm)
 {
   int rc = 0;
-  char *dir = xstrdup (p);
+  char *dir = mu_strdup (p);
   char *q = dir;
 
   while (!rc && (q = strchr (q + 1, '/')))
@@ -528,7 +528,7 @@ mh_find_file (const char *name, char **resolved_name)
       (name[0] == '.' && name[1] == '/') ||
       (name[0] == '.' && name[1] == '.' && name[2] == '/'))
     {
-      *resolved_name = xstrdup (name);
+      *resolved_name = mu_strdup (name);
       if (access (name, R_OK) == 0)
        return 0;
       return errno;
@@ -565,7 +565,7 @@ mh_find_file (const char *name, char **resolved_name)
                    _("cannot access %s: %s"), s, mu_strerror (errno));
   free (s);
 
-  *resolved_name = xstrdup (name);
+  *resolved_name = mu_strdup (name);
   if (access (name, R_OK) == 0)
     return 0;
   rc = errno;
@@ -925,7 +925,7 @@ mh_quote (const char *in, char **out)
         if (*p == '\\' || *p == '"')
          len++;
 
-      *out = xmalloc (len + 1);
+      *out = mu_alloc (len + 1);
       q = *out;
       p = in;
       *q++ = *p++;
@@ -939,7 +939,7 @@ mh_quote (const char *in, char **out)
       *q = 0;
     }
   else
-    *out = xstrdup (in);
+    *out = mu_strdup (in);
 }
 
 void
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 4aa8be0..f59e347 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -89,7 +89,7 @@ static mhl_variable_t *variable_lookup (char *name);
 static mhl_stmt_t *
 stmt_alloc (enum mhl_type type)
 {
-  mhl_stmt_t *p = xmalloc (sizeof (*p));
+  mhl_stmt_t *p = mu_alloc (sizeof (*p));
   p->type = type;
   return p;
 }
@@ -104,7 +104,7 @@ compdecl (char **str, char **compname)
       if (*p == ':')
        {
          int len = p - *str;
-         *compname = xmalloc (len + 1);
+         *compname = mu_alloc (len + 1);
          memcpy (*compname, *str, len);
          (*compname)[len] = 0;
          *str = p + 1;
@@ -121,7 +121,7 @@ parse_cleartext (locus_t *loc, mu_list_t formlist, char 
*str)
 {
   int len;
   mhl_stmt_t *stmt = stmt_alloc (stmt_cleartext);
-  stmt->v.cleartext = strdup (str);
+  stmt->v.cleartext = mu_strdup (str);
   len = strlen (stmt->v.cleartext);
   if (len > 0 && stmt->v.cleartext[len-1] == '\n')
     stmt->v.cleartext[len-1] = 0;
@@ -211,7 +211,7 @@ parse_variable (locus_t *loc, mu_list_t formlist, char *str)
       switch (var->type)
        {
        case dt_string:
-         stmt->v.variable.value.str = strdup (value);
+         stmt->v.variable.value.str = mu_strdup (value);
          break;
 
        case dt_integer:
@@ -226,7 +226,7 @@ parse_variable (locus_t *loc, mu_list_t formlist, char *str)
                        loc->line);
              exit (1);
            }
-         stmt->v.variable.value.fmt = xmalloc (sizeof (mh_format_t));
+         stmt->v.variable.value.fmt = mu_alloc (sizeof (mh_format_t));
          *stmt->v.variable.value.fmt = fmt;
          break;
 
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 8902217..8cea599 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -651,7 +651,7 @@ mh_disposition (const char *filename)
   struct mh_whatnow_env wh;
   int rc;
   memset (&wh, 0, sizeof (wh));
-  wh.file = xstrdup (filename);
+  wh.file = mu_strdup (filename);
   wh.prompt = (char*) _("Disposition?");
   rc = _whatnow (&wh, disp_tab);
   free (wh.file);
@@ -704,7 +704,7 @@ mh_usedraft (const char *filename)
   int rc;
   
   memset (&wh, 0, sizeof (wh));
-  wh.file = xstrdup (filename);
+  wh.file = mu_strdup (filename);
   mu_asprintf (&wh.prompt, _("Use \"%s\"?"), filename);
   rc = _whatnow (&wh, usedraft_tab);
   free (wh.prompt);
diff --git a/mh/mh_whom.c b/mh/mh_whom.c
index fe8dde9..c6d614d 100644
--- a/mh/mh_whom.c
+++ b/mh/mh_whom.c
@@ -29,7 +29,7 @@ static void
 addrcp (mu_list_t *list, char *addr, int isbcc)
 {
   int rc;
-  struct recipient *p = xmalloc (sizeof (*p));
+  struct recipient *p = mu_alloc (sizeof (*p));
   p->addr = addr;
   p->isbcc = isbcc;
   if (!*list && (rc = mu_list_create (list)))
@@ -227,7 +227,7 @@ read_header (mu_stream_t stream)
       exit (1);
     }
 
-  blurb = xmalloc (size + 1);
+  blurb = mu_alloc (size + 1);
 
   total = 0;
   while (1)
diff --git a/mh/mhn.c b/mh/mhn.c
index 5aadf94..e209f1f 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -19,7 +19,7 @@
 #include <mh.h>
 #include <signal.h>
 #include <mailutils/mime.h>
-#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_alloc mu_alloc
 #define obstack_chunk_free free
 #include <obstack.h>
 #include <setjmp.h>
@@ -184,17 +184,17 @@ split_content (const char *content, char **type, char 
**subtype)
   if (p)
     {
       int len = p - content;
-      *type = xmalloc (len + 1);
+      *type = mu_alloc (len + 1);
       memcpy (*type, content, len);
       (*type)[len] = 0;
 
       p++;
-      *subtype = xmalloc (strlen (p) + 1);
+      *subtype = mu_alloc (strlen (p) + 1);
       strcpy (*subtype, p);
     }
   else
     {
-      *type = xmalloc (strlen (content) + 1);
+      *type = mu_alloc (strlen (content) + 1);
       strcpy (*type, content);
       *subtype = NULL;
     }
@@ -234,7 +234,7 @@ _get_content_type (mu_header_t hdr, char **value, char 
**rest)
     {
       if (type)
        free (type);
-      type = xstrdup ("text/plain"); /* Default.  */
+      type = mu_strdup ("text/plain"); /* Default.  */
       if (rest)
        *rest = NULL;
     }
@@ -260,7 +260,7 @@ _get_content_encoding (mu_header_t hdr, char **value)
     {
       if (encoding)
        free (encoding);
-      encoding = xstrdup ("7bit"); /* Default.  */
+      encoding = mu_strdup ("7bit"); /* Default.  */
     }
   *value = encoding;
   return 0;
@@ -445,9 +445,9 @@ struct _msg_part
 msg_part_t 
 msg_part_create (size_t num)
 {
-  msg_part_t p = xmalloc (sizeof (*p));
+  msg_part_t p = mu_alloc (sizeof (*p));
   p->maxlevel = 16;
-  p->part = xmalloc (sizeof (*p->part) * p->maxlevel);
+  p->part = mu_alloc (sizeof (*p->part) * p->maxlevel);
   p->part[0] = num;
   p->level = 0;
   return p;
@@ -477,7 +477,7 @@ msg_part_incr (msg_part_t p)
   if (p->level == p->maxlevel)
     {
       p->maxlevel += 16;
-      p->part = xrealloc (p->part, sizeof (*p->part) * p->maxlevel);
+      p->part = mu_realloc (p->part, sizeof (*p->part) * p->maxlevel);
     }
   p->level++;
 }
@@ -529,7 +529,7 @@ msg_part_format (msg_part_t p)
       width += strlen (mu_umaxtostr (0, p->part[i]));
     }
 
-  str = s = xmalloc (width + 1);
+  str = s = mu_alloc (width + 1);
   for (i = 1; i <= p->level; i++)
     {
       if (i > 1)
@@ -709,7 +709,7 @@ mhn_compose_command (char *typestr, char *typeargs, int 
*flags, char *file)
   if (!*p)
     str = NULL;
   else
-    str = xstrdup (p);
+    str = mu_strdup (p);
 
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -920,7 +920,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int 
*flags,
   if (!*p)
     str = NULL;
   else
-    str = xstrdup (p);
+    str = mu_strdup (p);
 
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -957,7 +957,7 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const 
char *name,
          /* If the content is not application/octet-stream, then mhn
             will check to see if the content is a message.  If so, mhn
             will use the value "+".  */
-         *return_string = xstrdup (mh_current_folder ());
+         *return_string = mu_strdup (mh_current_folder ());
          return store_to_folder_msg;
        }
       else if (mu_c_strcasecmp (typestr, "application/octet-stream") == 0 &&
@@ -974,9 +974,9 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const 
char *name,
     {
     case '+':
       if (str[1])
-       *return_string = xstrdup (str);
+       *return_string = mu_strdup (str);
       else
-       *return_string = xstrdup (mh_current_folder ());
+       *return_string = mu_strdup (mh_current_folder ());
       return store_to_folder;
 
     case '-':
@@ -1060,7 +1060,7 @@ mhn_store_command (mu_message_t msg, msg_part_t part, 
const char *name,
   if (!*p)
     *return_string = NULL;
   else
-    *return_string = xstrdup (p);
+    *return_string = mu_strdup (p);
   
   obstack_free (&stk, NULL);
   return dest;
@@ -1147,7 +1147,7 @@ get_extbody_params (mu_message_t msg, char **content, 
char **descr)
        {
          p = mu_str_skip_class (buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION),
                                 MU_CTYPE_SPACE);
-         *descr = xstrdup (p);
+         *descr = mu_strdup (p);
        }
       else if (content
               && mu_c_strncasecmp (buf, MU_HEADER_CONTENT_TYPE ":",
@@ -1159,7 +1159,7 @@ get_extbody_params (mu_message_t msg, char **content, 
char **descr)
          q = strchr (p, ';');
          if (q)
            *q = 0;
-         *content = xstrdup (p);
+         *content = mu_strdup (p);
        }
     }
   mu_stream_destroy (&stream);
@@ -1919,7 +1919,7 @@ parse_brace (char **pval, char **cmd, int c, struct 
compose_env *env)
       return 1;
     }
   len = sp - rest;
-  val = xmalloc (len + 1);
+  val = mu_alloc (len + 1);
   memcpy (val, rest, len);
   val[len] = 0;
   *cmd = sp + 1;
@@ -2517,11 +2517,11 @@ edit_mime (char *cmd, struct compose_env *env, 
mu_message_t *msg, int level)
       _get_content_type (hdr, &typestr, NULL);
       split_content (typestr, &type, &subtype);
       if (mu_c_strcasecmp (type, "message") == 0)
-       encoding = xstrdup ("7bit");
+       encoding = mu_strdup ("7bit");
       else if (mu_c_strcasecmp (type, "text") == 0)
-       encoding = xstrdup ("quoted-printable");
+       encoding = mu_strdup ("quoted-printable");
       else
-       encoding = xstrdup ("base64");
+       encoding = mu_strdup ("base64");
       mu_header_set_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding, 
1);
       free (typestr);
       free (type);
@@ -2623,7 +2623,7 @@ mhn_edit (struct compose_env *env, int level)
                      if (n + n2 > bufsize)
                        {
                          bufsize += 128;
-                         buf = xrealloc (buf, bufsize);
+                         buf = mu_realloc (buf, bufsize);
                        }
                      memcpy (buf + n - 2, b2, n2);
                      n += n2 - 2;
@@ -2736,7 +2736,7 @@ parse_header_directive (const char *val, char **encoding, 
char **charset,
 
   if (*val != '#')
     {
-      *subject = xstrdup (val);
+      *subject = mu_strdup (val);
       return 1;
     }
   val++;
@@ -2753,7 +2753,7 @@ parse_header_directive (const char *val, char **encoding, 
char **charset,
          int i, argc;
          char **argv;
            
-         *subject = xstrdup (p + 1);
+         *subject = mu_strdup (p + 1);
          split_args (val + 1, p - val - 1, &argc, &argv);
          for (i = 0; i < argc; i++)
            {
@@ -2761,13 +2761,13 @@ parse_header_directive (const char *val, char 
**encoding, char **charset,
                  && memcmp (argv[i], "charset=", 8) == 0)
                {
                  free (*charset);
-                 *charset = xstrdup (argv[i] + 8);
+                 *charset = mu_strdup (argv[i] + 8);
                }
              else if (strlen (argv[i]) > 9
                       && memcmp (argv[i], "encoding=", 9) == 0)
                {
                  free (*encoding);
-                 *encoding = xstrdup (argv[i] + 9);
+                 *encoding = mu_strdup (argv[i] + 9);
                }
            }
          mu_argcv_free (argc, argv);
@@ -2778,7 +2778,7 @@ parse_header_directive (const char *val, char **encoding, 
char **charset,
     default:
       val--;
     }
-  *subject = xstrdup (val);
+  *subject = mu_strdup (val);
   return 1;
 }
 
@@ -2824,7 +2824,7 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
                        if (strlen (argv[i]) > 8
                            && memcmp (argv[i], "charset=", 8) == 0)
                          {
-                           charset = xstrdup (argv[i]+8);
+                           charset = mu_strdup (argv[i]+8);
                            break;
                          }
                      mu_argcv_free (argc, argv);
@@ -2842,7 +2842,7 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
          if (!encoding || strcmp (encoding, "7bit") == 0)
            {
              free (encoding);
-             encoding = xstrdup ("base64");
+             encoding = mu_strdup ("base64");
            }
          rc = mu_rfc2047_encode (charset, encoding, subject, &p);
          if (rc)
diff --git a/mh/pick.y b/mh/pick.y
index 700bc19..a7b9bdc 100644
--- a/mh/pick.y
+++ b/mh/pick.y
@@ -25,7 +25,7 @@ static void set_cflags (char *str);
 static regex_t *
 regex_dup (regex_t *re)
 {
-  regex_t *rp = xmalloc (sizeof (*rp));
+  regex_t *rp = mu_alloc (sizeof (*rp));
   *rp = *re;
   return rp;
 }
@@ -245,7 +245,7 @@ pick_add_token (mu_list_t *list, int tok, char *val)
       mu_error(_("cannot create list: %s"), mu_strerror (rc));
       exit (1);
     }
-  tp = xmalloc (sizeof (*tp));
+  tp = mu_alloc (sizeof (*tp));
   tp->tok = tok;
   tp->val = val;
   mu_list_append (*list, tp);
@@ -279,7 +279,7 @@ pick_node_create (node_type type, void *a, void *b)
 {
   node_t *node;
 
-  node = xmalloc (sizeof (*node));
+  node = mu_alloc (sizeof (*node));
   node->type = type;
   node->v.gen.a = a;
   node->v.gen.b = b;
diff --git a/mh/prompter-rl.c b/mh/prompter-rl.c
index 21fdaa8..78f1ce4 100644
--- a/mh/prompter-rl.c
+++ b/mh/prompter-rl.c
@@ -50,7 +50,7 @@ prompter_get_value (const char *name)
 
   if (name)
     {
-      prompt = xmalloc (strlen (name) + 3);
+      prompt = mu_alloc (strlen (name) + 3);
       strcpy (prompt, name);
       strcat (prompt, ": ");
     }
diff --git a/mh/refile.c b/mh/refile.c
index 1d48faf..596fe40 100644
--- a/mh/refile.c
+++ b/mh/refile.c
@@ -70,7 +70,7 @@ add_folder (const char *folder)
       mu_error (_("cannot create folder list"));
       exit (1);
     }
-  mu_list_append (folder_name_list, strdup (folder));
+  mu_list_append (folder_name_list, mu_strdup (folder));
 }
 
 void
diff --git a/mh/repl.c b/mh/repl.c
index a31af39..901cc80 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -385,7 +385,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct 
mh_whatnow_env *wh)
       wh->msg = msgname;
     else
       {
-       wh->msg = strdup (p+1);
+       wh->msg = mu_strdup (p+1);
        free (msgname);
       }
   }
diff --git a/mh/send.c b/mh/send.c
index e1713f4..a6911d6 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -302,7 +302,7 @@ check_file (char *name)
       mu_error (_("cannot create message list"));
       return 1;
     }
-  elt = xmalloc (sizeof *elt);
+  elt = mu_alloc (sizeof *elt);
   elt->file_name = file_name;
   elt->msg = msg;
   return mu_list_append (mesg_list, elt);
@@ -354,7 +354,7 @@ read_mts_profile ()
     {
       char *newdomain;
 
-      newdomain = xmalloc (strlen (hostname) + 1 + strlen (p) + 1);
+      newdomain = mu_alloc (strlen (hostname) + 1 + strlen (p) + 1);
       strcpy (newdomain, hostname);
       strcat (newdomain, ".");
       strcat (newdomain, p);
@@ -388,7 +388,7 @@ read_mts_profile ()
          exit (1);
        }
       len = strlen (p) + 1 + strlen (domain) + 1;
-      newemail = xmalloc (len);
+      newemail = mu_alloc (len);
       strcpy (newemail, p);
       strcat (newemail, "@");
       strcat (newemail, domain);
@@ -621,7 +621,7 @@ fix_dcc (mu_message_t msg)
 void
 backup_file (const char *file_name)
 {
-  char *new_name = xmalloc (strlen (file_name) + 2);
+  char *new_name = mu_alloc (strlen (file_name) + 2);
   char *p = strrchr (file_name, '/');
   if (p)
     {
@@ -744,7 +744,7 @@ _add_to_mesg_list (size_t num, mu_message_t msg, void *data)
   size_t uid;
   int rc;
   
-  elt = xmalloc (sizeof *elt);
+  elt = mu_alloc (sizeof *elt);
   elt->msg = msg;
   mu_message_get_uid (msg, &uid);
   elt->file_name = mu_make_file_name (path, mu_umaxtostr (0, uid));
diff --git a/mh/sortm.c b/mh/sortm.c
index 158bd97..4795fc6 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -207,7 +207,7 @@ static mu_list_t oplist;
 static void
 addop (char *field, compfun comp)
 {
-  struct comp_op *op = xmalloc (sizeof (*op));
+  struct comp_op *op = mu_alloc (sizeof (*op));
   
   if (!oplist)
     {
@@ -491,7 +491,7 @@ void
 sort ()
 {
   size_t *oldlist, i;
-  oldlist = xmalloc (msgcount * sizeof (*oldlist));
+  oldlist = mu_alloc (msgcount * sizeof (*oldlist));
   memcpy (oldlist, msgarr, msgcount * sizeof (*oldlist));
 
   switch (algorithm)
@@ -587,7 +587,7 @@ fill_msgarr (mu_msgset_t msgset)
       exit (1);
     }
       
-  msgarr = xcalloc (msgcount, sizeof (msgarr[0]));
+  msgarr = mu_calloc (msgcount, sizeof (msgarr[0]));
   i = 0;
   rc = mu_msgset_foreach_msgno (msgset, _add_msgno, &i);
   if (rc)
diff --git a/mimeview/mimetypes.y b/mimeview/mimetypes.y
index 2df3861..2fafa08 100644
--- a/mimeview/mimetypes.y
+++ b/mimeview/mimetypes.y
@@ -505,7 +505,7 @@ b_contains (union argument *args)
       return 0;
     }
 
-  buf = xmalloc (args[1].number);
+  buf = mu_alloc (args[1].number);
   rc = mu_stream_read (mimeview_stream, buf, args[1].number, &count);
   if (count != args[1].number)
     {
diff --git a/mimeview/mimeview.h b/mimeview/mimeview.h
index 681b11a..2c42866 100644
--- a/mimeview/mimeview.h
+++ b/mimeview/mimeview.h
@@ -21,7 +21,6 @@
 # include <strings.h>
 #endif
 #include <mailutils/mailutils.h>
-#include <xalloc.h>
 #include <fnmatch.h>
 #define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
diff --git a/mu/acl.c b/mu/acl.c
index a1349dd..f545f71 100644
--- a/mu/acl.c
+++ b/mu/acl.c
@@ -27,7 +27,6 @@
 #include <mailutils/libcfg.h>
 #include "argp.h"
 #include "mu.h"
-#include "xalloc.h"
 
 static char acl_doc[] = N_("mu acl - test access control lists.");
 char acl_docstring[] = N_("test access control lists");
diff --git a/mu/dbm.c b/mu/dbm.c
index 9d79322..6546353 100644
--- a/mu/dbm.c
+++ b/mu/dbm.c
@@ -29,7 +29,6 @@
 #include <mailutils/dbm.h>
 #include "argp.h"
 #include "mu.h"
-#include "xalloc.h"
 
 static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
 "Valid COMMANDs are:\n"
@@ -519,7 +518,7 @@ C_read_datum (struct iobuf *inp, struct mu_dbm_datum *datum)
     }
 
   memset (datum, 0, sizeof (*datum));
-  datum->mu_dptr = ptr = xmalloc (length);
+  datum->mu_dptr = ptr = mu_alloc (length);
   base = inp->buffer;
   for (i = 0; i < length; ptr++)
     {
@@ -797,7 +796,7 @@ print_action (struct mu_dbm_datum const *key, void *data)
          struct mu_auth_data *ap = mu_get_auth_by_uid (owner_uid);
          if (ap)
            {
-             owner_user = xstrdup (ap->name);
+             owner_user = mu_strdup (ap->name);
              known_meta_data |= META_USER;
              mu_auth_data_free (ap);
            }
@@ -808,7 +807,7 @@ print_action (struct mu_dbm_datum const *key, void *data)
          struct group *gr = getgrgid (owner_gid);
          if (gr)
            {
-             owner_group = xstrdup (gr->gr_name);
+             owner_group = mu_strdup (gr->gr_name);
              known_meta_data |= META_GROUP;
            }
        }
@@ -858,7 +857,7 @@ iterate_database (mu_dbm_file_t db,
          if (key.mu_dsize + 1 > bufsize)
            {
              bufsize = key.mu_dsize + 1;
-             buf = xrealloc (buf, bufsize);
+             buf = mu_realloc (buf, bufsize);
            }
          memcpy (buf, key.mu_dptr, key.mu_dsize);
          buf[key.mu_dsize] = 0;
@@ -924,7 +923,7 @@ match_regex (const char *str, void *data)
 static void
 compile_regexes (int argc, char **argv, struct regmatch *match)
 {
-  regex_t *regs = xcalloc (argc, sizeof (regs[0]));
+  regex_t *regs = mu_calloc (argc, sizeof (regs[0]));
   int i;
   int cflags = (case_sensitive ? 0: REG_ICASE) | REG_EXTENDED | REG_NOSUB;
   int errors = 0;
@@ -1028,7 +1027,7 @@ static int
 _set_file (const char *val)
 {
   if (!db_name)
-    db_name = xstrdup (val);
+    db_name = mu_strdup (val);
   return 0;
 }
 
@@ -1095,7 +1094,7 @@ _set_user (const char *val)
   if (known_meta_data & META_USER)
     return 0;
   free (owner_user);
-  owner_user = xstrdup (val);
+  owner_user = mu_strdup (val);
   known_meta_data |= META_USER;
   return 0;
 }
@@ -1106,7 +1105,7 @@ _set_group (const char *val)
   if (known_meta_data & META_GROUP)
     return 0;
   free (owner_group);
-  owner_group = xstrdup (val);
+  owner_group = mu_strdup (val);
   known_meta_data |= META_GROUP;
   return 0;
 }
@@ -1504,7 +1503,7 @@ store_to_list (struct mu_dbm_datum const *key, void *data)
 {
   int rc;
   mu_list_t list = data;
-  char *p = xmalloc (key->mu_dsize + 1);
+  char *p = mu_alloc (key->mu_dsize + 1);
   memcpy (p, key->mu_dptr, key->mu_dsize);
   p[key->mu_dsize] = 0;
   rc = mu_list_append (list, p);
@@ -1567,7 +1566,7 @@ delete_database (int argc, char **argv)
     case key_literal:
       for (i = 0; i < argc; i++)
        {
-         char *p = xstrdup (argv[i]);
+         char *p = mu_strdup (argv[i]);
          rc = mu_list_append (templist, p);
          if (rc)
            {
diff --git a/mu/dispatch.c b/mu/dispatch.c
index eccfbaf..2ebcd47 100644
--- a/mu/dispatch.c
+++ b/mu/dispatch.c
@@ -19,11 +19,11 @@
 #endif
 #include <stdlib.h>
 #include <string.h>
+#include <mailutils/alloc.h>
 #include <mailutils/stream.h>
 #include <mailutils/nls.h>
 #include "mu.h"
 #include "mu-setup.h"
-#include "xalloc.h"
 
 struct mutool_action_tab
 {
@@ -68,7 +68,7 @@ dispatch_docstring (const char *text)
   mu_stream_printf (str, "%s\n", _("Options are:"));
   mu_stream_flush (str);
   mu_stream_size (str, &size);
-  ret = xmalloc (size + 1);
+  ret = mu_alloc (size + 1);
   mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
   mu_stream_read (str, ret, size, &n);
   ret[n] = 0;
diff --git a/mu/imap.c b/mu/imap.c
index 6b9212d..98890aa 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -30,7 +30,6 @@
 #include <mailutils/msgset.h>
 #include "mu.h"
 #include "argp.h"
-#include "xalloc.h"
 
 static char imap_doc[] = N_("mu imap - IMAP4 client shell.");
 char imap_docstring[] = N_("IMAP4 client shell");
@@ -155,7 +154,7 @@ imap_prompt_env ()
 {
   enum mu_imap_session_state state = current_imap_state ();
   if (!mutool_prompt_env)
-    mutool_prompt_env = xcalloc (2*7 + 1, sizeof(mutool_prompt_env[0]));
+    mutool_prompt_env = mu_calloc (2*7 + 1, sizeof(mutool_prompt_env[0]));
 
   mutool_prompt_env[0] = "user";
   mutool_prompt_env[1] = (state >= MU_IMAP_SESSION_AUTH && username) ?
@@ -618,9 +617,9 @@ com_connect (int argc, char **argv)
   if (!status)
     {
       connect_argc = argc;
-      connect_argv = xcalloc (argc, sizeof (*connect_argv));
+      connect_argv = mu_calloc (argc, sizeof (*connect_argv));
       for (i = 0; i < argc; i++)
-       connect_argv[i] = xstrdup (argv[i]);
+       connect_argv[i] = mu_strdup (argv[i]);
       connect_argv[i] = NULL;
     
       imap_prompt_env ();
@@ -1319,7 +1318,7 @@ mutool_imap (int argc, char **argv)
     }
 
   /* Command line prompt */
-  mutool_shell_prompt = xstrdup ("imap> ");
+  mutool_shell_prompt = mu_strdup ("imap> ");
   imap_prompt_env ();
   mutool_shell ("imap", imap_comtab);
   return 0;
diff --git a/mu/pop.c b/mu/pop.c
index b57c694..fd19168 100644
--- a/mu/pop.c
+++ b/mu/pop.c
@@ -27,7 +27,6 @@
 #include <mailutils/mailutils.h>
 #include "mu.h"
 #include "argp.h"
-#include "xalloc.h"
 
 static char pop_doc[] = N_("mu pop - POP3 client shell.");
 char pop_docstring[] = N_("POP3 client shell");
@@ -99,7 +98,7 @@ static void
 pop_prompt_env ()
 {
   if (!mutool_prompt_env)
-    mutool_prompt_env = xcalloc (2*7 + 1, sizeof(mutool_prompt_env[0]));
+    mutool_prompt_env = mu_calloc (2*7 + 1, sizeof(mutool_prompt_env[0]));
 
   mutool_prompt_env[0] = "user";
   mutool_prompt_env[1] = (pop_session_status == pop_session_logged_in) ?
@@ -169,7 +168,7 @@ com_user (int argc, char **argv)
   status = mu_pop3_user (pop3, argv[1]);
   if (status == 0)
     {
-      username = strdup (argv[1]);
+      username = mu_strdup (argv[1]);
       pop_prompt_env ();
     }
   return status;
@@ -199,7 +198,7 @@ com_apop (int argc, char **argv)
   status = mu_pop3_apop (pop3, argv[1], pwd);
   if (status == 0)
     {
-      username = strdup (argv[1]);
+      username = mu_strdup (argv[1]);
       pop_session_status = pop_session_logged_in;
     }
   free (passbuf);
@@ -577,9 +576,9 @@ com_connect (int argc, char **argv)
   else
     {
       connect_argc = argc;
-      connect_argv = xcalloc (argc, sizeof (*connect_argv));
+      connect_argv = mu_calloc (argc, sizeof (*connect_argv));
       for (i = 0; i < argc; i++)
-       connect_argv[i] = xstrdup (argv[i]);
+       connect_argv[i] = mu_strdup (argv[i]);
       connect_argv[i] = NULL;
       port = n;
       pop_session_status = pop_session_connected;
@@ -688,7 +687,7 @@ mutool_pop (int argc, char **argv)
     }
 
   /* Command line prompt */
-  mutool_shell_prompt = xstrdup ("pop> ");
+  mutool_shell_prompt = mu_strdup ("pop> ");
   pop_prompt_env ();
   mutool_shell ("pop", pop_comtab);
   return 0;
diff --git a/mu/shell.c b/mu/shell.c
index bfc4ad0..358d2ac 100644
--- a/mu/shell.c
+++ b/mu/shell.c
@@ -25,7 +25,6 @@
 #include "mailutils/libargp.h"
 #include "muaux.h"
 #include "mu.h"
-#include "xalloc.h"
 
 #ifdef WITH_READLINE
 # include <readline/readline.h>
@@ -257,7 +256,7 @@ shell_prompt (int argc, char **argv)
   
   free (mutool_shell_prompt);
   size = strlen (argv[1]);
-  mutool_shell_prompt = xmalloc (size + 1);
+  mutool_shell_prompt = mu_alloc (size + 1);
   mu_wordsplit_c_unquote_copy (mutool_shell_prompt, argv[1], size);
   return 0;
 }
@@ -292,8 +291,8 @@ get_history_file_name ()
     {
       char *hname;
       
-      hname = xmalloc(sizeof HISTFILE_PREFIX + strlen (rl_readline_name) +
-                     sizeof HISTFILE_SUFFIX - 1);
+      hname = mu_alloc (sizeof HISTFILE_PREFIX + strlen (rl_readline_name) +
+                       sizeof HISTFILE_SUFFIX - 1);
       strcpy (hname, "~/.mu_");
       strcat (hname, rl_readline_name);
       strcat (hname, HISTFILE_SUFFIX);
@@ -397,7 +396,7 @@ shell_command_generator (const char *text, int state)
     {
       cmd++;
       if (strncmp (name, text, len) == 0)
-       return xstrdup (name);
+       return mu_strdup (name);
     }
 
   /* If no names matched, then return NULL. */
@@ -653,8 +652,8 @@ mutool_shell (const char *name, struct mutool_command *cmd)
     ;
 
   user_command_count = n;
-  shell_comtab = xcalloc (n + MU_ARRAY_SIZE (default_comtab),
-                         sizeof (shell_comtab[0]));
+  shell_comtab = mu_calloc (n + MU_ARRAY_SIZE (default_comtab),
+                           sizeof (shell_comtab[0]));
   memcpy (shell_comtab, cmd, n * sizeof (shell_comtab[0]));
   memcpy (shell_comtab + n, default_comtab, sizeof (default_comtab));
 
diff --git a/pop3d/apop.c b/pop3d/apop.c
index a4f4e12..ee05080 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -150,7 +150,7 @@ pop3d_apopuser (const char *user)
          {
            p = mu_str_skip_class (p + 1, MU_CTYPE_SPACE);
            if (*p)
-             password = strdup (p);
+             password = mu_strdup (p);
            break;
          }
       }
diff --git a/pop3d/bulletin.c b/pop3d/bulletin.c
index a51cfff..b49155e 100644
--- a/pop3d/bulletin.c
+++ b/pop3d/bulletin.c
@@ -22,7 +22,7 @@ static char *bulletin_db_name;
 void
 set_bulletin_db (const char *file)
 {
-  bulletin_db_name = strdup (file);
+  bulletin_db_name = mu_strdup (file);
 }
 
 static void
@@ -65,7 +65,7 @@ open_bulletin_mailbox (mu_mailbox_t *pmbox)
 int
 set_bulletin_source (const char *source)
 {
-  bulletin_mbox_name = strdup (source);
+  bulletin_mbox_name = mu_strdup (source);
   return 0;
 }
 
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index 0e110ce..10f3524 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -16,7 +16,6 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
-#include <xalloc.h>
 #include "mailutils/libargp.h"
 
 int db_list (char *input_name, char *output_name);
@@ -592,7 +591,7 @@ fill_pass (struct action_data *ap)
          if (!p)
            exit (EX_DATAERR);
          
-         ap->passwd = strdup (p);
+         ap->passwd = mu_strdup (p);
          /* TRANSLATORS: Please try to format this string so that it has
             the same length as the translation of 'Password:' above */
          rc = mu_getpass (in, out, _("Confirm :"), &p);
@@ -715,7 +714,7 @@ action_chpass (struct action_data *ap)
     {
       char *oldpass, *p;
       
-      oldpass = xmalloc (contents.mu_dsize + 1);
+      oldpass = mu_alloc (contents.mu_dsize + 1);
       memcpy (oldpass, contents.mu_dptr, contents.mu_dsize);
       oldpass[contents.mu_dsize] = 0;
       p = getpass (_("Old Password:"));
diff --git a/pop3d/user.c b/pop3d/user.c
index cc4a799..d68ab90 100644
--- a/pop3d/user.c
+++ b/pop3d/user.c
@@ -49,9 +49,7 @@ pop3d_begin_session ()
       return ERR_MBOX_LOCK;
     }
   
-  username = strdup (auth_data->name);
-  if (username == NULL)
-    pop3d_abquit (ERR_NO_MEM);
+  username = mu_strdup (auth_data->name);
   state = TRANSACTION;
 
   pop3d_outf ("+OK opened mailbox for %s\n", username);
diff --git a/python/libmu_py/address.c b/python/libmu_py/address.c
index 664bada..0575bed 100644
--- a/python/libmu_py/address.c
+++ b/python/libmu_py/address.c
@@ -129,7 +129,11 @@ api_address_createv (PyObject *self, PyObject *args)
       for (i = 0; i < len; i++) {
        py_item = PySequence_GetItem (py_seq, i);
        if (py_item && PyString_Check (py_item))
-         sv[i] = strdup (PyString_AsString (py_item));
+         if ((sv[i] = strdup (PyString_AsString (py_item))) == NULL)
+           {
+             PyErr_NoMemory ();
+             return NULL;
+           }
        Py_DECREF (py_item);
       }
       if (PyErr_Occurred ()) {
diff --git a/readmsg/readmsg.c b/readmsg/readmsg.c
index 2697e4f..0a23f4e 100644
--- a/readmsg/readmsg.c
+++ b/readmsg/readmsg.c
@@ -19,7 +19,6 @@
 #endif
 
 #include "readmsg.h"
-#include "xalloc.h"
 #include "mailutils/libargp.h"
 #include "mu_umaxtostr.h"
 
diff --git a/sql/odbc.c b/sql/odbc.c
index 8b313ac..56143a4 100644
--- a/sql/odbc.c
+++ b/sql/odbc.c
@@ -251,9 +251,9 @@ odbc_get_column (mu_sql_connection_t conn,
       return MU_ERR_SQL;
     }
   
-  *pdata = strdup (buffer);
-  mu_list_append (dp->result, *pdata);
-  return 0;
+  if ((*pdata = strdup (buffer)) == NULL)
+    return ENOMEM;
+  return mu_list_append (dp->result, *pdata);
 }
 
 /* FIXME: untested */


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]