summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-03-25 18:02:18 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-03-25 18:02:18 +0300
commit177423b53793e3ad5dc6fd787f75b3ff4038aedf (patch)
tree3371b7fb1f2311412b0c8f1b76066e58a163559f /examples
parentbf4c4a43ac942d8d81d0d276fe15ae3217f0e5a9 (diff)
downloadmailutils-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 'examples')
-rw-r--r--examples/aclck.c17
-rw-r--r--examples/sfrom.c14
2 files changed, 19 insertions, 12 deletions
diff --git a/examples/aclck.c b/examples/aclck.c
index 041b100dc..7cf01c50b 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 8924509ef..1e19132e9 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);

Return to:

Send suggestions and report system problems to the System administrator.