are *WAY* better to find allocation bugs.
found 5 or 6 of'em (mostly will generate crashes)
NNTP_INCLUDES = -I$(top_srcdir)/nntp
endif
-SUBDIRS = m4 po intl doc contrib lib $(IMAP_SUBDIR) $(POP_SUBDIR) $(NNTP_SUBDIR)
+SUBDIRS = m4 po lib-lib intl doc contrib lib $(IMAP_SUBDIR) $(POP_SUBDIR) $(NNTP_SUBDIR)
bin_SCRIPTS = muttngbug fleang
xterm.c
muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(LIBPOP) $(LIBNNTP) \
- -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
+ -Llib-lib -llib -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
-muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(top_builddir)/lib/libsane.a \
+muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \
+ $(top_builddir)/lib-lib/liblib.a \
+ $(top_builddir)/lib/libsane.a \
$(LIBIMAPDEPS) $(LIBPOPDEPS) $(LIBNNTPDEPS) $(INTLDEPS)
makedoc_SOURCES = makedoc.c
muttng_dotlock_DEPENDENCIES = @LIBOBJS@
pgpringng_SOURCES = pgppubring.c pgplib.c lib.c extlib.c sha1.c md5c.c pgppacket.c ascii.c
-pgpringng_LDADD = @LIBOBJS@ $(INTLLIBS) -Llib -lsane
+pgpringng_LDADD = @LIBOBJS@ $(INTLLIBS) -Llib-lib -llib -Llib -lsane
pgpringng_DEPENDENCIES = @LIBOBJS@ $(INTLDEPS)
pgpewrapng_SOURCES = pgpewrap.c
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "ascii.h"
#include <string.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/str.h"
}
if (!i) {
- u = mem_malloc (sizeof (LIST));
+ u = p_new(LIST, 1);
u->data = str_dup (a->mailbox);
u->next = *expn;
*expn = u;
while (a) {
if (a->name && (strstr (a->name, s) == a->name)) {
if (!a_list) /* init */
- a_cur = a_list = (ALIAS *) mem_malloc (sizeof (ALIAS));
+ a_cur = a_list = p_new(ALIAS, 1);
else {
- a_cur->next = (ALIAS *) mem_malloc (sizeof (ALIAS));
+ a_cur->next = p_new(ALIAS, 1);
a_cur = a_cur->next;
}
memcpy (a_cur, a, sizeof (ALIAS));
while (a_list) {
a_cur = a_list;
a_list = a_list->next;
- mem_free (&a_cur);
+ p_delete(&a_cur);
}
/* remove any aliases marked for deletion */
}
mutt_menuDestroy (&menu);
- mem_free (&AliasTable);
+ p_delete(&AliasTable);
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "handler.h"
b->parameter = NULL;
}
if (b->description) {
- mem_free (&a->description);
+ p_delete(&a->description);
a->description = b->description;
b->description = NULL;
}
if (b->form_name) {
- mem_free (&a->form_name);
+ p_delete(&a->form_name);
a->form_name = b->form_name;
b->form_name = NULL;
}
debug_print (1, ("\"%s\" -> %s\n", b->filename, type));
}
if (tmp.subtype)
- mem_free (&tmp.subtype);
+ p_delete(&tmp.subtype);
if (tmp.xtype)
- mem_free (&tmp.xtype);
+ p_delete(&tmp.xtype);
}
}
}
if (fp) {
/* recv case: we need to save the attachment to a file */
- mem_free (&fname);
+ p_delete(&fname);
if (mutt_save_attachment (fp, a, tempfile, 0, NULL) == -1)
goto return_error;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "mx.h"
int c;
for (c = 0; c < state->entrylen; c++) {
- mem_free (&((state->entry)[c].name));
- mem_free (&((state->entry)[c].desc));
- mem_free (&((state->entry)[c].st));
+ p_delete(&((state->entry)[c].name));
+ p_delete(&((state->entry)[c].desc));
+ p_delete(&((state->entry)[c].st));
}
#ifdef USE_IMAP
- mem_free (&state->folder);
+ p_delete(&state->folder);
#endif
- mem_free (&state->entry);
+ p_delete(&state->entry);
}
static int browser_compare_subject (const void *a, const void *b)
(state->entry)[state->entrylen].mtime = s->st_mtime;
(state->entry)[state->entrylen].size = s->st_size;
- (state->entry)[state->entrylen].st = mem_malloc (sizeof (struct stat));
+ (state->entry)[state->entrylen].st = p_new(struct stat, 1);
memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat));
}
if (mutt_yesorno (msg, M_NO) == M_YES) {
if (!imap_delete_mailbox (Context, mx)) {
/* free the mailbox from the browser */
- mem_free (&((state.entry)[nentry].name));
- mem_free (&((state.entry)[nentry].desc));
+ p_delete(&((state.entry)[nentry].name));
+ p_delete(&((state.entry)[nentry].desc));
/* and move all other entries up */
if (nentry + 1 < state.entrylen)
memmove (state.entry + nentry, state.entry + nentry + 1,
}
else
mutt_message _("Mailbox not deleted.");
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
}
break;
#endif
strfcpy (buf, NONULL (Mask.pattern), sizeof (buf));
if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) {
- regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t));
+ regex_t *rx = p_new(regex_t, 1);
char *s = buf;
int not = 0, err;
if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
regerror (err, rx, buf, sizeof (buf));
regfree (rx);
- mem_free (&rx);
+ p_delete(&rx);
mutt_error ("%s", buf);
}
else {
str_replace (&Mask.pattern, buf);
regfree (Mask.rx);
- mem_free (&Mask.rx);
+ p_delete(&Mask.rx);
Mask.rx = rx;
Mask.not = not;
folder.ff->st = NULL;
folder.ff->is_new = nd->new;
folder.ff->nd = nd;
- mem_free (&f->desc);
+ p_delete(&f->desc);
mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
newsgroup_format_str, (unsigned long) &folder,
M_FORMAT_ARROWCURSOR);
case OP_SUBSCRIBE_PATTERN:
case OP_UNSUBSCRIBE_PATTERN:
if (option (OPTNEWS)) {
- regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t));
+ regex_t *rx = p_new(regex_t, 1);
char *s = buf;
int j = menu->current;
NNTP_DATA *nd;
else
snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) {
- mem_free (&rx);
+ p_delete(&rx);
break;
}
if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
regerror (err, rx, buf, sizeof (buf));
regfree (rx);
- mem_free (&rx);
+ p_delete(&rx);
mutt_error ("%s", buf);
break;
}
folder.f = NULL;
folder.new = nd->new;
folder.nd = nd;
- mem_free (&f->desc);
+ p_delete(&f->desc);
mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
newsgroup_format_str, (unsigned long) &folder,
M_FORMAT_ARROWCURSOR);
nntp_clear_cacheindex (news);
if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE)
regfree (rx);
- mem_free (&rx);
+ p_delete(&rx);
}
#ifdef USE_IMAP
else
#include <string.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+
#include "buffer.h"
#include "lib/mem.h"
* Disregards the 'destroy' flag, which seems reserved for caller.
* This is bad, but there's no apparent protocol for it.
*/
-BUFFER *mutt_buffer_init (BUFFER * b)
+BUFFER *mutt_buffer_init(BUFFER *b)
{
if (!b) {
- b = mem_malloc (sizeof (BUFFER));
+ b = p_new(BUFFER, 1);
if (!b)
return NULL;
}
else {
- mem_free(&b->data);
+ p_delete(&b->data);
}
memset (b, 0, sizeof (BUFFER));
return b;
if (!p || !*p)
return;
- mem_free (&(*p)->data);
+ p_delete(&(*p)->data);
/* dptr is just an offset to data and shouldn't be freed */
- mem_free (p);
+ p_delete(p);
}
/* dynamically grows a BUFFER to accomodate s, in increments of 128 bytes.
cmd = str_substrdup (tok->dptr, pc);
if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {
debug_print (1, ("unable to fork command: %s\n", cmd));
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
- mem_free (&cmd);
+ p_delete(&cmd);
tok->dptr = pc + 1;
* the token */
if (expn.data && qc) {
mutt_buffer_addstr (dest, expn.data);
- mem_free (&expn.data);
+ p_delete(&expn.data);
}
else if (expn.data) {
expnlen = str_len (expn.data);
tok->dsize = expnlen + str_len (tok->dptr) + 1;
- ptr = mem_malloc (tok->dsize);
+ ptr = xmalloc(tok->dsize);
memcpy (ptr, expn.data, expnlen);
strcpy (ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */
if (tok->destroy)
- mem_free (&tok->data);
+ p_delete(&tok->data);
tok->data = ptr;
tok->dptr = ptr;
tok->destroy = 1; /* mark that the caller should destroy this data */
ptr = NULL;
- mem_free (&expn.data);
+ p_delete(&expn.data);
}
}
else if (ch == '$' && (!qc || qc == '"')
(mutt_option_value (var, tmp, sizeof (tmp)) && (env = tmp)))
mutt_buffer_addstr (dest, env);
}
- mem_free (&var);
+ p_delete(&var);
}
else
mutt_buffer_addch (dest, ch);
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffy.h"
#include "buffer.h"
/* func to free buffy for list_del() */
static void buffy_free (BUFFY** p) {
- mem_free(&(*p)->path);
- mem_free(p);
+ p_delete(&(*p)->path);
+ p_delete(p);
}
int buffy_lookup (const char* path) {
#include <unistd.h>
#include <errno.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "charset.h"
#include "ascii.h"
len = str_len (s);
ib = s, ibl = len + 1;
obl = MB_LEN_MAX * ibl;
- ob = buf = mem_malloc (obl + 1);
+ ob = buf = xmalloc(obl + 1);
mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
iconv_close (cd);
*ob = '\0';
- mem_free (ps);
+ p_delete(ps);
*ps = buf;
str_adjust (ps);
cd = mutt_iconv_open (to, from, flags);
if (cd != (iconv_t) - 1) {
- fc = mem_malloc (sizeof (struct fgetconv_s));
+ fc = p_new(struct fgetconv_s, 1);
fc->p = fc->ob = fc->bufo;
fc->ib = fc->bufi;
fc->ibl = 0;
fc->inrepls = mutt_is_utf8 (to) ? repls : repls + 1;
}
else
- fc = mem_malloc (sizeof (struct fgetconv_not));
+ fc = p_new(struct fgetconv_not, 1);
fc->file = file;
fc->cd = cd;
return (FGETCONV *) fc;
if (fc->cd != (iconv_t) - 1)
iconv_close (fc->cd);
- mem_free (_fc);
+ p_delete(_fc);
}
const char *mutt_get_first_charset (const char *charset)
if (cd == (iconv_t) (-1))
return (size_t) (-1);
obl = 4 * flen + 1;
- ob = buf = mem_malloc (obl);
+ ob = buf = xmalloc(obl);
n = my_iconv(cd, &f, &flen, &ob, &obl);
if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
e = errno;
- mem_free (&buf);
+ p_delete(&buf);
iconv_close (cd);
errno = e;
return (size_t) (-1);
n = c1 ? c1 - c : str_len (c);
if (!n)
continue;
- fromcode = mem_malloc (n + 1);
- strfcpy (fromcode, c, n + 1);
+ fromcode = p_dupstr(c, n);
m = convert_string (u, ulen, fromcode, Charset, &s, &slen);
- mem_free (&fromcode);
+ p_delete(&fromcode);
if (m != (size_t) (-1)) {
- mem_free (ps);
+ p_delete(ps);
*ps = s;
return 0;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffer.h"
#include "ascii.h"
regfree (&tmp->rx);
mutt_pattern_free (&tmp->color_pattern);
- mem_free (&tmp->pattern);
- mem_free (l);
+ p_delete(&tmp->pattern);
+ p_delete(l);
}
void ci_start_color (void)
{
memset (ColorDefs, A_NORMAL, sizeof (int) * MT_COLOR_MAX);
- ColorQuote = (int *) mem_malloc (COLOR_QUOTE_INIT * sizeof (int));
+ ColorQuote = p_new(int, COLOR_QUOTE_INIT);
memset (ColorQuote, A_NORMAL, sizeof (int) * COLOR_QUOTE_INIT);
ColorQuoteSize = COLOR_QUOTE_INIT;
ColorQuoteUsed = 0;
i++;
}
- p = (COLOR_LIST *) mem_malloc (sizeof (COLOR_LIST));
+ p = p_new(COLOR_LIST, 1);
p->next = ColorList;
ColorList = p;
if (p == ColorList) {
ColorList = ColorList->next;
- mem_free (&p);
+ p_delete(&p);
return;
}
q = ColorList;
while (q) {
if (q->next == p) {
q->next = p->next;
- mem_free (&p);
+ p_delete(&p);
return;
}
q = q->next;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "recvattach.h"
if (mutt_addrlist_to_idna (adr, &err) < 0) {
mutt_error (_("Bad IDN: '%s'"), err);
- mem_free (&err);
+ p_delete(&err);
rfc822_free_address (&adr);
return;
}
err.dsize = sizeof (errbuf);
memset (&token, 0, sizeof (token));
r = mutt_parse_rc_line (buffer, &token, &err);
- mem_free (&token.data);
+ p_delete(&token.data);
if (errbuf[0]) {
/* since errbuf could potentially contain printf() sequences in it,
we must call mutt_error() in this fashion so that vsprintf()
/* clean up previous junk */
mutt_free_parameter (&b->parameter);
- mem_free (&b->subtype);
+ p_delete(&b->subtype);
mutt_parse_content_type (buf, b);
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "mutt_curses.h"
if (mutt_addrlist_to_idna (*addr, &err) != 0) {
mutt_error (_("Warning: '%s' is a bad IDN."), err);
mutt_refresh ();
- mem_free (&err);
+ p_delete(&err);
}
/* redraw the expanded list so the user can see the result */
idx[x]->content->next = NULL;
idx[x]->content->parts = NULL;
mutt_free_body (&(idx[x]->content));
- mem_free (&idx[x]->tree);
- mem_free (&idx[x]);
+ p_delete(&idx[x]->tree);
+ p_delete(&idx[x]);
for (; x < *idxlen - 1; x++)
idx[x] = idx[x + 1];
menu->max = --(*idxlen);
buf[0] = 0;
if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0
&& buf[0]) {
- mem_free (&msg->env->newsgroups);
+ p_delete(&msg->env->newsgroups);
str_skip_trailws (buf);
msg->env->newsgroups = str_dup (str_skip_initws (buf));
move (HDR_TO, HDR_XOFFSET);
strfcpy (buf, msg->env->followup_to, sizeof (buf));
if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0
&& buf[0]) {
- mem_free (&msg->env->followup_to);
+ p_delete(&msg->env->followup_to);
str_skip_trailws (buf);
msg->env->followup_to = str_dup (str_skip_initws (buf));
move (HDR_CC, HDR_XOFFSET);
strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0
&& buf[0]) {
- mem_free (&msg->env->x_comment_to);
+ p_delete(&msg->env->x_comment_to);
msg->env->x_comment_to = str_dup (buf);
move (HDR_BCC, HDR_XOFFSET);
clrtoeol ();
fcc, fcclen);
if (mutt_env_to_idna (msg->env, &tag, &err)) {
mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
- mem_free (&err);
+ p_delete(&err);
}
}
else {
/* attachments may have been added */
if (idxlen && idx[idxlen - 1]->content->next) {
for (i = 0; i < idxlen; i++)
- mem_free (&idx[i]);
+ p_delete(&idx[i]);
idxlen = 0;
idx =
mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0,
menu->redraw |= REDRAW_INDEX;
}
else
- mem_free (&idx[idxlen]);
+ p_delete(&idx[idxlen]);
menu->redraw |= REDRAW_STATUS;
else {
error = 1;
mutt_error (_("Unable to attach %s!"), att);
- mem_free (&idx[idxlen]);
+ p_delete(&idx[idxlen]);
}
}
- mem_free (&files);
+ p_delete(&files);
if (!error)
mutt_clear_error ();
if (!ctx->msgcount) {
mx_close_mailbox (ctx, NULL);
- mem_free (&ctx);
+ p_delete(&ctx);
mutt_error _("No messages in that folder.");
break;
else {
mutt_error _("Unable to attach!");
- mem_free (&idx[idxlen]);
+ p_delete(&idx[idxlen]);
}
}
}
mx_close_mailbox (Context, NULL);
else
mx_fastclose_mailbox (Context);
- mem_free (&Context);
+ p_delete(&Context);
/* go back to the folder we started from */
Context = this;
/* Touch the file */
if (!(fp = safe_fopen (fname, "w"))) {
mutt_error (_("Can't create file %s"), fname);
- mem_free (&idx[idxlen]);
+ p_delete(&idx[idxlen]);
continue;
}
fclose (fp);
if (idx[idxlen]->unowned)
idx[idxlen]->content->unlink = 0;
mutt_free_body (&idx[idxlen]->content);
- mem_free (&idx[idxlen]->tree);
- mem_free (&idx[idxlen]);
+ p_delete(&idx[idxlen]->tree);
+ p_delete(&idx[idxlen]);
}
- mem_free (&idx);
+ p_delete(&idx);
idxlen = 0;
idxmax = 0;
r = -1;
msg->content = idx[0]->content;
for (i = 0; i < idxlen; i++) {
idx[i]->content->aptr = NULL;
- mem_free (&idx[i]);
+ p_delete(&idx[i]);
}
}
else
msg->content = NULL;
- mem_free (&idx);
+ p_delete(&idx);
return (r);
}
* please see the file GPL in the top level source directory.
*/
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#ifdef USE_COMPRESSED
COMPRESS_INFO *ci;
/* Now lets uncompress this thing */
- ci = mem_malloc (sizeof (COMPRESS_INFO));
+ ci = p_new(COMPRESS_INFO, 1);
ctx->compressinfo = (void *) ci;
ci->append = find_compress_hook (M_APPENDHOOK, ctx->path);
ci->open = find_compress_hook (M_OPENHOOK, ctx->path);
/* Uncompress to /tmp */
mutt_mktemp (tmppath);
- ctx->path = mem_malloc (str_len (tmppath) + 1);
- strcpy (ctx->path, tmppath);
+ ctx->path = p_dupstr(tmppath, str_len(tmppath));
}
static int get_size (const char *path)
COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
if (ci->size != get_size (ctx->realpath)) {
- mem_free (&ctx->compressinfo);
- mem_free (&ctx->realpath);
+ p_delete(&ctx->compressinfo);
+ p_delete(&ctx->realpath);
mutt_error _("Mailbox was corrupted!");
return (-1);
if (!ci->open) {
ctx->magic = 0;
- mem_free (ctx->compressinfo);
+ p_delete(&ctx->compressinfo);
return (-1);
}
if (!ci->close || access (ctx->path, W_OK) != 0)
if ((fp = fopen (ctx->realpath, "r")) == NULL) {
mutt_perror (ctx->realpath);
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
mutt_block_signals ();
mutt_unblock_signals ();
mutt_error _("Unable to lock mailbox!");
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
if (rc) {
mutt_any_key_to_continue (NULL);
ctx->magic = 0;
- mem_free (ctx->compressinfo);
+ p_delete(&ctx->compressinfo);
mutt_error (_("Error executing: %s : unable to open the mailbox!\n"),
cmd);
}
- mem_free (&cmd);
+ p_delete(&cmd);
if (rc)
return (-1);
void restore_path (CONTEXT * ctx)
{
- mem_free (&ctx->path);
+ p_delete(&ctx->path);
ctx->path = ctx->realpath;
}
return (mutt_open_read_compressed (ctx));
ctx->magic = 0;
- mem_free (&ctx->compressinfo);
+ p_delete(&ctx->compressinfo);
return (-1);
}
remove_file (ctx);
restore_path (ctx);
- mem_free (&ctx->compressinfo);
+ p_delete(&ctx->compressinfo);
}
}
if ((fp = fopen (ctx->realpath, "a")) == NULL) {
mutt_perror (ctx->realpath);
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
mutt_block_signals ();
store_size (ctx);
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
mutt_unblock_signals ();
fclose (fp);
- mem_free (&cmd);
+ p_delete(&cmd);
store_size (ctx);
if ((fp = fopen (ctx->realpath, "a")) == NULL) {
mutt_perror (ctx->realpath);
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
mutt_block_signals ();
mutt_unblock_signals ();
mutt_error _("Unable to lock mailbox!");
- mem_free (&cmd);
+ p_delete(&cmd);
return (-1);
}
mutt_error (_
(" %s: Error compressing mailbox! Uncompressed one kept!\n"),
ctx->path);
- mem_free (&cmd);
+ p_delete(&cmd);
mbox_unlock_compressed (ctx, fp);
mutt_unblock_signals ();
fclose (fp);
fclose (fp);
remove_file (ctx);
restore_path (ctx);
- mem_free (&cmd);
- mem_free (&ctx->compressinfo);
+ p_delete(&cmd);
+ p_delete(&ctx->compressinfo);
return (0);
}
AC_OUTPUT(Makefile intl/Makefile m4/Makefile
po/Makefile.in doc/Makefile contrib/Makefile
muttbug.sh
+ lib-lib/Makefile
lib/Makefile
imap/Makefile
pop/Makefile
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "handler.h"
mem_realloc (&headers[x], str_len (headers[x]) +
str_len (this_one) + sizeof (char));
strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
- mem_free (&this_one);
+ p_delete(&this_one);
}
this_one = NULL;
mem_realloc (&headers[x], str_len (headers[x]) +
str_len (this_one) + sizeof (char));
strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
- mem_free (&this_one);
+ p_delete(&this_one);
}
this_one = NULL;
/* Free in a separate loop to be sure that all headers are freed
* in case of error. */
for (x = 0; x < hdr_count; x++)
- mem_free (&headers[x]);
- mem_free (&headers);
+ p_delete(&headers[x]);
+ p_delete(&headers);
if (error)
return (-1);
/* Mutt stores references in reverse order, thus we create
* a reordered refs list that we can put in the headers */
for (; listp; listp = listp->next, refs = t) {
- t = (LIST *) mem_malloc (sizeof (LIST));
+ t = p_new(LIST, 1);
t->data = listp->data;
t->next = refs;
}
/* clearing refs from memory */
for (t = refs; refs; refs = t->next, t = refs)
- mem_free (&refs);
+ p_delete(&refs);
if (fputc ('\n', out) == EOF)
return (-1);
rfc822_free_address (&a);
- mem_free (&s);
+ p_delete(&s);
return 1;
}
#ifdef CRYPT_BACKEND_GPGME
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_crypt.h"
#include "mutt_menu.h"
{
char *tstr;
- tstr = mem_malloc (len + 1);
- memcpy (tstr, buf, len);
- tstr[len] = 0;
+ tstr = p_dupstr(buf, len);
mutt_convert_string (&tstr, "utf-8", Charset, M_ICONV_HOOK_FROM);
fputs (tstr, fp);
- mem_free (&tstr);
+ p_delete(&tstr);
}
while (*keylist) {
crypt_key_t *k = (*keylist)->next;
- mem_free (&k);
+ p_delete(&k);
*keylist = k;
}
}
else {
mutt_error (_("error adding recipient `%s': %s\n"),
buf, gpgme_strerror (err));
- mem_free (&rset);
+ p_delete(&rset);
return NULL;
}
}
convert_to_7bit (a);
plaintext = body_to_data_object (a, 0);
if (!plaintext) {
- mem_free (&rset);
+ p_delete(&rset);
return NULL;
}
outfile = encrypt_gpgme_object (plaintext, rset, 0, sign);
gpgme_data_release (plaintext);
- mem_free (&rset);
+ p_delete(&rset);
if (!outfile)
return NULL;
plaintext = body_to_data_object (a, 0);
if (!plaintext) {
- mem_free (&rset);
+ p_delete(&rset);
return NULL;
}
outfile = encrypt_gpgme_object (plaintext, rset, 1, 0);
gpgme_data_release (plaintext);
- mem_free (&rset);
+ p_delete(&rset);
if (!outfile)
return NULL;
return;
is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
- buf = mem_malloc (str_len (prefix) + str_len (s) * 4 + 2);
+ buf = xmalloc(str_len (prefix) + str_len (s) * 4 + 2);
strcpy (buf, prefix); /* __STRCPY_CHECKED__ */
p = buf + str_len (buf);
if (is_pgp && str_len (s) == 40) { /* PGP v4 style formatted. */
*p++ = '\n';
*p = 0;
state_attach_puts (buf, state);
- mem_free (&buf);
+ p_delete(&buf);
}
/* Show the valididy of a key used for one signature. */
if (!fname)
return;
unlink (fname);
- mem_free (&fname);
+ p_delete(&fname);
fc = fgetconv_open (fp, charset, Charset, M_ICONV_HOOK_FROM);
}
else {
unlink (tmpfname);
- mem_free (&tmpfname);
+ p_delete(&tmpfname);
}
}
gpgme_release (ctx);
n = s - string;
if (!n)
return NULL; /* empty key */
- array->key = mem_malloc (n + 1);
+ array->key = p_dupstr(string, n );
p = (unsigned char *) array->key;
- memcpy (p, string, n); /* fixme: trim trailing spaces */
- p[n] = 0;
string = s + 1;
if (*string == '#') { /* hexstring */
if (!n || (n & 1))
return NULL; /* empty or odd number of digits */
n /= 2;
- p = mem_malloc (n + 1);
+ p = xmalloc(n + 1);
array->value = (char *) p;
for (s1 = string; n; s1 += 2, n--)
*p++ = xtoi_2 (s1);
n++;
}
- p = mem_malloc (n + 1);
+ p = xmalloc(n + 1);
array->value = (char *) p;
for (s = string; n; s++, n--) {
if (*s == '\\') {
int i;
arraysize = 7; /* C,ST,L,O,OU,CN,email */
- array = mem_malloc ((arraysize + 1) * sizeof *array);
+ array = p_new(struct dn_array_s, arraysize + 1);
arrayidx = 0;
while (*string) {
while (*string == ' ')
struct dn_array_s *a2;
arraysize += 5;
- a2 = mem_malloc ((arraysize + 1) * sizeof *array);
+ a2 = p_new(struct dn_array_s, arraysize + 1);
for (i = 0; i < arrayidx; i++) {
a2[i].key = array[i].key;
a2[i].value = array[i].value;
}
- mem_free (&array);
+ p_delete(&array);
array = a2;
}
array[arrayidx].key = NULL;
failure:
for (i = 0; i < arrayidx; i++) {
- mem_free (&array[i].key);
- mem_free (&array[i].value);
+ p_delete(&array[i].key);
+ p_delete(&array[i].value);
}
- mem_free (&array);
+ p_delete(&array);
return NULL;
}
else {
print_dn_parts (fp, dn);
for (i = 0; dn[i].key; i++) {
- mem_free (&dn[i].key);
- mem_free (&dn[i].value);
+ p_delete(&dn[i].key);
+ p_delete(&dn[i].value);
}
- mem_free (&dn);
+ p_delete(&dn);
}
}
}
err = gpgme_new (&ctx);
if (err) {
mutt_error (_("gpgme_new failed: %s"), gpgme_strerror (err));
- mem_free (&pattern);
+ p_delete(&pattern);
return NULL;
}
patarr[n] = NULL;
err = gpgme_op_keylist_ext_start (ctx, (const char **) patarr, secret, 0);
for (n = 0; patarr[n]; n++)
- mem_free (&patarr[n]);
- mem_free (&patarr);
+ p_delete(&patarr[n]);
+ p_delete(&patarr);
if (err) {
mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err));
gpgme_release (ctx);
- mem_free (&pattern);
+ p_delete(&pattern);
return NULL;
}
if (err) {
mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err));
gpgme_release (ctx);
- mem_free (&pattern);
+ p_delete(&pattern);
return NULL;
}
}
gpgme_release (ctx);
- mem_free (&pattern);
+ p_delete(&pattern);
return db;
}
hints = mutt_add_list (hints, t);
}
- mem_free (&scratch);
+ p_delete(&scratch);
return hints;
}
}
mutt_menuDestroy (&menu);
- mem_free (&key_table);
+ p_delete(&key_table);
set_option (OPTNEEDREDRAW);
if (l)
str_replace (&l->dflt, resp);
else {
- l = mem_malloc (sizeof (struct crypt_cache));
+ l = p_new(struct crypt_cache, 1);
l->next = id_defaults;
id_defaults = l;
l->what = str_dup (whatfor);
}
}
else if (r == -1) {
- mem_free (&keylist);
+ p_delete(&keylist);
rfc822_free_address (&tmp);
rfc822_free_address (&addr);
return NULL;
app,
#endif
&forced_valid)) == NULL) {
- mem_free (&keylist);
+ p_delete(&keylist);
rfc822_free_address (&tmp);
rfc822_free_address (&addr);
return NULL;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "crypt-mod.h"
#include "lib/mem.h"
/* Register a new crypto module. */
void crypto_module_register (crypt_module_specs_t specs)
{
- crypt_module_t module_new = mem_malloc (sizeof (*module_new));
+ crypt_module_t module_new = p_new(struct crypt_module, 1);
module_new->specs = specs;
module_new->next = modules;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "handler.h"
state_attach_puts (_("[-- The following data is signed --]\n\n"), s);
- mem_free (&signatures);
+ p_delete(&signatures);
}
else
state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"),
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "mutt_menu.h"
* ensure there is enough room for the answer and truncate the question
* to fit.
*/
- answer_string = mem_malloc (COLS + 1);
+ answer_string = p_new(char, COLS + 1);
snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no,
def == M_YES ? no : yes);
answer_string_len = str_len (answer_string);
printw ("%.*s%s", COLS - answer_string_len, msg, answer_string);
- mem_free (&answer_string);
+ p_delete(&answer_string);
FOREVER {
mutt_refresh ();
*redraw = REDRAW_FULL;
}
else {
- char *pc = mem_malloc (str_len (prompt) + 3);
+ char *pc = p_new(char, str_len(prompt) + 3);
sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */
mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
!= 0)
buf[0] = 0;
MAYBE_REDRAW (*redraw);
- mem_free (&pc);
+ p_delete(&pc);
}
return 0;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "mx.h"
/* save the list of new messages */
if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
- save_new =
- (HEADER **) mem_malloc (sizeof (HEADER *) *
- (Context->msgcount - oldcount));
+ save_new = p_new(HEADER*, Context->msgcount - oldcount);
for (j = oldcount; j < Context->msgcount; j++)
save_new[j - oldcount] = Context->hdrs[j];
}
mutt_uncollapse_thread (Context, h);
}
}
- mem_free (&save_new);
+ p_delete(&save_new);
mutt_set_virtual (Context);
}
}
if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
if (!Context->path) {
/* fatal error occurred */
- mem_free (&Context);
+ p_delete(&Context);
menu->redraw = REDRAW_FULL;
}
set_option (OPTSEARCHINVALID);
snprintf (buf, sizeof (buf), "~A");
unset_option (OPTHIDEREAD);
}
- mem_free (&Context->pattern);
+ p_delete(&Context->pattern);
Context->pattern = str_dup (buf);
}
if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
/* check for a fatal error, or all messages deleted */
if (!Context->path)
- mem_free (&Context);
+ p_delete(&Context);
/* if we were in the pager, redisplay the message */
if (menu->menu == MENU_PAGER) {
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
break;
}
- mem_free (&Context);
+ p_delete(&Context);
}
mutt_sleep (0);
{
if (Context) {
mx_fastclose_mailbox (Context);
- mem_free (&Context);
+ p_delete(&Context);
}
done = 1;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "enter.h"
static void be_free_memory (char **buf, int buflen)
{
while (buflen-- > 0)
- mem_free (&buf[buflen]);
+ p_delete(&buf[buflen]);
if (buf)
- mem_free (&buf);
+ p_delete(&buf);
}
static char **be_include_messages (char *msg, char **buf, int *bufmax,
buflen--;
strfcpy (tmp, buf[buflen], sizeof (tmp));
tmp[str_len (tmp) - 1] = 0;
- mem_free (&buf[buflen]);
+ p_delete(&buf[buflen]);
buf[buflen] = NULL;
continue;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "mutt_menu.h"
memcpy (state->wbuf + state->curpos, savebuf, savelen * sizeof (wchar_t));
state->lastchar = state->curpos + savelen;
- mem_free (&savebuf);
+ p_delete(&savebuf);
}
/*
bye:
- mem_free (&tempbuf);
+ p_delete(&tempbuf);
return rv;
}
if (!esp)
return;
- mem_free (&(*esp)->wbuf);
- mem_free (esp);
+ p_delete(&(*esp)->wbuf);
+ p_delete(esp);
}
/*
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "lib/mem.h"
#include <time.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "pgp.h"
#include "charset.h"
char *ob;
size_t ibl, obl;
- buf = mem_malloc (n + 1);
+ buf = p_new(char, n + 1);
ib = uid, ibl = d - uid + 1, ob = buf, obl = n;
my_iconv(cd, &ib, &ibl, &ob, &obl);
if (!ibl) {
else if (ob - buf == n && (buf[n] = 0, str_len (buf) < n))
memcpy (uid, buf, n);
}
- mem_free (&buf);
+ p_delete(&buf);
iconv_close (cd);
}
}
#include <sys/wait.h>
#include <sys/stat.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "recvattach.h"
state_putc ('\n', s); /* add a final newline */
- mem_free (&(stte.buffer));
- mem_free (&(stte.line));
- mem_free (&(stte.param));
+ p_delete(&(stte.buffer));
+ p_delete(&(stte.line));
+ p_delete(&(stte.param));
return (0);
}
mutt_sanitize_filename (fname, 1);
rfc1524_expand_filename (entry->nametemplate, fname, tempfile,
sizeof (tempfile));
- mem_free (&fname);
+ p_delete(&fname);
if (entry->command) {
strfcpy (command, entry->command, sizeof (command));
#include <stdio.h>
#include <string.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "lib/mem.h"
HASH *hash_create (int nelem)
{
- HASH *table = mem_malloc (sizeof (HASH));
+ HASH *table = p_new(HASH, 1);
if (nelem == 0)
nelem = 2;
return table;
}
-HASH *hash_resize (HASH * ptr, int nelem)
+HASH *hash_resize(HASH *ptr, int nelem)
{
HASH *table;
struct hash_elem *elem, *tmp;
tmp = elem;
elem = elem->next;
hash_insert (table, tmp->key, tmp->data, 1);
- mem_free (&tmp);
+ p_delete(&tmp);
}
}
- mem_free (&ptr->table);
- mem_free (&ptr);
+ p_delete(&ptr->table);
+ p_delete(&ptr);
return table;
}
struct hash_elem *ptr;
int h;
- ptr = (struct hash_elem *) mem_malloc (sizeof (struct hash_elem));
+ ptr = p_new(struct hash_elem, 1);
h = hash_string ((unsigned char *) key, table->nelem);
ptr->key = key;
ptr->data = data;
for (tmp = table->table[h], last = NULL; tmp; last = tmp, tmp = tmp->next) {
r = str_cmp (tmp->key, key);
if (r == 0) {
- mem_free (&ptr);
+ p_delete(&ptr);
return (-1);
}
if (r > 0)
*last = ptr->next;
if (destroy)
destroy (ptr->data);
- mem_free (&ptr);
+ p_delete(&ptr);
ptr = *last;
} else {
elem = elem->next;
if (destroy)
destroy (tmp->data);
- mem_free (&tmp);
+ p_delete(&tmp);
}
}
- mem_free (&pptr->table);
- mem_free (ptr);
+ p_delete(&pptr->table);
+ p_delete(ptr);
}
void hash_map (HASH* table, void (*mapfunc) (const char* key, void* data,
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#ifdef USE_IMAP
#include "message.h"
siz = 4096;
}
- return mem_malloc (siz);
+ return xmalloc(siz);
}
static void lazy_realloc (void *ptr, size_t siz)
return;
}
- *c = mem_malloc (size);
- memcpy (*c, d + *off, size);
+ *c = p_dup(d + *off, size);
*off += size;
}
restore_int (&counter, d, off);
while (counter) {
- *a = mem_malloc (sizeof (ADDRESS));
+ *a = p_new(ADDRESS, 1);
restore_char (&(*a)->personal, d, off);
restore_char (&(*a)->mailbox, d, off);
restore_int ((unsigned int *) &(*a)->group, d, off);
restore_int (&counter, d, off);
while (counter) {
- *l = mem_malloc (sizeof (LIST));
+ *l = p_new(LIST, 1);
restore_char (&(*l)->data, d, off);
l = &(*l)->next;
counter--;
return;
}
- *b = mem_malloc (sizeof (BUFFER));
+ *b = p_new(BUFFER, 1);
restore_char (&(*b)->data, d, off);
restore_int (&offset, d, off);
restore_int (&counter, d, off);
while (counter) {
- *p = mem_malloc (sizeof (PARAMETER));
+ *p = p_new(PARAMETER, 1);
restore_char (&(*p)->attribute, d, off);
restore_char (&(*p)->value, d, off);
p = &(*p)->next;
if (!path || path[0] == '\0')
{
- mem_free(&h->folder);
- mem_free(&h);
+ p_delete(&h->folder);
+ p_delete(&h);
return NULL;
}
return h;
else
{
- mem_free(&h->folder);
- mem_free(&h);
+ p_delete(&h->folder);
+ p_delete(&h);
return NULL;
}
return;
vlclose(h->db);
- mem_free(&h->folder);
- mem_free(&h);
+ p_delete(&h->folder);
+ p_delete(&h);
}
void *
if (! crc32_matches(data, h->crc))
{
- mem_free(&data);
+ p_delete(&data);
return NULL;
}
ret = vlput(h->db, path, ksize, data, dsize, VL_DOVER);
- mem_free(&data);
+ p_delete(&data);
return ret;
}
h->crc = generate_crc32 ();
if (!path || path[0] == '\0') {
- mem_free (&h->folder);
- mem_free (&h);
+ p_delete(&h->folder);
+ p_delete(&h);
return NULL;
}
return h;
}
else {
- mem_free (&h->folder);
- mem_free (&h);
+ p_delete(&h->folder);
+ p_delete(&h);
return NULL;
}
}
gdbm_close (h->db);
- mem_free (&h->folder);
- mem_free (&h);
+ p_delete(&h->folder);
+ p_delete(&h);
}
void *mutt_hcache_fetch (void *db, const char *filename,
data = gdbm_fetch (h->db, key);
if (!crc32_matches (data.dptr, h->crc)) {
- mem_free(&data.dptr);
+ p_delete(&data.dptr);
return NULL;
}
ret = gdbm_store (h->db, key, data, GDBM_REPLACE);
- mem_free (&data.dptr);
+ p_delete(&data.dptr);
return ret;
}
h->crc = generate_crc32 ();
if (!path || path[0] == '\0') {
- mem_free (&h);
+ p_delete(&h);
return NULL;
}
h->fd = open (h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (h->fd < 0) {
- mem_free (&h);
+ p_delete(&h);
return NULL;
}
if (mx_lock_file (h->lockfile, h->fd, 1, 0, 5)) {
close (h->fd);
- mem_free (&h);
+ p_delete(&h);
return NULL;
}
if (ret) {
mx_unlock_file (h->lockfile, h->fd, 0);
close (h->fd);
- mem_free (&h);
+ p_delete(&h);
return NULL;
}
h->env->close (h->env, 0);
mx_unlock_file (h->lockfile, h->fd, 0);
close (h->fd);
- mem_free (&h);
+ p_delete(&h);
return NULL;
}
}
h->env->close (h->env, 0);
mx_unlock_file (h->lockfile, h->fd, 0);
close (h->fd);
- mem_free (&h);
+ p_delete(&h);
return NULL;
}
h->env->close (h->env, 0);
mx_unlock_file (h->lockfile, h->fd, 0);
close (h->fd);
- mem_free (&h);
+ p_delete(&h);
}
void *mutt_hcache_fetch (void *db, const char *filename,
h->db->get (h->db, NULL, &key, &data, 0);
if (!crc32_matches (data.data, h->crc)) {
- mem_free(&data.data);
+ p_delete(&data.data);
return NULL;
}
ret = h->db->put (h->db, NULL, &key, &data, 0);
- mem_free (&data.data);
+ p_delete(&data.data);
return ret;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "history.h"
#include "lib/mem.h"
if (OldSize) {
if (h->hist) {
for (i = 0; i < OldSize; i++)
- mem_free (&h->hist[i]);
- mem_free (&h->hist);
+ p_delete(&h->hist[i]);
+ p_delete(&h->hist);
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffer.h"
#include "mx.h"
if (data & (M_FOLDERHOOK | M_MBOXHOOK)) {
strfcpy (path, pattern.data, sizeof (path));
_mutt_expand_path (path, sizeof (path), 1);
- mem_free (&pattern.data);
+ p_delete(&pattern.data);
memset (&pattern, 0, sizeof (pattern));
pattern.data = str_dup (path);
}
strfcpy (tmp, pattern.data, sizeof (tmp));
mutt_check_simple (tmp, sizeof (tmp), DefaultHook);
- mem_free (&pattern.data);
+ p_delete(&pattern.data);
memset (&pattern, 0, sizeof (pattern));
pattern.data = str_dup (tmp);
}
if (data & (M_MBOXHOOK | M_SAVEHOOK | M_FCCHOOK)) {
strfcpy (path, command.data, sizeof (path));
mutt_expand_path (path, sizeof (path));
- mem_free (&command.data);
+ p_delete(&command.data);
memset (&command, 0, sizeof (command));
command.data = str_dup (path);
}
* pattern, so if we've already seen this pattern/command pair, just
* ignore it instead of creating a duplicate */
if (!str_cmp (ptr->command, command.data)) {
- mem_free (&command.data);
- mem_free (&pattern.data);
+ p_delete(&command.data);
+ p_delete(&pattern.data);
return 0;
}
}
* order of execution of the hooks, which i think is desirable since
* a common action to perform is to change the default (.) entry
* based upon some other information. */
- mem_free (&ptr->command);
+ p_delete(&ptr->command);
ptr->command = command.data;
- mem_free (&pattern.data);
+ p_delete(&pattern.data);
return 0;
}
}
goto error;
}
else {
- rx = mem_malloc (sizeof (regex_t));
+ rx = p_new(regex_t, 1);
#ifdef M_CRYPTHOOK
if ((rc =
REGCOMP (rx, NONULL (pattern.data),
{
regerror (rc, rx, err->data, err->dsize);
regfree (rx);
- mem_free (&rx);
+ p_delete(&rx);
goto error;
}
}
return 0;
error:
- mem_free (&pattern.data);
- mem_free (&command.data);
+ p_delete(&pattern.data);
+ p_delete(&command.data);
return (-1);
}
static void delete_hook (HOOK * h)
{
- mem_free (&h->command);
- mem_free (&h->rx.pattern);
+ p_delete(&h->command);
+ p_delete(&h->rx.pattern);
if (h->rx.rx) {
regfree (h->rx.rx);
}
mutt_pattern_free (&h->pattern);
- mem_free (&h);
+ p_delete(&h);
}
/* Deletes all hooks of type ``type'', or all defined hooks if ``type'' is 0 */
mutt_error ("%s", err.data);
mutt_sleep (1); /* pause a moment to let the user see the error */
if (ERROR_STOP) {
- mem_free (&token.data);
+ p_delete(&token.data);
current_hook_type = 0;
return;
}
}
}
}
- mem_free (&token.data);
+ p_delete(&token.data);
current_hook_type = 0;
}
mutt_error ("%s", err.data);
mutt_sleep (1);
if (ERROR_STOP) {
- mem_free (&token.data);
+ p_delete(&token.data);
current_hook_type = 0;
return;
}
}
}
- mem_free (&token.data);
+ p_delete(&token.data);
current_hook_type = 0;
}
mutt_error ("%s", err.data);
mutt_sleep (1);
if (ERROR_STOP) {
- mem_free (&token.data);
+ p_delete(&token.data);
current_hook_type = 0;
return;
}
}
}
- mem_free (&token.data);
+ p_delete(&token.data);
}
#endif
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/debug.h"
!ascii_strcasecmp (authenticator->method, method))
if ((r = authenticator->authenticate (idata, method)) !=
IMAP_AUTH_UNAVAIL) {
- mem_free (&methods);
+ p_delete(&methods);
return r;
}
}
}
- mem_free (&methods);
+ p_delete(&methods);
}
else {
/* Fall back to default: any authenticator */
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mutt_sasl.h"
#include <stdlib.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+
#include "lib/mem.h"
#include "lib/str.h"
#include "lib/intl.h"
if (save_lsub)
set_option (OPTIMAPCHECKSUBSCRIBED);
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
fail:
if (save_lsub)
set_option (OPTIMAPCHECKSUBSCRIBED);
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
mutt_sleep (0);
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
fail:
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
mutt_message (_("Mailbox renamed."));
mutt_sleep (0);
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
fail:
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
do {
if (imap_parse_list_response (idata, &name, &noselect, &noinferiors,
&idata->delim) != 0) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
}
while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0));
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
}
* than at scan, since it's so expensive to scan. But that's big changes
* to browser.c */
if (!((regexec (Mask.rx, relpath, 0, NULL, 0) == 0) ^ Mask.not)) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return;
}
(state->entry)[state->entrylen].inferiors = !noinferiors;
(state->entrylen)++;
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
}
static int compare_names (struct folder_file *a, struct folder_file *b)
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/debug.h"
cmd_make_sequence (idata);
/* seq, space, cmd, \r\n\0 */
outlen = str_len (idata->cmd.seq) + str_len (cmd) + 4;
- out = (char *) mem_malloc (outlen);
+ out = p_new(char, outlen);
snprintf (out, outlen, "%s %s\r\n", idata->cmd.seq, cmd);
rc = mutt_socket_write (idata->conn, out);
- mem_free (&out);
+ p_delete(&out);
return (rc < 0) ? IMAP_CMD_BAD : 0;
}
cmd_make_sequence (idata);
/* seq, space, cmd, \r\n\0 */
outlen = str_len (idata->cmd.seq) + str_len (cmd) + 4;
- out = (char *) mem_malloc (outlen);
+ out = p_new(char, outlen);
snprintf (out, outlen, "%s %s\r\n", idata->cmd.seq, cmd);
rc = mutt_socket_write_d (idata->conn, out,
flags & IMAP_CMD_PASS ? IMAP_LOG_PASS :
IMAP_LOG_CMD);
- mem_free (&out);
+ p_delete(&out);
if (rc < 0) {
cmd_handle_fatal (idata);
debug_print (2, ("Handling CAPABILITY\n"));
s = imap_next_word (s);
- mem_free (&idata->capstr);
+ p_delete(&idata->capstr);
idata->capstr = str_dup (s);
memset (idata->capabilities, 0, sizeof (idata->capabilities));
err.dsize = sizeof (errstr);
if (mutt_parse_rc_line (buf, &token, &err))
debug_print (1, ("Error adding subscribed mailbox: %s\n", errstr));
- mem_free (&token.data);
+ p_delete(&token.data);
}
else
debug_print (1, ("Bad LSUB response\n"));
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "buffer.h"
if (!(idata = imap_conn_find (&mx.account,
option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW :
0))) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
/* we may already be in the folder we're checking */
if (!ascii_strcmp(idata->mailbox, mx.mbox)) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
}
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
if (mutt_bit_isset (idata->capabilities, IMAP4REV1))
if (!(idata = imap_conn_find (&mx.account,
option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW
: 0))) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
}
if (idata->cache[cacheno].uid == HEADER_DATA (h)->uid &&
idata->cache[cacheno].path) {
unlink (idata->cache[cacheno].path);
- mem_free (&idata->cache[cacheno].path);
+ p_delete(&idata->cache[cacheno].path);
}
imap_free_header_data (&h->data);
else
mutt_account_unsetpass (&idata->conn->account);
- mem_free (&idata->capstr);
+ p_delete(&idata->capstr);
}
if (new && idata->state == IMAP_AUTHENTICATED) {
imap_get_delim (idata);
idata->state = IMAP_AUTHENTICATED;
if (imap_check_capabilities (idata) != 0)
goto bail;
- mem_free (&idata->capstr);
+ p_delete(&idata->capstr);
}
else {
imap_error ("imap_open_connection()", buf);
mutt_socket_close (idata->conn);
idata->state = IMAP_DISCONNECTED;
bail:
- mem_free (&idata->capstr);
+ p_delete(&idata->capstr);
return -1;
}
/* Clean up path and replace the one in the ctx */
imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
- mem_free (&(idata->mailbox));
+ p_delete(&(idata->mailbox));
idata->mailbox = str_dup (buf);
imap_qualify_path (buf, sizeof (buf), &mx, idata->mailbox);
- mem_free (&(ctx->path));
+ p_delete(&(ctx->path));
ctx->path = str_dup (buf);
idata->ctx = ctx;
}
debug_print (2, ("msgcount is %d\n", ctx->msgcount));
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
fail:
if (idata->state == IMAP_SELECTED)
idata->state = IMAP_AUTHENTICATED;
fail_noidata:
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
* ctx is brand new and mostly empty */
if (!(idata = imap_conn_find (&(mx.account), 0))) {
- mem_free(&mx.mbox);
+ p_delete(&mx.mbox);
return (-1);
}
conn = idata->conn;
imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));
- mem_free(&mx.mbox);
+ p_delete(&mx.mbox);
/* really we should also check for W_OK */
if (!imap_access (ctx->path, F_OK))
idata->status = IMAP_BYE;
imap_cmd_start (idata, "LOGOUT");
while (imap_cmd_step (idata) == IMAP_CMD_CONTINUE);
- mem_free (&idata->cmd.buf);
- mem_free (&idata);
+ p_delete(&idata->cmd.buf);
+ p_delete(&idata);
}
/*
}
}
- mem_free (&hdrs);
+ p_delete(&hdrs);
return count;
}
rc = 0;
out:
if (cmd.data)
- mem_free (&cmd.data);
+ p_delete(&cmd.data);
if (appendctx) {
mx_fastclose_mailbox (appendctx);
- mem_free (&appendctx);
+ p_delete(&appendctx);
}
return rc;
}
}
idata->reopen &= IMAP_REOPEN_ALLOW;
- mem_free (&(idata->mailbox));
+ p_delete(&(idata->mailbox));
mutt_free_list (&idata->flags);
idata->ctx = NULL;
}
for (i = 0; i < IMAP_CACHE_LEN; i++) {
if (idata->cache[i].path) {
unlink (idata->cache[i].path);
- mem_free (&idata->cache[i].path);
+ p_delete(&idata->cache[i].path);
}
}
}
connflags = M_IMAP_CONN_NONEW;
if (!(idata = imap_conn_find (&(mx.account), connflags))) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
conn = idata->conn;
imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
imap_munge_mbox_name (mbox, sizeof (mbox), buf);
strfcpy (mbox_unquoted, buf, sizeof (mbox_unquoted));
memset (&buf, 0, sizeof (buf));
mutt_buffer_addstr (&buf, "UID SEARCH ");
if (imap_compile_search (pat, &buf) < 0) {
- mem_free (&buf.data);
+ p_delete(&buf.data);
return -1;
}
if (imap_exec (idata, buf.data, 0) < 0) {
- mem_free (&buf.data);
+ p_delete(&buf.data);
return -1;
}
- mem_free (&buf.data);
+ p_delete(&buf.data);
return 0;
}
subscribe ? "" : "un", path);
if (mutt_parse_rc_line (mbox, &token, &err))
debug_print (1, ("Error adding subscribed mailbox: %s\n", errstr));
- mem_free (&token.data);
+ p_delete(&token.data);
}
if (subscribe)
if (imap_exec (idata, buf, 0) < 0)
goto fail;
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
fail:
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
/* don't open a new socket just for completion. Instead complete over
* known mailboxes/hooks/etc */
if (!(idata = imap_conn_find (&(mx.account), M_IMAP_CONN_NONEW))) {
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
strfcpy (dest, path, dlen);
return imap_complete_hosts (dest, dlen);
}
imap_qualify_path (dest, dlen, &mx, completion);
mutt_pretty_mailbox (dest);
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
}
#include <stdlib.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "buffer.h"
rewind (fp);
- mem_free (&uid_validity);
+ p_delete(&uid_validity);
}
while ((rc != IMAP_CMD_OK) && ((mfhrc == -1) ||
return 0;
else {
unlink (cache->path);
- mem_free (&cache->path);
+ p_delete(&cache->path);
}
}
mutt_mktemp (path);
cache->path = str_dup (path);
if (!(msg->fp = safe_fopen (path, "w+"))) {
- mem_free (&cache->path);
+ p_delete(&cache->path);
return -1;
}
safe_fclose (&msg->fp);
if (cache->path) {
unlink (cache->path);
- mem_free (&cache->path);
+ p_delete(&cache->path);
}
return -1;
goto fail;
}
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return 0;
fail:
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return -1;
}
}
if (cmd.data)
- mem_free (&cmd.data);
+ p_delete(&cmd.data);
if (sync_cmd.data)
- mem_free (&sync_cmd.data);
- mem_free (&mx.mbox);
+ p_delete(&sync_cmd.data);
+ p_delete(&mx.mbox);
return 0;
fail:
if (cmd.data)
- mem_free (&cmd.data);
+ p_delete(&cmd.data);
if (sync_cmd.data)
- mem_free (&sync_cmd.data);
- mem_free (&mx.mbox);
+ p_delete(&sync_cmd.data);
+ p_delete(&mx.mbox);
return -1;
}
/* this should be safe even if the list wasn't used */
mutt_free_list (&(((IMAP_HEADER_DATA *) * data)->keywords));
- mem_free (data);
+ p_delete(data);
}
/* imap_set_flags: fill out the message header according to the flags from
debug_print (2, ("parsing FLAGS\n"));
if ((s = msg_parse_flags (&newh, s)) == NULL) {
- mem_free (&newh.data);
+ p_delete(&newh.data);
return NULL;
}
mutt_free_list (&(HEADER_DATA (h)->keywords));
HEADER_DATA (h)->keywords = newh.data->keywords;
- mem_free (&newh.data);
+ p_delete(&newh.data);
return s;
}
#include <sys/stat.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "imap_private.h"
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "charset.h"
#include "imap_private.h"
char *buf, *p;
int b, ch, k;
- p = buf = mem_malloc (u7len + u7len / 8 + 1);
+ p = buf = p_new(char, u7len + u7len / 8 + 1);
for (; u7len; u7++, u7len--) {
if (*u7 == '&') {
return buf;
bail:
- mem_free (&buf);
+ p_delete(&buf);
return 0;
}
* In the worst case we convert 2 chars to 7 chars. For example:
* "\x10&\x10&..." -> "&ABA-&-&ABA-&-...".
*/
- p = buf = mem_malloc ((u8len / 2) * 7 + 6);
+ p = buf = p_new(char, (u8len / 2) * 7 + 6);
while (u8len) {
unsigned char c = *u8;
}
if (u8len) {
- mem_free (&buf);
+ p_delete(&buf);
return 0;
}
return buf;
bail:
- mem_free (&buf);
+ p_delete(&buf);
return 0;
}
if (!mutt_convert_string (&t, Charset, "UTF-8", 0)) {
char *u7 = utf8_to_utf7 (t, strlen (t), NULL, 0);
- mem_free (s);
+ p_delete(s);
*s = u7;
}
- mem_free (&t);
+ p_delete(&t);
}
}
char *t = utf7_to_utf8 (*s, str_len (*s), 0, 0);
if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0)) {
- mem_free (s);
+ p_delete(s);
*s = t;
}
}
#include "config.h"
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mx.h" /* for M_IMAP */
#include "ascii.h"
url.path = mx.mbox;
rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD);
- mem_free (&mx.mbox);
+ p_delete(&mx.mbox);
return rc;
}
if (!(url.scheme == U_IMAP || url.scheme == U_IMAPS) ||
mutt_account_fromurl (&mx->account, &url) < 0 || !*mx->account.host) {
- mem_free (&c);
+ p_delete(&c);
return -1;
}
if (url.scheme == U_IMAPS)
mx->account.flags |= M_ACCT_SSL;
- mem_free (&c);
+ p_delete(&c);
if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
mx->account.port = ImapsPort;
if (target.mbox[hlen] == *delim)
home_match = 1;
}
- mem_free (&home.mbox);
+ p_delete(&home.mbox);
}
/* do the '=' substitution */
url_ciss_tostring (&url, path, 1024, 0);
}
- mem_free (&target.mbox);
+ p_delete(&target.mbox);
}
/* -- library functions -- */
if (!idata)
return;
- mem_free (&(*idata)->capstr);
+ p_delete(&(*idata)->capstr);
mutt_free_list (&(*idata)->flags);
- mem_free (&((*idata)->cmd.buf));
- mem_free (idata);
+ p_delete(&((*idata)->cmd.buf));
+ p_delete(idata);
}
/*
imap_quote_string (dest, dlen, buf);
- mem_free (&buf);
+ p_delete(&buf);
}
void imap_unmunge_mbox_name (char *s)
strncpy (s, buf, str_len (s));
}
- mem_free (&buf);
+ p_delete(&buf);
}
/* imap_wordcasecmp: find word a in word list b */
}
imap_check_mailbox (ctx, NULL, 1);
if (!idata->ctx)
- mem_free (&ctx);
+ p_delete(&ctx);
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffer.h"
#include "ascii.h"
/* get some $muttng_ values dynamically */
if (ascii_strcmp ("muttng_pwd", option->option) == 0) {
- val = mem_malloc (_POSIX_PATH_MAX);
+ val = p_new(char, _POSIX_PATH_MAX);
val = getcwd (val, _POSIX_PATH_MAX-1);
clean = 1;
} else if (ascii_strcmp ("muttng_folder_path", option->option) == 0 &&
snprintf (dst, dstlen, "%s=\"%s\"", option->option, NONULL (val));
if (clean)
- mem_free (&val);
+ p_delete(&val);
}
static int path_from_string (struct option_t* dst, const char* val,
return (0);
if (!val || !*val) {
- mem_free ((char**) dst->data);
+ p_delete((char**) dst->data);
return (1);
}
s++;
}
- rx = mem_malloc (sizeof(regex_t));
+ rx = p_new(regex_t, 1);
if ((e = REGCOMP (rx, s, flags)) != 0) {
regerror (e, rx, errbuf, errlen);
regfree (rx);
- mem_free (&rx);
+ p_delete(&rx);
return (0);
}
if (p->rx) {
regfree (p->rx);
- mem_free (&p->rx);
+ p_delete(&p->rx);
}
str_replace (&p->pattern, val);
*dst = '\0';
return (0);
}
- tmp = mem_malloc (dstlen+1);
+ tmp = p_new(char, dstlen+1);
FuncTable[DTYPE (option->type)].opt_to_string (tmp, dstlen, option);
/* as we get things of type $var=value and don't want to bloat the
}
}
memcpy (dst, t, l+1);
- mem_free (&tmp);
+ p_delete(&tmp);
debug_print (1, ("stripped == '%s'\n", dst));
return (1);
/* for synonym warning reports: adds synonym to end of list */
static void syn_add (struct option_t* n, struct option_t* o) {
- syn_t* tmp = mem_malloc (sizeof(syn_t));
+ syn_t* tmp = p_new(syn_t, 1);
tmp->f = str_dup (CurRCFile);
tmp->l = CurRCLine;
tmp->n = n;
/* for synonym warning reports: free single item (for list_del()) */
static void syn_del (void** p) {
- mem_free(&(*(syn_t**) p)->f);
- mem_free(p);
+ p_delete(&(*(syn_t**) p)->f);
+ p_delete(p);
}
void toggle_quadoption (int opt)
* the template, and leaving t pointed at the current item.
*/
t = last;
- mem_free(t->template);
+ p_delete(&t->template);
break;
}
if (!last->next)
if (spam->rx && !str_cmp (spam->rx->pattern, pat)) {
*list = spam->next;
rx_free (&spam->rx);
- mem_free(&spam->template);
- mem_free(&spam);
+ p_delete(&spam->template);
+ p_delete(&spam);
return 1;
}
if (!str_cmp (spam->rx->pattern, pat)) {
prev->next = spam->next;
rx_free (&spam->rx);
- mem_free(spam->template);
- mem_free(spam);
+ p_delete(&spam->template);
+ p_delete(&spam);
spam = prev->next;
++nremoved;
}
last = NULL;
while (p) {
if (ascii_strcasecmp (str, p->data) == 0) {
- mem_free (&p->data);
+ p_delete(&p->data);
if (last)
last->next = p->next;
else
(*l) = p->next;
- mem_free (&p);
+ p_delete(&p);
}
else {
last = p;
if (data == res) {
if (mutt_parse_rc_line (tmp->data, &token, err) == -1) {
mutt_error ("Error: %s", err->data);
- mem_free (&token.data);
+ p_delete(&token.data);
return (-1);
}
- mem_free (&token.data);
+ p_delete(&token.data);
}
return 0;
}
/* Add to the spam list. */
if (add_to_spam_list (&SpamList, buf->data, templ.data, err) != 0) {
- mem_free (&templ.data);
+ p_delete(&templ.data);
return -1;
}
- mem_free (&templ.data);
+ p_delete(&templ.data);
}
/* If not, try to remove from the nospam list. */
if (!buf->data || *buf->data == '\0')
continue;
- a = mem_malloc(sizeof(ATTACH_MATCH));
+ a = p_new(ATTACH_MATCH, 1);
/* some cheap hacks that I expect to remove */
if (!str_casecmp(buf->data, "any"))
}
len = str_len (a->minor);
- tmpminor = mem_malloc(len+3);
+ tmpminor = p_new(char, len + 3);
strcpy(&tmpminor[1], a->minor); /* __STRCPY_CHECKED__ */
tmpminor[0] = '^';
tmpminor[len+1] = '$';
a->major_int = mutt_check_mime_type(a->major);
regcomp(&a->minor_rx, tmpminor, REG_ICASE|REG_EXTENDED);
- mem_free (&tmpminor);
+ p_delete(&tmpminor);
debug_print (5, ("parse_attach_list: added %s/%s [%d]\n",
a->major, a->minor, a->major_int));
- listp = mem_malloc(sizeof(LIST));
+ listp = p_new(LIST, 1);
listp->data = (char *)a;
listp->next = NULL;
if (lastp) {
debug_print(5, ("parse_unattach_list: removed %s/%s [%d]\n",
a->major, a->minor, a->major_int));
regfree(&a->minor_rx);
- mem_free(&a->major);
+ p_delete(&a->major);
/* Relink backward */
if (lastp)
*ldata = lp->next;
newlp = lp->next;
- mem_free(&lp->data); /* same as a */
- mem_free(&lp);
+ p_delete(&lp->data); /* same as a */
+ p_delete(&lp);
lp = newlp;
continue;
}
}
while (MoreArgs (s));
- mem_free (&tmp);
+ p_delete(&tmp);
_attachments_clean();
return 0;
}
/* see if there is already a field by this name */
if (ascii_strncasecmp (buf->data, tmp->data, keylen) == 0) {
/* replace the old value */
- mem_free (&tmp->data);
+ p_delete(&tmp->data);
tmp->data = buf->data;
memset (buf, 0, sizeof(BUFFER));
return 0;
struct option_t* ptr = (struct option_t*) p;
char* s = (char*) ptr->data;
debug_print (1, ("removing option '%s' from table\n", NONULL (ptr->option)));
- mem_free (&ptr->option);
- mem_free (&s);
- mem_free (&ptr->init);
- mem_free (&ptr);
+ p_delete(&ptr->option);
+ p_delete(&s);
+ p_delete(&ptr->init);
+ p_delete(&ptr);
}
static int init_expand (char** dst, struct option_t* src) {
BUFFER token, in;
size_t len = 0;
- mem_free (dst);
+ p_delete(dst);
if (DTYPE(src->type) == DT_STR ||
DTYPE(src->type) == DT_PATH) {
memset (&token, 0, sizeof(BUFFER));
memset (&in, 0, sizeof(BUFFER));
len = str_len (src->init) + 2;
- in.data = mem_malloc (len+1);
+ in.data = p_new(char, len + 1);
snprintf (in.data, len, "\"%s\"", src->init);
in.dptr = in.data;
in.dsize = len;
*dst = str_dup (token.data);
else
*dst = str_dup ("");
- mem_free (&in.data);
- mem_free (&token.data);
+ p_delete(&in.data);
+ p_delete(&token.data);
} else
*dst = str_dup ("");
} else
ptr->option, NONULL (init), errbuf);
exit (1);
}
- mem_free (&init);
+ p_delete(&init);
}
if (ptr->flags & R_INDEX)
rc = 0;
break;
}
- list_del (&list, (list_del_t*) _mem_free);
+ list_del (&list, (list_del_t*)xmemfree);
return (rc);
}
hash_delete (ConfigOptions, option->option,
option, del_option);
else
- mem_free ((void *) option->data);
+ p_delete((void **)&option->data);
break;
}
}
mutt_error (_("Error in %s, line %d: %s"), rcfile, line, err->data);
if (--rc < -MAXERRS) {
if (conv)
- mem_free (¤tline);
+ p_delete(¤tline);
break;
}
}
rc = -1;
}
if (conv)
- mem_free (¤tline);
+ p_delete(¤tline);
}
- mem_free (&token.data);
- mem_free (&linebuf);
+ p_delete(&token.data);
+ p_delete(&linebuf);
fclose (f);
if (pid != -1)
mutt_wait_filter (pid);
r = 0;
finish:
if (expn.destroy)
- mem_free (&expn.data);
+ p_delete(&expn.data);
return (r);
}
snprintf (command, sizeof(command), "set ?%s\n", p->data);
if (mutt_parse_rc_line (command, &token, &err) == -1) {
fprintf (stderr, "%s\n", err.data);
- mem_free (&token.data);
+ p_delete(&token.data);
return 1;
}
printf ("%s\n", err.data);
}
- mem_free (&token.data);
+ p_delete(&token.data);
return 0;
}
for (; p; p = p->next) {
if (mutt_parse_rc_line (p->data, &token, &err) != 0) {
fprintf (stderr, _("Error in command line: %s\n"), err.data);
- mem_free (&token.data);
+ p_delete(&token.data);
return (-1);
}
}
- mem_free (&token.data);
+ p_delete(&token.data);
return 0;
}
else
#endif /* DOMAIN */
if (*DOMAIN != '@') {
- Fqdn = mem_malloc (str_len (DOMAIN) + str_len (Hostname) + 2);
+ Fqdn = p_new(char, str_len(DOMAIN) + str_len(Hostname) + 2);
sprintf (Fqdn, "%s.%s", NONULL (Hostname), DOMAIN); /* __SPRINTF_CHECKED__ */
}
else
memset (&token, 0, sizeof(token));
parse_my_hdr (&token, &buf, 0, &err);
- mem_free (&token.data);
+ p_delete(&token.data);
}
if ((p = getenv ("EMAIL")) != NULL)
}
else {
strfcpy (buffer, Muttrc, sizeof(buffer));
- mem_free (&Muttrc);
+ p_delete(&Muttrc);
mutt_expand_path (buffer, sizeof(buffer));
Muttrc = str_dup (buffer);
}
- mem_free (&AliasFile);
+ p_delete(&AliasFile);
AliasFile = str_dup (NONULL (Muttrc));
/* Process the global rc file if it exists and the user hasn't explicity
** This variable configures how often (in seconds) Mutt-ng should look for
** new mail.
*/
- {"pop_delete", DT_QUAD, R_NONE, OPT_POPDELETE, "ask-no" },
+ {"pop_delete(", DT_QUAD, R_NONE, OPT_POPDELETE, "ask-no" },
/*
** .pp
** Availability: POP
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffer.h"
#include "ascii.h"
struct keymap_t *Keymaps[MENU_MAX];
-static struct keymap_t *allocKeys (int len, keycode_t * keys)
+static struct keymap_t *allocKeys(int len, keycode_t *keys)
{
- struct keymap_t *p;
+ struct keymap_t *p;
- p = mem_calloc (1, sizeof (struct keymap_t));
- p->len = len;
- p->keys = mem_malloc (len * sizeof (keycode_t));
- memcpy (p->keys, keys, len * sizeof (keycode_t));
- return (p);
+ p = mem_calloc (1, sizeof (struct keymap_t));
+ p->len = len;
+ p->keys = p_dup(keys, len);
+ return p;
}
static int parse_fkey (char *s)
do {
len = tmp->eq;
next = tmp->next;
- mem_free (&tmp->macro);
- mem_free (&tmp->keys);
- mem_free (&tmp->descr);
- mem_free (&tmp);
+ p_delete(&tmp->macro);
+ p_delete(&tmp->keys);
+ p_delete(&tmp->descr);
+ p_delete(&tmp);
tmp = next;
}
while (tmp && len >= pos);
strfcpy (err->data, _("too few arguments"), err->dsize);
}
error:
- mem_free (&buf.data);
+ p_delete(&buf.data);
return (NULL);
}
}
}
}
- mem_free (&key);
+ p_delete(&key);
return (r);
}
}
}
- mem_free (&seq);
+ p_delete(&seq);
}
else {
for (i = 0; i < nummenus; ++i) {
}
}
}
- mem_free (&key);
+ p_delete(&key);
return (r);
}
--- /dev/null
+noinst_LIBRARIES = liblib.a
+
+liblib_a_SOURCES = mem.c
+
+noinst_HEADERS = mem.h
+
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author: Pierre Habouzit <madcoder@debian.org>
+ */
+
+#ifndef MUTT_LIB_LIB_MEM_H
+#define MUTT_LIB_LIB_MEM_H
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static inline void *xmalloc(ssize_t size) {
+ void *mem;
+
+ if (size <= 0)
+ return NULL;
+
+ mem = calloc(size, 1);
+ if (!mem)
+ abort();
+ return mem;
+}
+
+static inline void *xrealloc(void *mem, ssize_t newsize) {
+ mem = realloc(mem, newsize);
+ if (!mem)
+ abort();
+ return mem;
+}
+
+static inline void *xmemdup(const void *src, ssize_t size) {
+ return memcpy(xmalloc(size), src, size);
+}
+
+static inline void *xmemdupstr(const void *src, ssize_t len) {
+ char *res = xmalloc(len + 1);
+ memcpy(res, src, len);
+ res[len] = '\0';
+ return res;
+}
+
+#define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count)))
+#define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))
+#define p_dup(p, count) xmemdup((p), sizeof(*(p)) * (count))
+#define p_dupstr(p, len) xmemdupstr((p), (len))
+
+#ifdef __GNUC__
+
+# define p_delete(mem_pp) \
+ ({ \
+ typeof(**(mem_pp)) **__ptr = (mem_pp); \
+ free(*__ptr); \
+ *__ptr = NULL; \
+ })
+
+#else
+
+# define p_delete(mem_p) \
+ do { \
+ void *__ptr = (mem_p); \
+ free(*__ptr); \
+ *(void **)__ptr = NULL; \
+ } while (0)
+
+#endif
+
+static inline void xmemfree(void **ptr) {
+ p_delete(ptr);
+}
+
+#endif /* MUTT_LIB_LIB_MEM_H */
#define EX_OK 0
#endif
+#include <lib-lib/mem.h>
+
#include "lib.h"
#include "lib/mem.h"
* If a line ends with "\", this char and the linefeed is removed,
* and the next line is read too.
*/
-char *mutt_read_line (char *s, size_t * size, FILE * fp, int *line)
+char *mutt_read_line(char *s, size_t * size, FILE * fp, int *line)
{
size_t offset = 0;
char *ch;
if (!s) {
- s = mem_malloc (STRING);
+ s = p_new(char, STRING);
*size = STRING;
}
FOREVER {
if (fgets (s + offset, *size - offset, fp) == NULL) {
- mem_free (&s);
+ p_delete(&s);
return NULL;
}
if ((ch = strchr (s + offset, '\n')) != NULL) {
INCLUDES = -I$(top_srcdir) -I../intl
noinst_LIBRARIES = libsane.a
-noinst_HEADERS = mem.h str.h exit.h intl.h list.h rx.h debug.h
+noinst_HEADERS = str.h exit.h intl.h list.h rx.h debug.h
-libsane_a_SOURCES = mem.c exit.c str.c list.c rx.h debug.h \
- mem.h exit.h str.h list.h rx.c debug.c intl.h
+libsane_a_SOURCES = mem.h exit.c str.c list.c rx.h debug.h \
+ mem.c exit.h str.h list.h rx.c debug.c intl.h
-include ../cflags.mk
#include <stddef.h>
#include <string.h>
+#include <lib-lib/mem.h>
+
#include "list.h"
#include "mem.h"
if (del)
for (i = 0; i < (*l)->length; i++)
del (&(*l)->data[i]);
- mem_free(&(*l)->data);
- mem_free(l);
+ p_delete(&(*l)->data);
+ p_delete(l);
}
void list_push_back (list2_t** l, void* p) {
return (p);
}
-list2_t* list_cpy (list2_t* l) {
- list2_t* ret = NULL;
- if (list_empty(l))
- return (NULL);
- ret = list_new ();
- ret->length = l->length;
- ret->data = mem_malloc (l->length*sizeof(void*));
- memcpy (ret->data, l->data, l->length*sizeof(void*));
- return (ret);
+list2_t *list_cpy(list2_t *l) {
+ list2_t* ret = NULL;
+ if (list_empty(l))
+ return NULL;
+ ret = list_new();
+ ret->length = l->length;
+ ret->data = p_dup(l->data, l->length);
+ return ret;
}
list2_t* list_dup (list2_t* l, void* (*dup) (void*)) {
return (NULL);
ret = list_new ();
ret->length = l->length;
- ret->data = mem_malloc (l->length*sizeof(void*));
+ ret->data = p_new(void*, l->length);
for (i = 0; i < l->length; i++)
ret->data[i] = dup (l->data[i]);
return (ret);
for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) {
list_push_back (&ret, str_dup (p));
}
- mem_free (&tmp);
+ p_delete(&tmp);
return (ret);
}
return p;
}
-void *_mem_malloc (size_t siz, int line, const char* fname) {
- void *p;
-
- if (siz == 0)
- return 0;
- if ((p = (void *) malloc (siz)) == 0) { /* __MEM_CHECKED__ */
- exit_fatal ("mem_malloc", _("Out of memory!"), line, fname, 1);
- return (NULL);
- }
- return (p);
-}
-
void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) {
void *r;
void **p = (void **) ptr;
*p = r;
}
-
-void _mem_free (void *ptr) {
- void **p = (void **) ptr;
-
- if (*p) {
- free (*p); /* __MEM_CHECKED__ */
- *p = 0;
- }
-}
#include <sys/types.h>
-void* _mem_malloc (size_t, int, const char*);
void* _mem_calloc (size_t, size_t, int, const char*);
void _mem_realloc (void*, size_t, int, const char*);
-void _mem_free (void*);
-#define mem_malloc(s) _mem_malloc(s,__LINE__,__FILE__)
#define mem_calloc(s,c) _mem_calloc(s,c,__LINE__,__FILE__)
#define mem_realloc(p,c) _mem_realloc(p,c,__LINE__,__FILE__)
-#define mem_free(x) _mem_free(x)
#endif /* !_LIB_MEM_H */
#include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "rx.h"
#include "mem.h"
}
void rx_free (rx_t** p) {
- mem_free(&(*p)->pattern);
+ p_delete(&(*p)->pattern);
regfree ((*p)->rx);
- mem_free(&(*p)->rx);
- mem_free(p);
+ p_delete(&(*p)->rx);
+ p_delete(p);
}
int rx_compare (const rx_t* r1, const rx_t* r2) {
#include <string.h>
#include <ctype.h>
+#include <lib-lib/mem.h>
+
#include "str.h"
#include "mem.h"
char *str_dup (const char *s)
{
- char *p;
- size_t l;
-
- if (!s || !*s) return NULL;
- l = str_len (s) + 1;
- p = (char *) mem_malloc (l);
- memcpy (p, s, l);
- return (p);
+ if (!s || !*s)
+ return NULL;
+ return p_dupstr(s, str_len(s));
}
char *str_cat (char *d, size_t l, const char *s)
void str_replace (char **p, const char *s)
{
- mem_free (p);
+ p_delete(p);
*p = str_dup (s);
}
return dest;
}
-char *str_substrdup (const char *begin, const char *end)
+char *str_substrdup(const char *begin, const char *end)
{
- size_t len;
- char *p;
-
- if (end)
- len = end - begin;
- else
- len = str_len (begin);
-
- p = mem_malloc (len + 1);
- memcpy (p, begin, len);
- p[len] = 0;
- return p;
+ return p_dupstr(begin, (end ? end - begin : strlen(begin)));
}
const char *str_isstr (const char *haystack, const char *needle)
#include <stdlib.h>
#include <string.h>
+#include <lib-lib/mem.h>
+
#include "list.h"
#include "lib/mem.h"
#include "lib/str.h"
LIST *t, *r = NULL, *l = NULL;
for (; p; p = p->next) {
- t = (LIST *) mem_malloc (sizeof (LIST));
+ t = p_new(LIST, 1);
t->data = str_dup (p->data);
t->next = NULL;
if (l) {
for (tmp = head; tmp && tmp->next; tmp = tmp->next);
if (tmp) {
- tmp->next = mem_malloc (sizeof (LIST));
+ tmp->next = p_new(LIST, 1);
tmp = tmp->next;
} else
- head = tmp = mem_malloc (sizeof (LIST));
+ head = tmp = p_new(LIST, 1);
- tmp->data = mem_malloc (len);
+ tmp->data = p_new(char, len);
if (len)
memcpy (tmp->data, data, len);
tmp->next = NULL;
while (*list) {
p = *list;
*list = (*list)->next;
- mem_free (&p->data);
- mem_free (&p);
+ p_delete(&p->data);
+ p_delete(&p);
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "keymap.h"
mutt_endwin (NULL);
perror (tempfile);
fclose (fin);
- mem_free (&tempfile);
+ p_delete(&tempfile);
exit (1);
}
if (fin)
}
}
- mem_free (&bodytext);
+ p_delete(&bodytext);
if (attach) {
LIST *t = attach;
if (option (OPTXTERMSETTITLES))
mutt_xterm_set_title (NONULL (XtermLeave));
if (Context)
- mem_free (&Context);
+ p_delete(&Context);
}
mutt_endwin (Errorbuf);
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mx.h"
#include "buffy.h"
ctx->hdrs[i]->index = j++;
}
}
- mem_free (&newOffset);
- mem_free (&oldOffset);
+ p_delete(&newOffset);
+ p_delete(&oldOffset);
unlink (tempfile); /* remove partial copy of the mailbox */
mutt_unblock_signals ();
mbox_unlock_mailbox (ctx);
mutt_unblock_signals ();
- mem_free (&newOffset);
- mem_free (&oldOffset);
+ p_delete(&newOffset);
+ p_delete(&oldOffset);
if ((ctx->fp = freopen (ctx->path, "r", ctx->fp)) == NULL) {
mutt_error _("Could not reopen mailbox!");
if (ctx->subj_hash)
hash_destroy (&ctx->subj_hash, NULL);
mutt_clear_threads (ctx);
- mem_free (&ctx->v2r);
+ p_delete(&ctx->v2r);
if (ctx->readonly) {
for (i = 0; i < ctx->msgcount; i++)
mutt_free_header (&(ctx->hdrs[i])); /* nothing to do! */
- mem_free (&ctx->hdrs);
+ p_delete(&ctx->hdrs);
}
else {
/* save the old headers */
/* free the old headers */
for (j = 0; j < old_msgcount; j++)
mutt_free_header (&(old_hdrs[j]));
- mem_free (&old_hdrs);
+ p_delete(&old_hdrs);
ctx->quiet = 0;
return (-1);
msg_mod = 1;
}
}
- mem_free (&old_hdrs);
+ p_delete(&old_hdrs);
}
ctx->quiet = 0;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "mutt_curses.h"
{
int shift = option (OPTARROWCURSOR) ? 3 : 0;
int cols;
- char *tmpbuf = mem_malloc (n);
+ char *tmpbuf = p_new(char, n);
if (option (OPTMBOXPANE))
cols = COLS - shift - SidebarWidth;
mutt_format_string (tmpbuf, n, cols, cols, 0, ' ', s, str_len (s), 1);
tmpbuf[n - 1] = 0;
snprintf (s, n, "%s", tmpbuf); /* overkill */
- mem_free (&tmpbuf);
+ p_delete(&tmpbuf);
}
void menu_redraw_full (MUTTMENU * menu)
{
int i;
- mem_free (&(*p)->searchBuf);
+ p_delete(&(*p)->searchBuf);
if ((*p)->dialog) {
for (i = 0; i < (*p)->max; i++)
- mem_free (&(*p)->dialog[i]);
+ p_delete(&(*p)->dialog[i]);
- mem_free (&(*p)->dialog);
+ p_delete(&(*p)->dialog);
}
- mem_free (p);
+ p_delete(p);
}
#define M_SEARCH_UP 1
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mx.h"
#include "mh.h"
static void mhs_free_sequences (struct mh_sequences *mhs)
{
- mem_free (&mhs->flags);
+ p_delete(&mhs->flags);
}
static short mhs_check (struct mh_sequences *mhs, int i)
}
}
- mem_free (&buff);
+ p_delete(&buff);
safe_fclose (&fp);
}
}
if ((*fp = fdopen (fd, "w")) == NULL) {
- mem_free (tgt);
+ p_delete(tgt);
close (fd);
unlink (path);
return (-1);
unlink (tmpfname);
}
- mem_free (&tmpfname);
+ p_delete(&tmpfname);
}
static void mh_sequences_add_one (CONTEXT * ctx, int n, short unseen,
}
}
safe_fclose (&ofp);
- mem_free (&buff);
+ p_delete(&buff);
if (!unseen_done && unseen)
fprintf (nfp, "%s: %d\n", NONULL (MhUnseen), n);
if (safe_rename (tmpfname, sequences) != 0)
unlink (tmpfname);
- mem_free (&tmpfname);
+ p_delete(&tmpfname);
}
static void mh_update_maildir (struct maildir *md, struct mh_sequences *mhs)
if (!md || !*md)
return;
- mem_free (&(*md)->canon_fname);
+ p_delete(&(*md)->canon_fname);
if ((*md)->h)
mutt_free_header (&(*md)->h);
- mem_free (md);
+ p_delete(md);
}
static void maildir_free_maildir (struct maildir **md)
}
if (q == h->maildir_flags)
- mem_free (&h->maildir_flags);
+ p_delete(&h->maildir_flags);
else if (q)
*q = '\0';
}
else
mutt_free_header (&p->h);
#ifdef USE_HCACHE
- mem_free (&data);
+ p_delete(&data);
#endif
}
#ifdef USE_HCACHE
}
if ((msg->fp = fdopen (fd, "w")) == NULL) {
- mem_free (&msg->path);
+ p_delete(&msg->path);
close (fd);
unlink (path);
return (-1);
if (safe_rename (msg->path, full) == 0) {
if (hdr)
str_replace (&hdr->path, path);
- mem_free (&msg->path);
+ p_delete(&msg->path);
/*
* Adjust the mtime on the file to match the time at which this
if (safe_rename (msg->path, path) == 0) {
if (hdr)
str_replace (&hdr->path, tmp);
- mem_free (&msg->path);
+ p_delete(&msg->path);
break;
}
else if (errno != EEXIST) {
safe_fclose (&fp);
if (safe_rename (tmp, buf) == -1)
unlink (tmp);
- mem_free (&tmp);
+ p_delete(&tmp);
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "charset.h"
irrev = 1;
}
- mem_free (&t2);
- mem_free (&tmp);
+ p_delete(&t2);
+ p_delete(&tmp);
if (irrev)
goto notrans;
return 0;
notrans:
- mem_free (out);
+ p_delete(out);
*out = str_dup (in);
return 1;
}
if (!rv && idna_to_ascii_8z (tmp, out, 1) != IDNA_SUCCESS)
rv = -2;
- mem_free (&tmp);
+ p_delete(&tmp);
if (rv < 0) {
- mem_free (out);
+ p_delete(out);
*out = str_dup (in);
}
return rv;
sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
}
- mem_free (&domain);
- mem_free (&user);
- mem_free (&tmp);
+ p_delete(&domain);
+ p_delete(&user);
+ p_delete(&tmp);
if (e)
return -1;
sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
}
- mem_free (&domain);
- mem_free (&user);
- mem_free (&tmp);
+ p_delete(&domain);
+ p_delete(&user);
+ p_delete(&tmp);
}
return 0;
char *domain = NULL;
char *user = NULL;
- mem_free (&buff);
+ p_delete(&buff);
if (mbox_to_udomain (a->mailbox, &user, &domain) != 0)
return a->mailbox;
if (mutt_idna_to_local (domain, &tmp, MI_MAY_BE_IRREVERSIBLE) != 0) {
- mem_free (&user);
- mem_free (&domain);
- mem_free (&tmp);
+ p_delete(&user);
+ p_delete(&domain);
+ p_delete(&tmp);
return a->mailbox;
}
mem_realloc (&buff, str_len (tmp) + str_len (user) + 2);
sprintf (buff, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
- mem_free (&tmp);
- mem_free (&user);
- mem_free (&domain);
+ p_delete(&tmp);
+ p_delete(&user);
+ p_delete(&domain);
return buff;
}
#include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "enter.h"
/* Create hostname:port string and tell libesmtp */
/* len = SmtpHost len + colon + max port (65536 => 5 chars) + terminator */
hostportlen = str_len (SmtpHost) + 7;
- hostportstr = mem_malloc (hostportlen);
+ hostportstr = p_new(char, hostportlen);
snprintf (hostportstr, hostportlen, "%s:%d", SmtpHost, SmtpPort);
if (!smtp_set_server (session, hostportstr))
SMTPFAIL ("smtp_set_server");
if (fp != NULL)
fclose (fp);
if (hostportstr != NULL)
- mem_free (&hostportstr);
+ p_delete(&hostportstr);
if (session != NULL)
smtp_destroy_session (session);
if (authctx != NULL)
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "account.h"
#include "mutt_sasl.h"
return SASL_FAIL;
interaction->len = str_len (resp) + 1;
- interaction->result = mem_malloc (interaction->len);
- memcpy ((char*) interaction->result, resp, interaction->len);
-
+ interaction->result = p_dupstr(resp, interaction->len - 1);
interaction++;
}
* for the read/write methods. */
void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn)
{
- SASL_DATA *sasldata = (SASL_DATA *) mem_malloc (sizeof (SASL_DATA));
+ SASL_DATA *sasldata = p_new(SASL_DATA, 1);
sasldata->saslconn = saslconn;
/* get ssf so we know whether we have to (en|de)code read/write */
len = str_len (account->pass);
- *psecret = (sasl_secret_t *) mem_malloc (sizeof (sasl_secret_t) + len);
+ *psecret = xmalloc(sizeof(sasl_secret_t) + len);
(*psecret)->len = len;
strcpy ((char*) (*psecret)->data, account->pass); /* __STRCPY_CHECKED__ */
/* release sasl resources */
sasl_dispose (&sasldata->saslconn);
- mem_free (&sasldata->buf);
- mem_free (&sasldata);
+ p_delete(&sasldata->buf);
+ p_delete(&sasldata);
/* call underlying close */
rc = (conn->conn_close) (conn);
conn->sockdata = sasldata->sockdata;
- mem_free (&sasldata->buf);
+ p_delete(&sasldata->buf);
sasldata->bpos = 0;
sasldata->blen = 0;
}
rc = (sasldata->msasl_write) (conn, pbuf, plen);
- mem_free (&pbuf);
+ p_delete(&pbuf);
if (rc != plen)
goto fail;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "globals.h"
#include "mutt_socket.h"
/* head is special case, doesn't need prev updated */
if (iter == conn) {
Connections = iter->next;
- mem_free (&iter);
+ p_delete(&iter);
return;
}
if (iter->next == conn) {
tmp = iter->next;
iter->next = tmp->next;
- mem_free (&tmp);
+ p_delete(&tmp);
return;
}
iter = iter->next;
rc = getaddrinfo (host_idna, port, &hints, &res);
# ifdef HAVE_LIBIDN
- mem_free (&host_idna);
+ p_delete(&host_idna);
# endif
if (rc) {
if ((he = gethostbyname (host_idna)) == NULL) {
# ifdef HAVE_LIBIDN
- mem_free (&host_idna);
+ p_delete(&host_idna);
# endif
mutt_error (_("Could not find the host \"%s\""), conn->account.host);
}
# ifdef HAVE_LIBIDN
- mem_free (&host_idna);
+ p_delete(&host_idna);
# endif
mutt_message (_("Connecting to %s..."), conn->account.host);
#include <string.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_socket.h"
#include "mutt_menu.h"
return 0;
bail_ssl:
- mem_free (&ssldata->ssl);
+ p_delete(&ssldata->ssl);
bail_ctx:
- mem_free (&ssldata->ctx);
+ p_delete(&ssldata->ctx);
bail_ssldata:
- mem_free (&ssldata);
+ p_delete(&ssldata);
bail:
return -1;
}
#endif
SSL_free (data->ssl);
SSL_CTX_free (data->ctx);
- mem_free (&conn->sockdata);
+ p_delete(&conn->sockdata);
}
return raw_socket_close (conn);
#include <gnutls/openssl.h>
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_socket.h"
#include "mutt_curses.h"
conn->sockdata = data;
err = gnutls_certificate_allocate_credentials (&data->xcred);
if (err < 0) {
- mem_free (&conn->sockdata);
+ p_delete(&conn->sockdata);
mutt_error (_("gnutls_certificate_allocate_credentials: %s"),
gnutls_strerror (err));
mutt_sleep (2);
fail:
gnutls_certificate_free_credentials (data->xcred);
gnutls_deinit (data->state);
- mem_free (&conn->sockdata);
+ p_delete(&conn->sockdata);
return -1;
}
gnutls_certificate_free_credentials (data->xcred);
gnutls_deinit (data->state);
- mem_free(&conn->sockdata);
+ p_delete(&conn->sockdata);
}
return raw_socket_close (conn);
do {
ret = gnutls_pem_base64_decode_alloc (NULL, &b64_data, &cert);
if (ret != 0) {
- mem_free (&b64_data_data);
+ p_delete(&b64_data_data);
return 0;
}
if (memcmp (cert.data, peercert->data, cert.size) == 0) {
/* match found */
gnutls_free (cert.data);
- mem_free (&b64_data_data);
+ p_delete(&b64_data_data);
return 1;
}
}
} while (ptr != NULL);
/* no match found */
- mem_free (&b64_data_data);
+ p_delete(&b64_data_data);
return 0;
}
if (str_cmp (linestr + pmatch[1].rm_so, hostname) == 0 &&
str_cmp (linestr + pmatch[2].rm_so, buf) == 0) {
regfree (&preg);
- mem_free(&linestr);
+ p_delete(&linestr);
fclose (fp);
return 1;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_socket.h"
#include "mutt_tunnel.h"
int rc;
int pin[2], pout[2];
- tunnel = (TUNNEL_DATA *) mem_malloc (sizeof (TUNNEL_DATA));
+ tunnel = p_new(TUNNEL_DATA, 1);
conn->sockdata = tunnel;
mutt_message (_("Connecting with \"%s\"..."), Tunnel);
NONULL(mutt_strsysexit(WEXITSTATUS(status))));
mutt_sleep (2);
}
- mem_free (&conn->sockdata);
+ p_delete(&conn->sockdata);
return 0;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "buffer.h"
else if (b->filename)
debug_print (1, ("not unlinking %s.\n", b->filename));
- mem_free (&b->filename);
- mem_free (&b->content);
- mem_free (&b->xtype);
- mem_free (&b->subtype);
- mem_free (&b->description);
- mem_free (&b->form_name);
+ p_delete(&b->filename);
+ p_delete(&b->content);
+ p_delete(&b->xtype);
+ p_delete(&b->subtype);
+ p_delete(&b->description);
+ p_delete(&b->form_name);
if (b->hdr) {
/* Don't free twice (b->hdr->content = b->parts) */
if (b->parts)
mutt_free_body (&b->parts);
- mem_free (&b);
+ p_delete(&b);
}
*p = 0;
PARAMETER *o;
while (t) {
- mem_free (&t->attribute);
- mem_free (&t->value);
+ p_delete(&t->attribute);
+ p_delete(&t->value);
o = t;
t = t->next;
- mem_free (&o);
+ p_delete(&o);
}
*p = 0;
}
return;
mutt_free_envelope (&(*h)->env);
mutt_free_body (&(*h)->content);
- mem_free (&(*h)->maildir_flags);
- mem_free (&(*h)->tree);
- mem_free (&(*h)->path);
+ p_delete(&(*h)->maildir_flags);
+ p_delete(&(*h)->tree);
+ p_delete(&(*h)->path);
#ifdef MIXMASTER
mutt_free_list (&(*h)->chain);
#endif
#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
- mem_free (&(*h)->data);
+ p_delete(&(*h)->data);
#endif
- mem_free (h);
+ p_delete(h);
}
/* returns true if the header contained in "s" is in list "t" */
rfc822_free_address (&(*p)->reply_to);
rfc822_free_address (&(*p)->mail_followup_to);
- mem_free (&(*p)->list_post);
- mem_free (&(*p)->subject);
+ p_delete(&(*p)->list_post);
+ p_delete(&(*p)->subject);
/* real_subj is just an offset to subject and shouldn't be freed */
- mem_free (&(*p)->message_id);
- mem_free (&(*p)->supersedes);
- mem_free (&(*p)->date);
- mem_free (&(*p)->x_label);
- mem_free (&(*p)->organization);
+ p_delete(&(*p)->message_id);
+ p_delete(&(*p)->supersedes);
+ p_delete(&(*p)->date);
+ p_delete(&(*p)->x_label);
+ p_delete(&(*p)->organization);
#ifdef USE_NNTP
- mem_free (&(*p)->newsgroups);
- mem_free (&(*p)->xref);
- mem_free (&(*p)->followup_to);
- mem_free (&(*p)->x_comment_to);
+ p_delete(&(*p)->newsgroups);
+ p_delete(&(*p)->xref);
+ p_delete(&(*p)->followup_to);
+ p_delete(&(*p)->x_comment_to);
#endif
mutt_buffer_free (&(*p)->spam);
mutt_free_list (&(*p)->references);
mutt_free_list (&(*p)->in_reply_to);
mutt_free_list (&(*p)->userhdrs);
- mem_free (p);
+ p_delete(p);
}
/* move all the headers from extra not present in base into base */
while (*p) {
t = *p;
*p = (*p)->next;
- mem_free (&t->name);
+ p_delete(&t->name);
rfc822_free_address (&t->addr);
- mem_free (&t);
+ p_delete(&t);
}
}
str_replace (directory, fname);
break;
case 1: /* yes */
- mem_free (directory);
+ p_delete(directory);
break;
case -1: /* abort */
- mem_free (directory);
+ p_delete(directory);
return -1;
case 2: /* no */
- mem_free (directory);
+ p_delete(directory);
return 1;
}
}
}
else {
unsigned int bar = mutt_skipchars (src, "%\\");
- char *bar2 = mem_malloc (bar + 1);
+ char *bar2 = p_dupstr(src, bar);
- strfcpy (bar2, src, bar + 1);
while (bar--) {
*wptr++ = *src++;
wlen++;
}
col += mutt_strwidth (bar2);
- mem_free (&bar2);
+ p_delete(&bar2);
}
}
*wptr = 0;
s[len - 1] = 0;
mutt_endwin (NULL);
*thepid = mutt_create_filter (s, NULL, &f, NULL);
- mem_free (&s);
+ p_delete(&s);
} else {
f = fopen (path, "r");
if (!f)
p = *list;
*list = (*list)->next;
rx_free (&p->rx);
- mem_free(&p->template);
- mem_free(&p);
+ p_delete(&p->template);
+ p_delete(&p);
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffy.h"
#include "ascii.h"
int rc;
if (!ctx)
- ctx = mem_malloc (sizeof (CONTEXT));
- memset (ctx, 0, sizeof (CONTEXT));
+ ctx = p_new(CONTEXT, 1);
+ p_clear(ctx, 1);
ctx->path = str_dup (path);
ctx->msgnotreadyet = -1;
if (mx_open_mailbox_append (ctx, flags) != 0) {
mx_fastclose_mailbox (ctx);
if (!pctx)
- mem_free (&ctx);
+ p_delete(&ctx);
return NULL;
}
return ctx;
if (ctx->magic <= 0) {
mx_fastclose_mailbox (ctx);
if (!pctx)
- mem_free (&ctx);
+ p_delete(&ctx);
return (NULL);
}
else {
mx_fastclose_mailbox (ctx);
if (!pctx)
- mem_free (&ctx);
+ p_delete(&ctx);
}
unset_option (OPTFORCEREFRESH);
mutt_clear_threads (ctx);
for (i = 0; i < ctx->msgcount; i++)
mutt_free_header (&ctx->hdrs[i]);
- mem_free (&ctx->hdrs);
- mem_free (&ctx->v2r);
+ p_delete(&ctx->hdrs);
+ p_delete(&ctx->v2r);
#ifdef USE_COMPRESSED
if (ctx->compressinfo)
mutt_fast_close_compressed (ctx);
#endif
- mem_free (&ctx->path);
- mem_free (&ctx->pattern);
+ p_delete(&ctx->path);
+ p_delete(&ctx->pattern);
if (ctx->limit_pattern)
mutt_pattern_free (&ctx->limit_pattern);
safe_fclose (&ctx->fp);
}
}
else
- mem_free (&msg);
+ p_delete(&msg);
return msg;
}
if (msg->fp == NULL) {
mutt_perror (path);
debug_print (1, ("fopen: %s: %s (errno %d).\n", path, strerror (errno), errno));
- mem_free (&msg);
+ p_delete(&msg);
}
}
break;
case M_IMAP:
{
if (imap_fetch_message (msg, ctx, msgno) != 0)
- mem_free (&msg);
+ p_delete(&msg);
break;
}
#endif /* USE_IMAP */
case M_POP:
{
if (pop_fetch_message (msg, ctx, msgno) != 0)
- mem_free (&msg);
+ p_delete(&msg);
break;
}
#endif /* USE_POP */
case M_NNTP:
{
if (nntp_fetch_message (msg, ctx, msgno) != 0)
- mem_free (&msg);
+ p_delete(&msg);
break;
}
#endif /* USE_NNTP */
default:
debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic));
- mem_free (&msg);
+ p_delete(&msg);
break;
}
return (msg);
if ((*msg)->path) {
debug_print (1, ("unlinking %s\n", (*msg)->path));
unlink ((*msg)->path);
- mem_free (&(*msg)->path);
+ p_delete(&(*msg)->path);
}
- mem_free (msg);
+ p_delete(msg);
return (r);
}
h2 = hash_find (ctx->id_hash, h->env->supersedes);
- /* mem_free (&h->env->supersedes); should I ? */
+ /* p_delete(&h->env->supersedes); should I ? */
if (h2) {
h2->superseded = 1;
if (!ctx->counting && option (OPTSCORE))
#include <sys/stat.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "nntp.h"
#include <config.h>
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "sort.h"
nntp_add_to_list (news, data);
}
else
- mem_free (&data->entries);
+ p_delete(&data->entries);
data->rc = 1;
data->entries = mem_calloc (x * 2, sizeof (NEWSRC_ENTRY));
return -1;
}
- buf = mem_malloc (sb.st_size + 1);
+ buf = p_new(char, sb.st_size + 1);
while (fgets (buf, sb.st_size + 1, fp))
nntp_parse_newsrc_line (news, buf);
- mem_free (&buf);
+ p_delete(&buf);
mx_unlock_file (news->newsrc, fileno (fp), 0);
fclose (fp);
set_option (OPTNEWSCACHE);
- mem_free (&news->cache);
+ p_delete(&news->cache);
snprintf (buf, sizeof (buf), "%s/.index", dir);
if (!(index = safe_fopen (buf, "a+")))
return 0;
ret = mutt_account_fromurl (acct, &url);
}
- mem_free (&c);
+ p_delete(&c);
return ret;
}
url.path = str_dup (line);
mutt_account_tourl (acct, &url);
url_ciss_tostring (&url, line, len, 0);
- mem_free (&url.path);
+ p_delete(&url.path);
}
/*
strcpy (p, server);
if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
- mem_free (&buf);
+ p_delete(&buf);
mutt_error (_("%s is an invalid newsserver specification!"), server);
return NULL;
}
- mem_free (&buf);
+ p_delete(&buf);
conn = mutt_conn_find (NULL, &acct);
if (!conn)
for (list = serv->list; list; list = list->next)
list->data = NULL;
mutt_free_list (&serv->list);
- mem_free (&serv->newsrc);
- mem_free (&serv->cache);
- mem_free (&serv);
+ p_delete(&serv->newsrc);
+ p_delete(&serv->cache);
+ p_delete(&serv);
return NULL;
}
nntp_clear_cacheindex (serv);
news->size = st.st_size;
news->mtime = st.st_mtime;
}
- mem_free (&buf);
+ p_delete(&buf);
return r;
}
nntp_cache_expand (buf, data->cache);
unlink (buf);
- mem_free (&data->cache);
+ p_delete(&data->cache);
data->lastCached = 0;
nntp_cache_expand (buf, ".index");
mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
#include <config.h>
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "sort.h"
ret = 0;
line = 0;
- inbuf = mem_malloc (sizeof (buf));
+ inbuf = p_new(char, sizeof(buf));
FOREVER {
chunk = mutt_socket_readln_d (buf, sizeof (buf), nntp_data->nserv->conn,
mem_realloc (&inbuf, lenbuf + sizeof (buf));
}
- mem_free (&inbuf);
+ p_delete(&inbuf);
funct (NULL, data);
}
while (!done);
debug_print (2, ("group: %s, desc: %s\n", line, d));
if ((data = (NNTP_DATA *) hash_find (news->newsgroups, line)) != NULL &&
str_cmp (d, data->desc)) {
- mem_free (&data->desc);
+ p_delete(&data->desc);
data->desc = str_dup (d);
}
return 0;
hdr->received = hdr->date_sent;
break;
case 4:
- mem_free (&hdr->env->message_id);
+ p_delete(&hdr->env->message_id);
hdr->env->message_id = str_dup (b);
break;
case 5:
break;
case 8:
if (!hdr->read)
- mem_free (&hdr->env->xref);
+ p_delete(&hdr->env->xref);
b = b + 6; /* skips the "Xref: " */
hdr->env->xref = str_dup (b);
nntp_parse_xref (ctx, nntp_data->group, b, hdr);
#ifdef DEBUG
nntp_error ("nntp_fetch_headers()", buf);
#endif
- mem_free (&fc.messages);
+ p_delete(&fc.messages);
return -1;
}
}
}
num = last - first + 1;
if (num <= 0) {
- mem_free (&fc.messages);
+ p_delete(&fc.messages);
return 0;
}
#ifdef DEBUG
nntp_error ("nntp_fetch_headers()", buf);
#endif
- mem_free (&fc.messages);
+ p_delete(&fc.messages);
return -1;
}
/* fetched OK */
else
mutt_free_header (&h); /* skip it */
if (ret == -1) {
- mem_free (&fc.messages);
+ p_delete(&fc.messages);
return -1;
}
if (current > nntp_data->lastLoaded)
nntp_data->lastLoaded = current;
}
- mem_free (&fc.messages);
+ p_delete(&fc.messages);
nntp_data->lastLoaded = last;
mutt_clear_error ();
return 0;
/* clear the previous entry */
unlink (cache->path);
- mem_free (&cache->path);
+ p_delete(&cache->path);
cache->index = ctx->hdrs[msgno]->index;
mutt_mktemp (path);
cache->path = str_dup (path);
if (!(msg->fp = safe_fopen (path, "w+"))) {
- mem_free (&cache->path);
+ p_delete(&cache->path);
return -1;
}
if (ret) {
fclose (msg->fp);
unlink (path);
- mem_free (&cache->path);
+ p_delete(&cache->path);
return -1;
}
for (i = 0; i < NNTP_CACHE_LEN; i++) {
if (data->acache[i].path) {
unlink (data->acache[i].path);
- mem_free (&data->acache[i].path);
+ p_delete(&data->acache[i].path);
}
}
}
void nntp_delete_data (void *p)
{
- NNTP_DATA *data = (NNTP_DATA *) p;
+ NNTP_DATA *data = (NNTP_DATA *)p;
if (!p)
return;
- mem_free (&data->entries);
- mem_free (&data->desc);
- mem_free (&data->cache);
+ p_delete(&data->entries);
+ p_delete(&data->desc);
+ p_delete(&data->cache);
nntp_free_acache (data);
- mem_free (p);
+ p_delete(&data);
}
int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2)
else
nntp_data->allowed = 0;
if (nntp_data->desc)
- mem_free (&nntp_data->desc);
+ p_delete(&nntp_data->desc);
if (*desc)
nntp_data->desc = str_dup (desc);
if (nntp_data->rc || nntp_data->lastCached)
return 0;
}
else {
- mem_free (&serv->cache);
+ p_delete(&serv->cache);
return -1;
}
}
cc.ctx = ctx;
cc.num = 0;
cc.max = 25;
- cc.child = mem_malloc (sizeof (unsigned int) * 25);
+ cc.child = p_new(unsigned int, 25);
if (mutt_nntp_fetch (nntp_data, buf, NULL, NULL, check_children, &cc, 0)) {
- mem_free (&cc.child);
+ p_delete(&cc.child);
return -1;
}
/* dont try to read the xover cache. check_children() already
}
if (tmp)
set_option (OPTNEWSCACHE);
- mem_free (&cc.child);
+ p_delete(&cc.child);
return ret;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "mutt_curses.h"
cleanup_quote (&((*QuoteList)->down));
ptr = (*QuoteList)->next;
if ((*QuoteList)->prefix)
- mem_free (&(*QuoteList)->prefix);
- mem_free (QuoteList);
+ p_delete(&(*QuoteList)->prefix);
+ p_delete(QuoteList);
*QuoteList = ptr;
}
memset (&((*lineInfo)[ch]), 0, sizeof (struct line_t));
(*lineInfo)[ch].type = -1;
(*lineInfo)[ch].search_cnt = -1;
- (*lineInfo)[ch].syntax = mem_malloc (sizeof (struct syntax_t));
+ (*lineInfo)[ch].syntax = p_new(struct syntax_t, 1);
((*lineInfo)[ch].syntax)[0].first = ((*lineInfo)[ch].syntax)[0].last =
-1;
}
mem_realloc (&((*lineInfo)[n].search),
((*lineInfo)[n].search_cnt) * sizeof (struct syntax_t));
else
- (*lineInfo)[n].search = mem_malloc (sizeof (struct syntax_t));
+ (*lineInfo)[n].search = p_new(struct syntax_t, 1);
pmatch[0].rm_so += offset;
pmatch[0].rm_eo += offset;
((*lineInfo)[n].search)[(*lineInfo)[n].search_cnt - 1].first =
mutt_set_flag (Context, extra->hdr, M_READ, 1);
}
- lineInfo = mem_malloc (sizeof (struct line_t) * (maxLine = LINES));
+ lineInfo = p_new(struct line_t, maxLine = LINES);
for (i = 0; i < maxLine; i++) {
memset (&lineInfo[i], 0, sizeof (struct line_t));
lineInfo[i].type = -1;
lineInfo[i].search_cnt = -1;
- lineInfo[i].syntax = mem_malloc (sizeof (struct syntax_t));
+ lineInfo[i].syntax = p_new(struct syntax_t, 1);
(lineInfo[i].syntax)[0].first = (lineInfo[i].syntax)[0].last = -1;
}
lines = Resize->line;
redraw |= REDRAW_SIGWINCH;
- mem_free (&Resize);
+ p_delete(&Resize);
}
#endif
lines++;
if (flags & M_PAGER_RETWINCH) {
- Resize = mem_malloc (sizeof (struct resize));
+ Resize = p_new(struct resize, 1);
Resize->line = lines;
Resize->SearchCompiled = SearchCompiled;
mem_realloc (&(lineInfo[i].syntax), sizeof (struct syntax_t));
if (SearchCompiled && lineInfo[i].search)
- mem_free (&(lineInfo[i].search));
+ p_delete(&(lineInfo[i].search));
}
lastLine = 0;
regfree (&SearchRE);
for (i = 0; i < lastLine; i++) {
if (lineInfo[i].search)
- mem_free (&(lineInfo[i].search));
+ p_delete(&(lineInfo[i].search));
lineInfo[i].search_cnt = -1;
}
}
for (i = 0; i < maxLine; i++) {
/* cleanup */
if (lineInfo[i].search)
- mem_free (&(lineInfo[i].search));
+ p_delete(&(lineInfo[i].search));
lineInfo[i].search_cnt = -1;
}
SearchFlag = 0;
mem_realloc (&(lineInfo[i].syntax), sizeof (struct syntax_t));
if (SearchCompiled && lineInfo[i].search)
- mem_free (&(lineInfo[i].search));
+ p_delete(&(lineInfo[i].search));
}
if (SearchCompiled) {
cleanup_quote (&QuoteList);
for (i = 0; i < maxLine; i++) {
- mem_free (&(lineInfo[i].syntax));
+ p_delete(&(lineInfo[i].syntax));
if (SearchCompiled && lineInfo[i].search)
- mem_free (&(lineInfo[i].search));
+ p_delete(&(lineInfo[i].search));
}
if (SearchCompiled) {
regfree (&SearchRE);
SearchCompiled = 0;
}
- mem_free (&lineInfo);
+ p_delete(&lineInfo);
if (index)
mutt_menuDestroy (&index);
return (rc != -1 ? rc : 0);
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffer.h"
#include "enter.h"
else if (o) {
m = str_len (s);
if (s[m - 1] == '>') {
- new = mem_malloc (sizeof (char) * (n + m + 1));
+ new = p_new(char, n + m + 1);
strcpy (new, o); /* __STRCPY_CHECKED__ */
strcpy (new + n, s); /* __STRCPY_CHECKED__ */
}
*/
if (!(at = strchr (new, '@')) || strchr (at + 1, '@')
|| (in_reply_to && at - new <= 8))
- mem_free (&new);
+ p_delete(&new);
else {
- t = (LIST *) mem_malloc (sizeof (LIST));
+ t = p_new(LIST, 1);
t->data = new;
t->next = lst;
lst = t;
new = mutt_new_parameter ();
- new->attribute = mem_malloc (i + 1);
- memcpy (new->attribute, s, i);
- new->attribute[i] = 0;
+ new->attribute = p_dupstr(s, i);
/* remove whitespace from the end of the attribute name */
while (ISSPACE (new->attribute[--i]))
char *pc;
char *subtype;
- mem_free (&ct->subtype);
+ p_delete(&ct->subtype);
mutt_free_parameter (&ct->parameter);
/* First extract any existing parameters */
{
BODY *p = mutt_new_body ();
char *c;
- char *line = mem_malloc (LONG_STRING);
+ char *line = p_new(char, LONG_STRING);
size_t linelen = LONG_STRING;
p->hdr_offset = ftello (fp);
else if (p->type == TYPEMESSAGE && !p->subtype)
p->subtype = str_dup ("rfc822");
- mem_free (&line);
+ p_delete(&line);
return (p);
}
}
/* extract the first substring that looks like a message-id */
-static char *extract_message_id (const char *s)
+static char *extract_message_id(const char *s)
{
- const char *p;
- char *r;
- size_t l;
+ const char *p;
- if ((s = strchr (s, '<')) == NULL || (p = strchr (s, '>')) == NULL)
- return (NULL);
- l = (size_t) (p - s) + 1;
- r = mem_malloc (l + 1);
- memcpy (r, s, l);
- r[l] = 0;
- return (r);
+ if ((s = strchr(s, '<')) == NULL || (p = strchr(s, '>')) == NULL)
+ return NULL;
+ return p_dupstr(s, (p - s));
}
void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur)
/* Take the first mailto URL */
if (url_check_scheme (beg) == U_MAILTO) {
- mem_free (&e->list_post);
+ p_delete(&e->list_post);
e->list_post = str_substrdup (beg, end);
break;
}
}
else if (!ascii_strcasecmp (line + 1, "essage-id")) {
/* We add a new "Message-ID:" when building a message */
- mem_free (&e->message_id);
+ p_delete(&e->message_id);
e->message_id = extract_message_id (p);
matched = 1;
}
#ifdef USE_NNTP
case 'n':
if (!str_casecmp (line + 1, "ewsgroups")) {
- mem_free (&e->newsgroups);
+ p_delete(&e->newsgroups);
str_skip_trailws (p);
e->newsgroups = str_dup (str_skip_initws (p));
matched = 1;
{
ENVELOPE *e = mutt_new_envelope ();
LIST *last = NULL;
- char *line = mem_malloc (LONG_STRING);
+ char *line = p_new(char, LONG_STRING);
char *p;
off_t loc;
int matched;
}
- mem_free (&line);
+ p_delete(&line);
if (hdr) {
hdr->content->hdr_offset = hdr->offset;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "buffer.h"
#include "handler.h"
}
}
- blen = STRING;
- buf = mem_malloc (blen);
+ buf = p_new(char, blen = STRING);
/* search the file "fp" */
while (lng > 0) {
lng -= str_len (buf);
}
- mem_free (&buf);
+ p_delete(&buf);
mx_close_message (&msg);
if (pat->stringmatch) {
pat->str = str_dup (buf.data);
- mem_free (&buf.data);
+ p_delete(&buf.data);
} else {
- pat->rx = mem_malloc (sizeof (regex_t));
+ pat->rx = p_new(regex_t, 1);
r = REGCOMP (pat->rx, buf.data, REG_NEWLINE | REG_NOSUB | mutt_which_case (buf.data));
- mem_free (&buf.data);
+ p_delete(&buf.data);
if (r) {
regerror (r, pat->rx, err->data, err->dsize);
regfree (pat->rx);
- mem_free (&pat->rx);
+ p_delete(&pat->rx);
return (-1);
}
}
if (isdigit ((unsigned char) *pc)) {
/* mininum date specified */
if ((pc = getDate (pc, &min, err)) == NULL) {
- mem_free (&buffer.data);
+ p_delete(&buffer.data);
return (-1);
}
haveMin = TRUE;
max.tm_mday = min.tm_mday;
if (!parse_date_range (pc, &min, &max, haveMin, &baseMin, err)) { /* bail out on any parsing error */
- mem_free (&buffer.data);
+ p_delete(&buffer.data);
return (-1);
}
}
pat->min = mutt_mktime (&min, 1);
pat->max = mutt_mktime (&max, 1);
- mem_free (&buffer.data);
+ p_delete(&buffer.data);
return 0;
}
if (tmp->rx) {
regfree (tmp->rx);
- mem_free (&tmp->rx);
+ p_delete(&tmp->rx);
}
- mem_free (&tmp->str);
+ p_delete(&tmp->str);
if (tmp->child)
mutt_pattern_free (&tmp->child);
- mem_free (&tmp);
+ p_delete(&tmp);
}
}
/* compile the sub-expression */
buf = str_substrdup (ps.dptr + 1, p);
if ((tmp = mutt_pattern_comp (buf, flags, err)) == NULL) {
- mem_free (&buf);
+ p_delete(&buf);
mutt_pattern_free (&curlist);
return NULL;
}
- mem_free (&buf);
+ p_delete(&buf);
if (last)
last->next = tmp;
else
err.data = error;
err.dsize = sizeof (error);
if ((pat = mutt_pattern_comp (buf, M_FULL_MSG, &err)) == NULL) {
- mem_free (&simple);
+ p_delete(&simple);
mutt_error ("%s", err.data);
return (-1);
}
if (op == M_LIMIT) {
/* drop previous limit pattern */
- mem_free (&Context->pattern);
+ p_delete(&Context->pattern);
if (Context->limit_pattern)
mutt_pattern_free (&Context->limit_pattern);
if (Context->msgcount && !Context->vcount) {
Context->limit_pattern = mutt_pattern_comp (buf, M_FULL_MSG, &err);
}
}
- mem_free (&simple);
+ p_delete(&simple);
mutt_pattern_free (&pat);
return 0;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "ascii.h"
fputs (line, fpout);
fputc ('\n', fpout);
}
- mem_free (&line);
+ p_delete(&line);
}
else {
debug_print (2, ("No pattern.\n"));
k_info = pgp_getkeybystr (keyID, KEYFLAG_CANENCRYPT, PGP_PUBRING);
}
else if (r == -1) {
- mem_free (&keylist);
+ p_delete(&keylist);
rfc822_free_address (&tmp);
rfc822_free_address (&addr);
return NULL;
if ((key = pgp_ask_for_key (buf, q->mailbox,
KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) {
- mem_free (&keylist);
+ p_delete(&keylist);
rfc822_free_address (&tmp);
rfc822_free_address (&addr);
return NULL;
#include <fcntl.h>
#include <time.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_idna.h"
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "ascii.h"
}
mutt_menuDestroy (&menu);
- mem_free (&KeyTable);
+ p_delete(&KeyTable);
set_option (OPTNEEDREDRAW);
if (l)
str_replace (&l->dflt, resp);
else {
- l = mem_malloc (sizeof (struct pgp_cache));
+ l = p_new(struct pgp_cache, 1);
l->next = id_defaults;
id_defaults = l;
l->what = str_dup (whatfor);
hints = mutt_add_list (hints, t);
}
- mem_free (&scratch);
+ p_delete(&scratch);
return hints;
}
#include <unistd.h>
#include <time.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "lib.h"
#include "pgplib.h"
for (sp = *sigp; sp; sp = q) {
q = sp->next;
- mem_free (&sp);
+ p_delete(&sp);
}
*sigp = NULL;
for (up = *upp; up; up = q) {
q = up->next;
pgp_free_sig (&up->sigs);
- mem_free (&up->addr);
- mem_free (&up);
+ p_delete(&up->addr);
+ p_delete(&up);
}
*upp = NULL;
kp = *kpp;
pgp_free_uid (&kp->address);
- mem_free (&kp->keyid);
- mem_free (kpp);
+ p_delete(&kp->keyid);
+ p_delete(kpp);
}
pgp_key_t pgp_remove_key (pgp_key_t * klist, pgp_key_t key)
#include <unistd.h>
#include <time.h>
+#include <lib-lib/mem.h>
+
#include "sha1.h"
#include "lib.h"
#include "pgplib.h"
startpos = ftello (fp);
if (!plen) {
- plen = CHUNKSIZE;
- pbuf = mem_malloc (plen);
+ pbuf = p_new(char, plen = CHUNKSIZE);
}
if (fread (&ctb, 1, 1, fp) < 1) {
void pgp_release_packet (void)
{
plen = 0;
- mem_free (&pbuf);
+ p_delete(&pbuf);
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "lib/mem.h"
#include "lib/str.h"
bailout:
- mem_free (&p);
+ p_delete(&p);
return NULL;
}
if (!addr)
break;
- chr = mem_malloc (l);
- memcpy (chr, buff + 1, l - 1);
- chr[l - 1] = '\0';
-
+ chr = p_dupstr(buff + 1, l - 1);
*addr = uid = mem_calloc (1, sizeof (pgp_uid_t)); /* XXX */
uid->addr = chr;
size_t error_buf_len;
error_buf_len = sizeof ("fopen: ") - 1 + str_len (ringfile) + 1;
- error_buf = mem_malloc (error_buf_len);
+ error_buf = p_new(char, error_buf_len);
snprintf (error_buf, error_buf_len, "fopen: %s", ringfile);
perror (error_buf);
- mem_free (&error_buf);
+ p_delete(&error_buf);
return;
}
keypos = pos;
}
else if (pt == PT_NAME) {
- char *tmp = mem_malloc (l);
-
- memcpy (tmp, buff + 1, l - 1);
- tmp[l - 1] = '\0';
+ char *tmp = p_dupstr(buff + 1, l - 1);
/* mutt_decode_utf8_string (tmp, chs); */
pgp_free_key (&p);
}
- mem_free (&tmp);
+ p_delete(&tmp);
}
FGETPOS (rfp, pos);
#include <sys/stat.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "pop.h"
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mx.h"
#include "pop.h"
if (!conn)
return -1;
- mem_free (&ctx->path);
+ p_delete(&ctx->path);
ctx->path = str_dup (buf);
pop_data = mem_calloc (1, sizeof (POP_DATA));
for (i = 0; i < POP_CACHE_LEN; i++) {
if (pop_data->cache[i].path) {
unlink (pop_data->cache[i].path);
- mem_free (&pop_data->cache[i].path);
+ p_delete(&pop_data->cache[i].path);
}
}
}
else {
/* clear the previous entry */
unlink (cache->path);
- mem_free (&cache->path);
+ p_delete(&cache->path);
}
}
strcpy (p, PopHost); /* __STRCPY_CHECKED__ */
ret = pop_parse_path (url, &acct);
- mem_free (&url);
+ p_delete(&url);
if (ret) {
mutt_error (_("%s is an invalid POP path"), PopHost);
return;
if (pop_open_connection (pop_data) < 0) {
mutt_socket_free (pop_data->conn);
- mem_free (&pop_data);
+ p_delete(&pop_data);
return;
}
if (pop_query (pop_data, buffer, sizeof (buffer)) == PQ_NOT_CONNECTED)
goto fail;
mutt_socket_close (conn);
- mem_free (&pop_data);
+ p_delete(&pop_data);
return;
fail:
mutt_error _("Server closed connection!");
mutt_socket_close (conn);
- mem_free (&pop_data);
+ p_delete(&pop_data);
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mx.h"
/* sasl_client_st(art|ep) allocate pc with malloc, expect me to
* free it */
#ifndef USE_SASL
- mem_free (&pc);
+ p_delete(&pc);
#endif
}
}
{
char *p1, *p2;
- mem_free (&pop_data->timestamp);
+ p_delete(&pop_data->timestamp);
if ((p1 = strchr (buf, '<')) && (p2 = strchr (p1, '>'))) {
p2[1] = '\0';
method = comma;
}
- mem_free (&methods);
+ p_delete(&methods);
}
else {
/* Fall back to default: any authenticator */
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mx.h"
ret = 0;
}
- mem_free (&c);
+ p_delete(&c);
return ret;
}
char *c;
if (!ascii_strncasecmp (line, "SASL", 4)) {
- mem_free (&pop_data->auth_list);
+ p_delete(&pop_data->auth_list);
c = line + 4;
SKIPWS (c);
pop_data->auth_list = str_dup (c);
POP_DATA *pop_data = (POP_DATA *) data;
if (!pop_data->auth_list) {
- pop_data->auth_list = mem_malloc (strlen (line) + 1);
- *pop_data->auth_list = '\0';
- }
- else {
+ pop_data->auth_list = p_new(char, strlen(line) + 1);
+ } else {
mem_realloc (&pop_data->auth_list,
strlen (pop_data->auth_list) + strlen (line) + 2);
strcat (pop_data->auth_list, " "); /* __STRCAT_CHECKED__ */
pop_data->resp_codes = 0;
pop_data->expire = 1;
pop_data->login_delay = 0;
- mem_free (&pop_data->auth_list);
+ p_delete(&pop_data->auth_list);
}
/* Execute CAPA command */
if (ret != PQ_OK)
return ret;
- inbuf = mem_malloc (sizeof (buf));
+ inbuf = p_new(char, sizeof(buf));
FOREVER {
chunk =
mem_realloc (&inbuf, lenbuf + sizeof (buf));
}
- mem_free (&inbuf);
+ p_delete(&inbuf);
return ret;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "enter.h"
if (!PostContext->msgcount) {
PostCount = 0;
mx_close_mailbox (PostContext, NULL);
- mem_free (&PostContext);
+ p_delete(&PostContext);
mutt_error _("No postponed messages.");
return (-1);
}
else if ((h = select_msg ()) == NULL) {
mx_close_mailbox (PostContext, NULL);
- mem_free (&PostContext);
+ p_delete(&PostContext);
return (-1);
}
if (mutt_prepare_template (NULL, PostContext, hdr, h, 0) < 0) {
mx_fastclose_mailbox (PostContext);
- mem_free (&PostContext);
+ p_delete(&PostContext);
return (-1);
}
mx_close_mailbox (PostContext, NULL);
set_quadoption (OPT_DELETE, opt_delete);
- mem_free (&PostContext);
+ p_delete(&PostContext);
for (tmp = hdr->env->userhdrs; tmp;) {
if (ascii_strncasecmp ("X-Mutt-References:", tmp->data, 18) == 0) {
newhdr->content->length = hdr->content->length;
mutt_parse_part (fp, newhdr->content);
- mem_free (&newhdr->env->message_id);
- mem_free (&newhdr->env->mail_followup_to); /* really? */
+ p_delete(&newhdr->env->message_id);
+ p_delete(&newhdr->env->mail_followup_to); /* really? */
/* decrypt pgp/mime encoded messages */
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_menu.h"
#include "mutt_idna.h"
}
}
}
- mem_free (&buf);
+ p_delete(&buf);
fclose (fp);
if (mutt_wait_filter (thepid)) {
debug_print (1, ("Error: %s\n", msg));
queryp = results;
while (queryp) {
rfc822_free_address (&queryp->addr);
- mem_free (&queryp->name);
- mem_free (&queryp->other);
+ p_delete(&queryp->name);
+ p_delete(&queryp->other);
results = queryp->next;
- mem_free (&queryp);
+ p_delete(&queryp);
queryp = results;
}
results = newresults;
- mem_free (&QueryTable);
+ p_delete(&QueryTable);
}
else {
/* append */
queryp = results;
while (queryp) {
rfc822_free_address (&queryp->addr);
- mem_free (&queryp->name);
- mem_free (&queryp->other);
+ p_delete(&queryp->name);
+ p_delete(&queryp->other);
results = queryp->next;
- mem_free (&queryp);
+ p_delete(&queryp);
queryp = results;
}
- mem_free (&QueryTable);
+ p_delete(&QueryTable);
/* tell whoever called me to redraw the screen when I return */
set_option (OPTNEEDREDRAW);
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "enter.h"
static int mutt_extract_path (char *filename, char *path)
{
- char *tmp = mem_malloc (sizeof (char) * _POSIX_PATH_MAX);
+ char *tmp = p_new(char, _POSIX_PATH_MAX);
char *help_ptr;
help_ptr = tmp;
}
*help_ptr++ = *filename++;
}
- mem_free (&tmp);
+ p_delete(&tmp);
return 0;
}
break;
}
- mem_free (&directory);
+ p_delete(&directory);
if (tag && menu) {
menu->oldcurrent = menu->current;
hdr->attach_del = 1;
if (idx[idxmax]->content)
idx[idxmax]->content->aptr = NULL;
- mem_free (&idx[idxmax]->tree);
- mem_free (&idx[idxmax]);
+ p_delete(&idx[idxmax]->tree);
+ p_delete(&idx[idxmax]);
}
if (hdr->attach_del)
hdr->changed = 1;
- mem_free (&idx);
+ p_delete(&idx);
idxmax = 0;
if (WithCrypto && need_secured && secured) {
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "state.h"
if (mutt_addrlist_to_idna (adr, &err) < 0) {
mutt_error (_("Bad IDN: '%s'"), err);
- mem_free (&err);
+ p_delete(&err);
rfc822_free_address (&adr);
return;
}
/* Free everything we malloc. */
#ifdef MATCH_MAY_ALLOCATE
-#define mem_free_VAR(var) if (var) REGEX_mem_free (var); var = NULL
+#define mem_free_VAR(var) if (var) REGEX_p_delete(var); var = NULL
#define mem_free_VARIABLES() \
do { \
REGEX_mem_free_STACK (fail_stack.stack); \
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "recvattach.h"
#include "mutt_curses.h"
static void mix_free_remailer (REMAILER ** r)
{
- mem_free (&(*r)->shortname);
- mem_free (&(*r)->addr);
- mem_free (&(*r)->ver);
+ p_delete(&(*r)->shortname);
+ p_delete(&(*r)->addr);
+ p_delete(&(*r)->ver);
- mem_free (r);
+ p_delete(r);
}
/* parse the type2.list as given by mixmaster -T */
for (i = 0; type2_list[i]; i++)
mix_free_remailer (&type2_list[i]);
- mem_free (type2_list);
+ p_delete(type2_list);
}
}
mix_free_type2_list (&type2_list);
- mem_free (&coords);
- mem_free (&chain);
+ p_delete(&coords);
+ p_delete(&chain);
}
/* some safety checks before piping the message to mixmaster */
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "rfc1524.h"
/* a non-zero exit code means test failed */
found = FALSE;
}
- mem_free (&test_command);
+ p_delete(&test_command);
}
}
} /* while (ch) */
if (!found) {
/* reset */
if (entry) {
- mem_free (&entry->command);
- mem_free (&entry->composecommand);
- mem_free (&entry->composetypecommand);
- mem_free (&entry->editcommand);
- mem_free (&entry->printcommand);
- mem_free (&entry->nametemplate);
- mem_free (&entry->convert);
+ p_delete(&entry->command);
+ p_delete(&entry->composecommand);
+ p_delete(&entry->composetypecommand);
+ p_delete(&entry->editcommand);
+ p_delete(&entry->printcommand);
+ p_delete(&entry->nametemplate);
+ p_delete(&entry->convert);
entry->needsterminal = 0;
entry->copiousoutput = 0;
}
} /* while (!found && (buf = mutt_read_line ())) */
fclose (fp);
} /* if ((fp = fopen ())) */
- mem_free (&buf);
+ p_delete(&buf);
return found;
}
{
rfc1524_entry *p = *entry;
- mem_free (&p->command);
- mem_free (&p->testcommand);
- mem_free (&p->composecommand);
- mem_free (&p->composetypecommand);
- mem_free (&p->editcommand);
- mem_free (&p->printcommand);
- mem_free (&p->nametemplate);
- mem_free (entry);
+ p_delete(&p->command);
+ p_delete(&p->testcommand);
+ p_delete(&p->composecommand);
+ p_delete(&p->composetypecommand);
+ p_delete(&p->editcommand);
+ p_delete(&p->printcommand);
+ p_delete(&p->nametemplate);
+ p_delete(entry);
}
/*
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mime.h"
if (cd == (iconv_t) (-1))
return (size_t) (-1);
obl = 4 * flen + 1;
- ob = buf = mem_malloc (obl);
+ ob = buf = p_new(char, obl);
n = my_iconv(cd, &f, &flen, &ob, &obl);
if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
e = errno;
- mem_free (&buf);
+ p_delete(&buf);
iconv_close (cd);
errno = e;
return (size_t) (-1);
n > (ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 2 - 12))
continue;
- t = mem_malloc (n + 1);
- memcpy (t, p, n);
- t[n] = '\0';
+ t = p_dupstr(p, n);
n = convert_string (u, ulen, fromcode, t, &s, &slen);
if (n == (size_t) (-1))
if (!tocode || n < bestn) {
bestn = n;
- mem_free (&tocode);
+ p_delete(&tocode);
tocode = t;
if (d) {
- mem_free (&e);
+ p_delete(&e);
e = s;
}
else
- mem_free (&s);
+ p_delete(&s);
elen = slen;
if (!bestn)
break;
}
else {
- mem_free (&t);
- mem_free (&s);
+ p_delete(&t);
+ p_delete(&s);
}
}
if (tocode) {
if (convert_string (d, dlen, fromcode, icode, &u, &ulen)) {
ret = 1;
icode = 0;
- u = mem_malloc ((ulen = dlen) + 1);
- memcpy (u, d, dlen);
- u[ulen] = 0;
+ u = p_dupstr(d, ulen = dlen);
}
/* Find earliest and latest things we must encode. */
/* Initialise the output buffer with the us-ascii prefix. */
buflen = 2 * ulen;
- buf = mem_malloc (buflen);
+ buf = p_new(char, buflen);
bufpos = t0 - u;
memcpy (buf, u, t0 - u);
bufpos += wlen;
memcpy (buf + bufpos, t1, u + ulen - t1);
- mem_free (&tocode1);
- mem_free (&u);
+ p_delete(&tocode1);
+ p_delete(&u);
buf[buflen] = '\0';
Charset, charsets, &e, &elen,
encode_specials ? RFC822Specials : NULL);
- mem_free (pd);
+ p_delete(pd);
*pd = e;
}
int enc = 0, count = 0;
char *charset = NULL;
- pd = d0 = mem_malloc (str_len (s));
+ pd = d0 = p_new(char, str_len(s));
for (pp = s; (pp1 = strchr (pp, '?')); pp = pp1 + 1) {
count++;
t = pp1;
if ((t1 = memchr (pp, '*', t - pp)))
t = t1;
- charset = mem_malloc (t - pp + 1);
- memcpy (charset, pp, t - pp);
- charset[t - pp] = '\0';
+ charset = p_dupstr(pp, t - pp);
break;
case 3:
if (toupper ((unsigned char) *pp) == 'Q')
else if (toupper ((unsigned char) *pp) == 'B')
enc = ENCBASE64;
else {
- mem_free (&charset);
- mem_free (&d0);
+ p_delete(&charset);
+ p_delete(&d0);
return (-1);
}
break;
if (charset)
mutt_convert_string (&d0, charset, Charset, M_ICONV_HOOK_FROM);
strfcpy (d, d0, len);
- mem_free (&charset);
- mem_free (&d0);
+ p_delete(&charset);
+ p_delete(&d0);
return (0);
}
return;
dlen = 4 * str_len (s); /* should be enough */
- d = d0 = mem_malloc (dlen + 1);
+ d = d0 = p_new(char, dlen + 1);
while (*s && dlen > 0) {
if (!(p = find_encoded_word (s, &q))) {
char *t;
size_t tlen;
- t = mem_malloc (n + 1);
- strfcpy (t, s, n + 1);
+ t = p_dupstr(s, n);
if (mutt_convert_nonmime_string (&t) == 0) {
tlen = str_len (t);
strncpy (d, t, tlen);
strncpy (d, s, n);
d += n;
}
- mem_free (&t);
+ p_delete(&t);
break;
}
}
}
*d = 0;
- mem_free (pd);
+ p_delete(pd);
*pd = d0;
str_adjust (pd);
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mime.h"
p->attribute = NULL;
p->value = NULL;
- mem_free (&p);
+ p_delete(&p);
rfc2231_list_insert (&conthead, conttmp);
}
static void rfc2231_free_parameter (struct rfc2231_parameter **p)
{
if (*p) {
- mem_free (&(*p)->attribute);
- mem_free (&(*p)->value);
- mem_free (p);
+ p_delete(&(*p)->attribute);
+ p_delete(&(*p)->value);
+ p_delete(p);
}
}
++ext;
if (encode) {
- e = mem_malloc (dlen + 2 * ext + str_len (charset) + 3);
+ e = p_new(char, dlen + 2 * ext + str_len(charset) + 3);
sprintf (e, "%s''", charset); /* __SPRINTF_CHECKED__ */
t = e + str_len (e);
for (s = d, slen = dlen; slen; s++, slen--)
*t = '\0';
if (d != *pd)
- mem_free (&d);
- mem_free (pd);
+ p_delete(&d);
+ p_delete(pd);
*pd = e;
}
else if (d != *pd) {
- mem_free (pd);
+ p_delete(pd);
*pd = d;
}
- mem_free (&charset);
+ p_delete(&charset);
return encode;
}
#include <sys/wait.h>
#include <sys/stat.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_curses.h"
#include "ascii.h"
int rfc3676_handler (BODY * a, STATE * s) {
int bytes = a->length;
char buf[LONG_STRING];
- char *curline = mem_malloc(1);
+ char *curline = p_new(char, 1);
char *t = NULL;
unsigned int curline_len = 1,
quotelevel = 0, newql = 0;
}
}
- mem_free (&curline);
+ p_delete(&curline);
return (0);
}
#include <ctype.h>
#include <stdlib.h>
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mutt_idna.h"
while (*p) {
t = *p;
*p = (*p)->next;
- mem_free (&t->personal);
- mem_free (&t->mailbox);
- mem_free (&t);
+ p_delete(&t->personal);
+ p_delete(&t->mailbox);
+ p_delete(&t);
}
}
cur = rfc822_new_address ();
if (phraselen) {
if (cur->personal)
- mem_free (&cur->personal);
+ p_delete(&cur->personal);
/* if we get something like "Michael R. Elkins" remove the quotes */
rfc822_dequote_comment (phrase);
cur->personal = str_dup (phrase);
for (; addr; addr = addr->next)
if (!addr->group && addr->mailbox && strchr (addr->mailbox, '@') == NULL) {
- p = mem_malloc (str_len (addr->mailbox) + str_len (host) + 2);
+ p = p_new(char, str_len(addr->mailbox) + str_len(host) + 2);
sprintf (p, "%s@%s", addr->mailbox, host); /* __SPRINTF_CHECKED__ */
- mem_free (&addr->mailbox);
+ p_delete(&addr->mailbox);
addr->mailbox = p;
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "sort.h"
#include "buffer.h"
memset (buf, 0, sizeof (BUFFER));
mutt_extract_token (buf, s, 0);
if (MoreArgs (s)) {
- mem_free (&pattern);
+ p_delete(&pattern);
strfcpy (err->data, _("score: too many arguments"), err->dsize);
return (-1);
}
break;
if (!ptr) {
if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
- mem_free (&pattern);
+ p_delete(&pattern);
return (-1);
}
ptr = mem_calloc (1, sizeof (SCORE));
last = tmp;
tmp = tmp->next;
mutt_pattern_free (&last->pat);
- mem_free (&last);
+ p_delete(&last);
}
Score = NULL;
}
else
Score = tmp->next;
mutt_pattern_free (&tmp->pat);
- mem_free (&tmp);
+ p_delete(&tmp);
/* there should only be one score per pattern, so we can stop here */
break;
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "ascii.h"
mutt_error (_("Error: '%s' is a bad IDN."), err);
mutt_refresh ();
mutt_sleep (2);
- mem_free (&err);
+ p_delete(&err);
}
}
while (idna_ok != 0);
buf[0] = 0;
if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) != 0)
return (-1);
- mem_free (&en->newsgroups);
+ p_delete(&en->newsgroups);
en->newsgroups = str_dup (buf);
if (en->followup_to)
if (option (OPTASKFOLLOWUP)
&& mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) != 0)
return (-1);
- mem_free (&en->followup_to);
+ p_delete(&en->followup_to);
en->followup_to = str_dup (buf);
if (en->x_comment_to)
if (option (OPTXCOMMENTTO) && option (OPTASKXCOMMENTTO)
&& mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) != 0)
return (-1);
- mem_free (&en->x_comment_to);
+ p_delete(&en->x_comment_to);
en->x_comment_to = str_dup (buf);
}
else
* been taken from a List-Post header. Is that correct?
*/
if (curenv->real_subj) {
- mem_free (&env->subject);
- env->subject = mem_malloc (str_len (curenv->real_subj) + 5);
+ p_delete(&env->subject);
+ env->subject = p_new(char, str_len(curenv->real_subj) + 5);
sprintf (env->subject, "Re: %s", curenv->real_subj); /* __SPRINTF_CHECKED__ */
}
else if (!env->subject)
if (tmp) {
tmp = rfc822_cpy_adr_real (tmp);
if (!option (OPTREVREAL))
- mem_free (&tmp->personal);
+ p_delete(&tmp->personal);
if (!tmp->personal)
tmp->personal = str_dup (Realname);
}
adr = rfc822_cpy_adr_real (From);
else if (option (OPTUSEDOMAIN)) {
adr = rfc822_new_address ();
- adr->mailbox =
- mem_malloc (str_len (Username) + str_len (fqdn) + 2);
+ adr->mailbox = p_new(char, str_len(Username) + str_len(fqdn) + 2);
sprintf (adr->mailbox, "%s@%s", NONULL (Username), NONULL (fqdn)); /* __SPRINTF_CHECKED__ */
}
else {
if (!(ctype = str_dup (ContentType)))
ctype = str_dup ("text/plain");
mutt_parse_content_type (ctype, msg->content);
- mem_free (&ctype);
+ p_delete(&ctype);
msg->content->unlink = 1;
msg->content->use_disp = 0;
if (mutt_env_to_idna (msg->env, &tag, &err)) {
mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
- mem_free (&err);
+ p_delete(&err);
if (!(flags & SENDBATCH))
goto main_loop;
else
mutt_protect (msg, pgpkeylist) == -1) {
msg->content = mutt_remove_multipart (msg->content);
- mem_free (&pgpkeylist);
+ p_delete(&pgpkeylist);
decode_descriptions (msg->content);
goto main_loop;
#endif
if (WithCrypto && (msg->security & ENCRYPT))
- mem_free (&pgpkeylist);
+ p_delete(&pgpkeylist);
if (WithCrypto && free_clear_content)
mutt_free_body (&clear_content);
if ((WithCrypto & APPLICATION_PGP) && (flags & SENDPOSTPONED)) {
if (signas) {
- mem_free (&PgpSignAs);
+ p_delete(&PgpSignAs);
PgpSignAs = signas;
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "handler.h"
&& !strcmp (buffer, tmp))
snprintf (buffer, sizeof (buffer), "\"%s\"", tmp);
- mem_free (&tmp);
+ p_delete(&tmp);
tmplen = str_len (buffer) + str_len (p->attribute) + 1;
tmp = str_dup (t);
encode = rfc2231_encode_string (&tmp);
rfc822_cat (buffer, sizeof (buffer), tmp, MimeSpecials);
- mem_free (&tmp);
+ p_delete(&tmp);
fprintf (f, "; filename%s=%s", encode ? "*" : "", buffer);
}
}
iconv_close (cd[i]);
iconv_close (cd1);
- mem_free (&cd);
- mem_free (&infos);
- mem_free (&score);
- mem_free (&states);
+ p_delete(&cd);
+ p_delete(&infos);
+ p_delete(&score);
+ p_delete(&states);
return ret;
#else
}
/* Copy them */
- tcode = mem_malloc (ncodes * sizeof (char *));
+ tcode = p_new(char *, ncodes);
for (c = tocodes, i = 0; c; c = c1 ? c1 + 1 : 0, i++) {
if ((c1 = strchr (c, ':')) == c)
continue;
tcode[cn] = 0;
break;
}
- mem_free (&fcode);
+ p_delete(&fcode);
}
}
else {
/* Free memory */
for (i = 0; i < ncodes; i++)
- mem_free (&tcode[i]);
+ p_delete(&tcode[i]);
- mem_free (tcode);
+ p_delete(tcode);
return ret;
}
mutt_set_parameter ("charset", chsbuf, &b->parameter);
}
b->file_charset = fromcode;
- mem_free (&tocode);
+ p_delete(&tocode);
safe_fclose (&fp);
return info;
}
mutt_write_mime_body (a->parts, fpout);
cleanup:
- mem_free (&line);
+ p_delete(&line);
if (fpin && !fp)
fclose (fpin);
mutt_set_encoding (a, info);
mutt_stamp_attachment (a);
- mem_free (&a->content);
+ p_delete(&a->content);
a->content = info;
}
fputs (ref[refcnt]->data, f);
}
- mem_free (&ref);
+ p_delete(&ref);
}
/* Note: all RFC2047 encoding should be done outside of this routine, except
fprintf (fp, "User-Agent: %s (%s)\n", mutt_make_version (0), os);
}
- list_del (&hdrs, (list_del_t*) _mem_free);
+ list_del (&hdrs, (list_del_t*)xmemfree);
return (ferror (fp) == 0 ? 0 : -1);
}
sprintf (h->data + i, ": %s", NONULL (tmp)); /* __SPRINTF_CHECKED__ */
- mem_free (&tmp);
+ p_delete(&tmp);
}
}
}
else if (pid == -1) {
unlink (msg);
- mem_free (tempfile);
+ p_delete(tempfile);
_exit (S_ERR);
}
st = WIFEXITED (st) ? WEXITSTATUS (st) : S_ERR;
if (SendmailWait && st == (0xff & EX_OK)) {
unlink (*tempfile); /* no longer needed */
- mem_free (tempfile);
+ p_delete(tempfile);
}
}
else {
st = (SendmailWait > 0 && errno == EINTR && SigAlrm) ? S_BKG : S_ERR;
if (SendmailWait > 0) {
unlink (*tempfile);
- mem_free (tempfile);
+ p_delete(tempfile);
}
}
if (kill (ppid, 0) == -1 && errno == ESRCH) {
/* the parent is already dead */
unlink (*tempfile);
- mem_free (tempfile);
+ p_delete(tempfile);
}
_exit (st);
else
unlink (childout);
- mem_free (&childout);
- mem_free (&path);
- mem_free (&s);
- mem_free (&args);
+ p_delete(&childout);
+ p_delete(&path);
+ p_delete(&s);
+ p_delete(&args);
if (i == (EX_OK & 0xff))
i = 0;
size_t rlen;
rlen = str_len (s) + 3;
- pr = r = (char *) mem_malloc (rlen);
+ pr = r = p_new(char, rlen);
*pr++ = '"';
while (*s) {
if (INVALID_CHAR (*s)) {
* please see the file GPL in the top level source directory.
*/
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_menu.h"
#include "mutt_curses.h"
if (last_dot) {
++last_dot;
- new_box = mem_malloc (maxlen + 1);
+ new_box = p_new(char, maxlen + 1);
new_box[0] = box[0];
for (i = 1, j = 1; j < maxlen && i < len; ++i) {
if (strchr (SidebarBoundary, box[i])) {
addnstr (entry, len);
if (shortened)
- mem_free(&box);
+ p_delete(&box);
return (1);
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "enter.h"
#include "handler.h"
}
}
if (hash) {
- fname = mem_malloc (13); /* Hash + '.' + Suffix + \0 */
+ fname = p_new(char, 13); /* Hash + '.' + Suffix + \0 */
sprintf (fname, "%.8x.%i", Table[cur].hash, Table[cur].suffix);
}
else
fname = NULL;
mutt_menuDestroy (&menu);
- mem_free (&Table);
+ p_delete(&Table);
set_option (OPTNEEDREDRAW);
if (fname)
/* the key used last time. */
if (*SmimeKeyToUse &&
!str_casecmp (k, SmimeKeyToUse + str_len (SmimeKeys) + 1)) {
- mem_free (&k);
+ p_delete(&k);
return;
}
else
if (str_casecmp (k, SmimeDefaultKey))
smime_void_passphrase ();
- mem_free (&k);
+ p_delete(&k);
return;
}
}
if (!keyID) {
mutt_message (_("No (valid) certificate found for %s."), q->mailbox);
- mem_free (&keylist);
+ p_delete(&keylist);
rfc822_free_address (&tmp);
rfc822_free_address (&addr);
return NULL;
mutt_wait_filter (thepid);
mutt_unlink (certfile);
- mem_free (&certfile);
+ p_delete(&certfile);
}
fflush (fpout);
else
retval = 0;
mutt_unlink (certfile);
- mem_free (&certfile);
+ p_delete(&certfile);
}
else
mutt_any_key_to_continue (_("no certfile"));
if (linelen && !str_casecmp (line, "verification successful"))
badsig = 0;
- mem_free (&line);
+ p_delete(&line);
}
}
line = mutt_read_line (line, &linelen, smimeerr, &lineno);
if (linelen && !str_casecmp (line, "verification successful"))
m->goodsig = 1;
- mem_free (&line);
+ p_delete(&line);
}
else {
m->goodsig = p->goodsig;
break;
case 4: /* (c)lear */
- mem_free (&SmimeCryptAlg);
+ p_delete(&SmimeCryptAlg);
/* fallback */
case -1: /* Ctrl-G or Enter */
choice = 0;
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "mutt_menu.h"
#include "mutt_curses.h"
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "sort.h"
#include "thread.h"
tree->subtree_visible = 0;
if (tree->message) {
- mem_free (&tree->message->tree);
+ p_delete(&tree->message->tree);
if (VISIBLE (tree->message, ctx)) {
tree->deep = 1;
tree->visible = 1;
* From now on we can simply ignore invisible subtrees
*/
calculate_visibility (ctx, &max_depth);
- pfx = mem_malloc (width * max_depth + 2);
- arrow = mem_malloc (width * max_depth + 2);
+ pfx = p_new(char, width * max_depth + 2);
+ arrow = p_new(char, width * max_depth + 2);
while (tree) {
if (depth) {
myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * width;
if (tree->visible) {
myarrow[width] = M_TREE_RARROW;
myarrow[width + 1] = 0;
- new_tree = mem_malloc ((2 + depth * width));
+ new_tree = p_new(char, (2 + depth * width));
if (start_depth > 1) {
strncpy (new_tree, pfx, (start_depth - 1) * width);
strfcpy (new_tree + (start_depth - 1) * width,
while (!tree->deep);
}
- mem_free (&pfx);
- mem_free (&arrow);
+ p_delete(&pfx);
+ p_delete(&arrow);
}
/* since we may be trying to attach as a pseudo-thread a THREAD that
oldlist = subjects;
subjects = subjects->next;
- mem_free (&oldlist);
+ p_delete(&oldlist);
}
return (last);
}
}
else {
Sort ^= SORT_REVERSE;
- mem_free (&array);
+ p_delete(&array);
return (top);
}
}
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+
#include "mutt.h"
#include "ascii.h"
#include "mapping.h"
}
}
- mem_free (&tmp);
+ p_delete(&tmp);
return 0;
}