diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-03-25 18:02:18 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-03-25 18:02:18 +0300 |
commit | 177423b53793e3ad5dc6fd787f75b3ff4038aedf (patch) | |
tree | 3371b7fb1f2311412b0c8f1b76066e58a163559f /mu | |
parent | bf4c4a43ac942d8d81d0d276fe15ae3217f0e5a9 (diff) | |
download | mailutils-177423b53793e3ad5dc6fd787f75b3ff4038aedf.tar.gz mailutils-177423b53793e3ad5dc6fd787f75b3ff4038aedf.tar.bz2 |
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
Diffstat (limited to 'mu')
-rw-r--r-- | mu/acl.c | 1 | ||||
-rw-r--r-- | mu/dbm.c | 21 | ||||
-rw-r--r-- | mu/dispatch.c | 4 | ||||
-rw-r--r-- | mu/imap.c | 9 | ||||
-rw-r--r-- | mu/pop.c | 13 | ||||
-rw-r--r-- | mu/shell.c | 13 |
6 files changed, 28 insertions, 33 deletions
@@ -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"); @@ -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 eccfbaf30..2ebcd47d0 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; @@ -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; @@ -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 bfc4ad042..358d2ac15 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)); |