From 03f5fece58719f4d2c0e2c099f639581abceed4b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Thu, 16 Nov 2017 01:36:55 +0000 Subject: [PATCH] rename memory functions --- addrbook.c | 2 +- alias.c | 6 ++--- attach.c | 8 +++---- bcache.c | 2 +- body.c | 2 +- browser.c | 10 ++++---- buffy.c | 2 +- charset.c | 6 ++--- color.c | 8 +++---- commands.c | 2 +- compose.c | 12 +++++----- compress.c | 2 +- conn/getdomain.c | 2 +- conn/sasl.c | 6 ++--- conn/socket.c | 2 +- conn/ssl.c | 12 +++++----- conn/ssl_gnutls.c | 10 ++++---- conn/tunnel.c | 2 +- copy.c | 14 +++++------ curs_lib.c | 16 ++++++------- curs_main.c | 4 ++-- edit.c | 10 ++++---- enter.c | 12 +++++----- enter_state.h | 2 +- envelope.c | 2 +- group.c | 4 ++-- handler.c | 12 +++++----- hcache/bdb.c | 2 +- hcache/hcache.c | 14 +++++------ hcache/lmdb.c | 2 +- header.c | 2 +- history.c | 2 +- hook.c | 10 ++++---- imap/auth_sasl.c | 6 ++--- imap/browse.c | 2 +- imap/command.c | 4 ++-- imap/imap.c | 10 ++++---- imap/message.c | 6 ++--- imap/utf7.c | 8 +++---- imap/util.c | 8 +++---- init.c | 46 ++++++++++++++++++------------------ keymap.c | 4 ++-- main.c | 2 +- mbox.c | 4 ++-- mbyte.c | 2 +- menu.c | 4 ++-- mh.c | 6 ++--- mutt/buffer.c | 8 +++---- mutt/file.c | 4 ++-- mutt/hash.c | 6 ++--- mutt/list.c | 6 ++--- mutt/mbyte.c | 4 ++-- mutt/memory.c | 32 ++++++++++++------------- mutt/memory.h | 10 ++++---- mutt/string.c | 8 +++---- mutt_idna.c | 4 ++-- mutt_lua.c | 4 ++-- mutt_notmuch.c | 6 ++--- mutt_tags.c | 2 +- muttlib.c | 8 +++---- mx.c | 14 +++++------ ncrypt/crypt.c | 4 ++-- ncrypt/crypt_gpgme.c | 36 ++++++++++++++-------------- ncrypt/crypt_mod.c | 2 +- ncrypt/gnupgparse.c | 6 ++--- ncrypt/pgp.c | 2 +- ncrypt/pgpkey.c | 4 ++-- ncrypt/pgplib.c | 2 +- ncrypt/pgplib.h | 2 +- ncrypt/pgppacket.c | 2 +- ncrypt/smime.c | 14 +++++------ newsrc.c | 38 +++++++++++++++--------------- nntp.c | 28 +++++++++++----------- pager.c | 56 ++++++++++++++++++++++---------------------- parameter.h | 2 +- parse.c | 8 +++---- pattern.c | 8 +++---- pattern.h | 2 +- pgppubring.c | 13 +++++----- pop.c | 6 ++--- pop_auth.c | 4 ++-- pop_lib.c | 8 +++---- query.c | 11 +++++---- recvattach.c | 4 ++-- remailer.c | 8 +++---- rfc1524.c | 4 ++-- rfc2047.c | 22 ++++++++--------- rfc2231.c | 6 ++--- rfc822.c | 2 +- rfc822.h | 2 +- safe_asprintf.c | 6 ++--- score.c | 2 +- send.c | 6 ++--- sendlib.c | 26 ++++++++++---------- sidebar.c | 6 ++--- smtp.c | 4 ++-- thread.c | 14 +++++------ url.c | 2 +- 98 files changed, 403 insertions(+), 401 deletions(-) diff --git a/addrbook.c b/addrbook.c index be6e5634944..11405abb1dd 100644 --- a/addrbook.c +++ b/addrbook.c @@ -173,7 +173,7 @@ void mutt_alias_menu(char *buf, size_t buflen, struct Alias *aliases) menu->max++; } - safe_realloc(&AliasTable, menu->max * sizeof(struct Alias *)); + mutt_mem_realloc(&AliasTable, menu->max * sizeof(struct Alias *)); menu->data = AliasTable; if (!AliasTable) return; diff --git a/alias.c b/alias.c index 12a929ed4f7..dc580a591c8 100644 --- a/alias.c +++ b/alias.c @@ -336,7 +336,7 @@ void mutt_create_alias(struct Envelope *cur, struct Address *iadr) } } - new = safe_calloc(1, sizeof(struct Alias)); + new = mutt_mem_calloc(1, sizeof(struct Alias)); new->name = safe_strdup(buf); mutt_addrlist_to_local(adr); @@ -548,10 +548,10 @@ int mutt_alias_complete(char *s, size_t buflen) if (a->name && (strstr(a->name, s) == a->name)) { if (!a_list) /* init */ - a_cur = a_list = safe_malloc(sizeof(struct Alias)); + a_cur = a_list = mutt_mem_malloc(sizeof(struct Alias)); else { - a_cur->next = safe_malloc(sizeof(struct Alias)); + a_cur->next = mutt_mem_malloc(sizeof(struct Alias)); a_cur = a_cur->next; } memcpy(a_cur, a, sizeof(struct Alias)); diff --git a/attach.c b/attach.c index 6358fb87031..92fde687f98 100644 --- a/attach.c +++ b/attach.c @@ -1139,8 +1139,8 @@ void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach) if (actx->idxlen == actx->idxmax) { actx->idxmax += 5; - safe_realloc(&actx->idx, sizeof(struct AttachPtr *) * actx->idxmax); - safe_realloc(&actx->v2r, sizeof(short) * actx->idxmax); + mutt_mem_realloc(&actx->idx, sizeof(struct AttachPtr *) * actx->idxmax); + mutt_mem_realloc(&actx->v2r, sizeof(short) * actx->idxmax); for (i = actx->idxlen; i < actx->idxmax; i++) actx->idx[i] = NULL; } @@ -1155,7 +1155,7 @@ void mutt_actx_add_fp(struct AttachCtx *actx, FILE *new_fp) if (actx->fp_len == actx->fp_max) { actx->fp_max += 5; - safe_realloc(&actx->fp_idx, sizeof(FILE *) * actx->fp_max); + mutt_mem_realloc(&actx->fp_idx, sizeof(FILE *) * actx->fp_max); for (i = actx->fp_len; i < actx->fp_max; i++) actx->fp_idx[i] = NULL; } @@ -1170,7 +1170,7 @@ void mutt_actx_add_body(struct AttachCtx *actx, struct Body *new_body) if (actx->body_len == actx->body_max) { actx->body_max += 5; - safe_realloc(&actx->body_idx, sizeof(struct Body *) * actx->body_max); + mutt_mem_realloc(&actx->body_idx, sizeof(struct Body *) * actx->body_max); for (i = actx->body_len; i < actx->body_max; i++) actx->body_idx[i] = NULL; } diff --git a/bcache.c b/bcache.c index 1dd6bb8b1e8..1f83a09a2c4 100644 --- a/bcache.c +++ b/bcache.c @@ -111,7 +111,7 @@ struct BodyCache *mutt_bcache_open(struct Account *account, const char *mailbox) if (!account) goto bail; - bcache = safe_calloc(1, sizeof(struct BodyCache)); + bcache = mutt_mem_calloc(1, sizeof(struct BodyCache)); if (bcache_path(account, mailbox, bcache->path, sizeof(bcache->path)) < 0) goto bail; bcache->pathlen = mutt_strlen(bcache->path); diff --git a/body.c b/body.c index a1e02f91a98..272f58428c0 100644 --- a/body.c +++ b/body.c @@ -35,7 +35,7 @@ struct Body *mutt_new_body(void) { - struct Body *p = safe_calloc(1, sizeof(struct Body)); + struct Body *p = mutt_mem_calloc(1, sizeof(struct Body)); p->disposition = DISPATTACH; p->use_disp = true; diff --git a/browser.c b/browser.c index dd661f7405f..b68e0699d84 100644 --- a/browser.c +++ b/browser.c @@ -605,7 +605,7 @@ static void add_folder(struct Menu *m, struct BrowserState *state, const char *n if (state->entrylen == state->entrymax) { /* need to allocate more space */ - safe_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256)); + mutt_mem_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256)); memset(&state->entry[state->entrylen], 0, sizeof(struct FolderFile) * 256); if (m) m->data = state->entry; @@ -649,7 +649,7 @@ static void init_state(struct BrowserState *state, struct Menu *menu) { state->entrylen = 0; state->entrymax = 256; - state->entry = safe_calloc(state->entrymax, sizeof(struct FolderFile)); + state->entry = mutt_mem_calloc(state->entrymax, sizeof(struct FolderFile)); #ifdef USE_IMAP state->imap_browse = false; #endif @@ -1475,7 +1475,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi if (menu->tagged) { *numfiles = menu->tagged; - tfiles = safe_calloc(*numfiles, sizeof(char *)); + tfiles = mutt_mem_calloc(*numfiles, sizeof(char *)); for (int j = 0, k = 0; j < state.entrylen; j++) { struct FolderFile ff = state.entry[j]; @@ -1492,7 +1492,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi else if (f[0]) /* no tagged entries. return selected entry */ { *numfiles = 1; - tfiles = safe_calloc(*numfiles, sizeof(char *)); + tfiles = mutt_mem_calloc(*numfiles, sizeof(char *)); mutt_expand_path(f, flen); tfiles[0] = safe_strdup(f); *files = tfiles; @@ -1684,7 +1684,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi strfcpy(buf, NONULL(Mask.pattern), sizeof(buf)); if (mutt_get_field(_("File Mask: "), buf, sizeof(buf), 0) == 0) { - regex_t *rx = safe_malloc(sizeof(regex_t)); + regex_t *rx = mutt_mem_malloc(sizeof(regex_t)); char *s = buf; int not = 0, err; diff --git a/buffy.c b/buffy.c index 97037c4df8a..5ad0d4e3efe 100644 --- a/buffy.c +++ b/buffy.c @@ -160,7 +160,7 @@ static struct Buffy *buffy_new(const char *path) char rp[PATH_MAX] = ""; char *r = NULL; - buffy = safe_calloc(1, sizeof(struct Buffy)); + buffy = mutt_mem_calloc(1, sizeof(struct Buffy)); strfcpy(buffy->path, path, sizeof(buffy->path)); r = realpath(path, rp); strfcpy(buffy->realpath, r ? rp : path, sizeof(buffy->realpath)); diff --git a/charset.c b/charset.c index 267df735286..ecf943fdc9a 100644 --- a/charset.c +++ b/charset.c @@ -469,7 +469,7 @@ int mutt_convert_string(char **ps, const char *from, const char *to, int flags) ib = s; ibl = len + 1; obl = MB_LEN_MAX * ibl; - ob = buf = safe_malloc(obl + 1); + ob = buf = mutt_mem_malloc(obl + 1); mutt_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); iconv_close(cd); @@ -533,14 +533,14 @@ FGETCONV *fgetconv_open(FILE *file, const char *from, const char *to, int flags) if (cd != (iconv_t) -1) { - fc = safe_malloc(sizeof(struct FgetConv)); + fc = mutt_mem_malloc(sizeof(struct FgetConv)); fc->p = fc->ob = fc->bufo; fc->ib = fc->bufi; fc->ibl = 0; fc->inrepls = mutt_is_utf8(to) ? repls : repls + 1; } else - fc = safe_malloc(sizeof(struct FgetConvNot)); + fc = mutt_mem_malloc(sizeof(struct FgetConvNot)); fc->file = file; fc->cd = cd; return (FGETCONV *) fc; diff --git a/color.c b/color.c index a82f0f72273..ad381a74e98 100644 --- a/color.c +++ b/color.c @@ -149,7 +149,7 @@ static const struct Mapping ComposeFields[] = { static struct ColorLine *new_color_line(void) { - struct ColorLine *p = safe_calloc(1, sizeof(struct ColorLine)); + struct ColorLine *p = mutt_mem_calloc(1, sizeof(struct ColorLine)); p->fg = p->bg = -1; @@ -179,7 +179,7 @@ static void free_color_line(struct ColorLine *tmp, int free_colors) void ci_start_color(void) { memset(ColorDefs, A_NORMAL, sizeof(int) * MT_COLOR_MAX); - ColorQuote = safe_malloc(COLOR_QUOTE_INIT * sizeof(int)); + ColorQuote = mutt_mem_malloc(COLOR_QUOTE_INIT * sizeof(int)); memset(ColorQuote, A_NORMAL, sizeof(int) * COLOR_QUOTE_INIT); ColorQuoteSize = COLOR_QUOTE_INIT; ColorQuoteUsed = 0; @@ -281,7 +281,7 @@ int mutt_alloc_color(int fg, int bg) i++; } - p = safe_malloc(sizeof(struct ColorList)); + p = mutt_mem_malloc(sizeof(struct ColorList)); p->next = ColorList; ColorList = p; @@ -940,7 +940,7 @@ static int parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, { if (q_level >= ColorQuoteSize) { - safe_realloc(&ColorQuote, (ColorQuoteSize += 2) * sizeof(int)); + mutt_mem_realloc(&ColorQuote, (ColorQuoteSize += 2) * sizeof(int)); ColorQuote[ColorQuoteSize - 2] = ColorDefs[MT_COLOR_QUOTED]; ColorQuote[ColorQuoteSize - 1] = ColorDefs[MT_COLOR_QUOTED]; } diff --git a/commands.c b/commands.c index 488282113be..d87a6cb7905 100644 --- a/commands.c +++ b/commands.c @@ -647,7 +647,7 @@ void mutt_enter_command(void) return; mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); mutt_buffer_init(&token); r = mutt_parse_rc_line(buffer, &token, &err); FREE(&token.data); diff --git a/compose.c b/compose.c index af7d89471f9..a1fcfeedbfd 100644 --- a/compose.c +++ b/compose.c @@ -534,7 +534,7 @@ static void mutt_gen_compose_attach_list(struct AttachCtx *actx, struct Body *m, } else { - new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); + new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr)); mutt_actx_add_attach(actx, new); new->content = m; m->aptr = new; @@ -800,7 +800,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ menu->redraw_data = &rd; mutt_push_current_menu(menu); - actx = safe_calloc(sizeof(struct AttachCtx), 1); + actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1); actx->hdr = msg; mutt_update_compose_menu(actx, menu, 1); @@ -992,7 +992,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ case OP_COMPOSE_ATTACH_KEY: if (!(WithCrypto & APPLICATION_PGP)) break; - new = safe_calloc(1, sizeof(struct AttachPtr)); + new = mutt_mem_calloc(1, sizeof(struct AttachPtr)); new->content = crypt_pgp_make_key_attachment(NULL); if (new->content) { @@ -1028,7 +1028,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ for (i = 0; i < numfiles; i++) { char *att = files[i]; - new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); + new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr)); new->unowned = 1; new->content = mutt_make_file_attach(att); if (new->content) @@ -1151,7 +1151,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ if (!message_is_tagged(Context, i)) continue; - new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); + new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr)); new->content = mutt_make_message_attach(Context, Context->hdrs[i], 1); if (new->content != NULL) update_idx(menu, actx, new); @@ -1427,7 +1427,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ mutt_error(_("Unknown Content-Type %s"), type); continue; } - new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); + new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr)); /* Touch the file */ fp = mutt_file_fopen(fname, "w"); if (!fp) diff --git a/compress.c b/compress.c index b0ff20f3420..104a5f55757 100644 --- a/compress.c +++ b/compress.c @@ -256,7 +256,7 @@ static struct CompressInfo *set_compress_info(struct Context *ctx) const char *c = find_hook(MUTT_CLOSEHOOK, ctx->path); const char *a = find_hook(MUTT_APPENDHOOK, ctx->path); - struct CompressInfo *ci = safe_calloc(1, sizeof(struct CompressInfo)); + struct CompressInfo *ci = mutt_mem_calloc(1, sizeof(struct CompressInfo)); ctx->compress_info = ci; ci->open = safe_strdup(o); diff --git a/conn/getdomain.c b/conn/getdomain.c index 593a7607936..0038f1d2c2e 100644 --- a/conn/getdomain.c +++ b/conn/getdomain.c @@ -73,7 +73,7 @@ int getdnsdomainname(char *d, size_t len) int status; struct timespec timeout = { 0, 100000000 }; struct gaicb *reqs[1]; - reqs[0] = safe_calloc(1, sizeof(*reqs[0])); + reqs[0] = mutt_mem_calloc(1, sizeof(*reqs[0])); reqs[0]->ar_name = node; reqs[0]->ar_request = &hints; if (getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0) diff --git a/conn/sasl.c b/conn/sasl.c index f71707f7b96..5cf046b21d2 100644 --- a/conn/sasl.c +++ b/conn/sasl.c @@ -285,7 +285,7 @@ static int mutt_sasl_cb_pass(sasl_conn_t *conn, void *context, int id, sasl_secr len = strlen(account->pass); - safe_realloc(&secret_ptr, sizeof(sasl_secret_t) + len); + mutt_mem_realloc(&secret_ptr, sizeof(sasl_secret_t) + len); memcpy((char *) secret_ptr->data, account->pass, (size_t) len); secret_ptr->len = len; *psecret = secret_ptr; @@ -667,7 +667,7 @@ int mutt_sasl_interact(sasl_interact_t *interaction) return SASL_FAIL; interaction->len = mutt_strlen(resp) + 1; - interaction->result = safe_malloc(interaction->len); + interaction->result = mutt_mem_malloc(interaction->len); memcpy((char *) interaction->result, resp, interaction->len); interaction++; @@ -686,7 +686,7 @@ int mutt_sasl_interact(sasl_interact_t *interaction) */ void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn) { - struct SaslData *sasldata = safe_malloc(sizeof(struct SaslData)); + struct SaslData *sasldata = mutt_mem_malloc(sizeof(struct SaslData)); /* work around sasl_getprop aliasing issues */ const void *tmp = NULL; diff --git a/conn/socket.c b/conn/socket.c index c1d52c11846..67192ed43a8 100644 --- a/conn/socket.c +++ b/conn/socket.c @@ -343,7 +343,7 @@ struct Connection *socket_new_conn(void) { struct Connection *conn = NULL; - conn = safe_calloc(1, sizeof(struct Connection)); + conn = mutt_mem_calloc(1, sizeof(struct Connection)); conn->fd = -1; return conn; diff --git a/conn/ssl.c b/conn/ssl.c index 049f62b773e..383c4d5897c 100644 --- a/conn/ssl.c +++ b/conn/ssl.c @@ -337,7 +337,7 @@ static void ssl_dprint_err_stack(void) buflen = BIO_get_mem_data(bio, &buf); if (buflen > 0) { - output = safe_malloc(buflen + 1); + output = mutt_mem_malloc(buflen + 1); memcpy(output, buf, buflen); output[buflen] = '\0'; mutt_debug(1, "SSL error stack: %s\n", output); @@ -886,7 +886,7 @@ static int check_host(X509 *x509cert, const char *hostname, char *err, size_t er goto out; } bufsize++; /* space for the terminal nul char */ - buf = safe_malloc((size_t) bufsize); + buf = mutt_mem_malloc((size_t) bufsize); if (X509_NAME_get_text_by_NID(x509_subject, NID_commonName, buf, bufsize) == -1) { if (err && errlen) @@ -977,9 +977,9 @@ static int interactive_check_cert(X509 *cert, int idx, int len, SSL *ssl, int al mutt_push_current_menu(menu); menu->max = mutt_array_size(part) * 2 + 10; - menu->dialog = safe_calloc(1, menu->max * sizeof(char *)); + menu->dialog = mutt_mem_calloc(1, menu->max * sizeof(char *)); for (int i = 0; i < menu->max; i++) - menu->dialog[i] = safe_calloc(1, SHORT_STRING * sizeof(char)); + menu->dialog[i] = mutt_mem_calloc(1, SHORT_STRING * sizeof(char)); row = 0; strfcpy(menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING); @@ -1338,7 +1338,7 @@ static int ssl_socket_open(struct Connection *conn) if (raw_socket_open(conn) < 0) return -1; - data = safe_calloc(1, sizeof(struct SslSockData)); + data = mutt_mem_calloc(1, sizeof(struct SslSockData)); conn->sockdata = data; data->ctx = SSL_CTX_new(SSLv23_client_method()); @@ -1441,7 +1441,7 @@ int mutt_ssl_starttls(struct Connection *conn) if (ssl_init()) goto bail; - ssldata = safe_calloc(1, sizeof(struct SslSockData)); + ssldata = mutt_mem_calloc(1, sizeof(struct SslSockData)); /* the ssl_use_xxx protocol options don't apply. We must use TLS in TLS. * * However, we need to be able to negotiate amongst various TLS versions, diff --git a/conn/ssl_gnutls.c b/conn/ssl_gnutls.c index 1379750fe92..80cc5ed17be 100644 --- a/conn/ssl_gnutls.c +++ b/conn/ssl_gnutls.c @@ -378,7 +378,7 @@ static int tls_compare_certificates(const gnutls_datum_t *peercert) return 0; b64_data.size = filestat.st_size + 1; - b64_data_data = safe_calloc(1, b64_data.size); + b64_data_data = mutt_mem_calloc(1, b64_data.size); b64_data_data[b64_data.size - 1] = '\0'; b64_data.data = b64_data_data; @@ -649,9 +649,9 @@ static int tls_check_one_certificate(const gnutls_datum_t *certdata, menu = mutt_new_menu(MENU_GENERIC); menu->max = 25; - menu->dialog = safe_calloc(1, menu->max * sizeof(char *)); + menu->dialog = mutt_mem_calloc(1, menu->max * sizeof(char *)); for (int i = 0; i < menu->max; i++) - menu->dialog[i] = safe_calloc(1, SHORT_STRING * sizeof(char)); + menu->dialog[i] = mutt_mem_calloc(1, SHORT_STRING * sizeof(char)); mutt_push_current_menu(menu); row = 0; @@ -1037,7 +1037,7 @@ static int tls_set_priority(struct TlsSockData *data) int err; priority_size = SHORT_STRING + mutt_strlen(SslCiphers); - priority = safe_malloc(priority_size); + priority = mutt_mem_malloc(priority_size); priority[0] = 0; if (SslCiphers) @@ -1142,7 +1142,7 @@ static int tls_negotiate(struct Connection *conn) struct TlsSockData *data = NULL; int err; - data = safe_calloc(1, sizeof(struct TlsSockData)); + data = mutt_mem_calloc(1, sizeof(struct TlsSockData)); conn->sockdata = data; err = gnutls_certificate_allocate_credentials(&data->xcred); if (err < 0) diff --git a/conn/tunnel.c b/conn/tunnel.c index e0871205ce2..57fcc49f4cd 100644 --- a/conn/tunnel.c +++ b/conn/tunnel.c @@ -76,7 +76,7 @@ static int tunnel_socket_open(struct Connection *conn) int pin[2], pout[2]; int devnull; - tunnel = safe_malloc(sizeof(struct TunnelData)); + tunnel = mutt_mem_malloc(sizeof(struct TunnelData)); conn->sockdata = tunnel; mutt_message(_("Connecting with \"%s\"..."), Tunnel); diff --git a/copy.c b/copy.c index 7dfe711389d..86d3c35903d 100644 --- a/copy.c +++ b/copy.c @@ -157,7 +157,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, mutt_debug(1, "WEED is %s\n", (flags & CH_WEED) ? "Set" : "Not"); - headers = safe_calloc(hdr_count, sizeof(char *)); + headers = mutt_mem_calloc(hdr_count, sizeof(char *)); /* Read all the headers into the array */ while (ftello(in) < off_end) @@ -195,7 +195,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, { int hlen = mutt_strlen(headers[x]); - safe_realloc(&headers[x], hlen + this_one_len + sizeof(char)); + mutt_mem_realloc(&headers[x], hlen + this_one_len + sizeof(char)); strcat(headers[x] + hlen, this_one); FREE(&this_one); } @@ -270,7 +270,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, { int blen = mutt_strlen(buf); - safe_realloc(&this_one, this_one_len + blen + sizeof(char)); + mutt_mem_realloc(&this_one, this_one_len + blen + sizeof(char)); strcat(this_one + this_one_len, buf); this_one_len += blen; } @@ -293,7 +293,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, { int hlen = mutt_strlen(headers[x]); - safe_realloc(&headers[x], hlen + this_one_len + sizeof(char)); + mutt_mem_realloc(&headers[x], hlen + this_one_len + sizeof(char)); strcat(headers[x] + hlen, this_one); FREE(&this_one); } @@ -899,7 +899,7 @@ static void format_address_header(char **h, struct Address *a) plen = linelen; buflen = linelen + 3; - safe_realloc(h, buflen); + mutt_mem_realloc(h, buflen); for (int count = 0; a; a = a->next, count++) { struct Address *tmp = a->next; @@ -932,7 +932,7 @@ static void format_address_header(char **h, struct Address *a) cbuflen = mutt_strlen(cbuf); c2buflen = mutt_strlen(c2buf); buflen += l + cbuflen + c2buflen; - safe_realloc(h, buflen); + mutt_mem_realloc(h, buflen); p = *h; strcat(p + plen, cbuf); plen += cbuflen; @@ -1034,7 +1034,7 @@ static int address_header_decode(char **h) *h = safe_strdup(s); else { - *h = safe_calloc(1, l + 2); + *h = mutt_mem_calloc(1, l + 2); strfcpy(*h, s, l + 1); format_address_header(h, a); } diff --git a/curs_lib.c b/curs_lib.c index 2daa0da8514..3c4ba2ecd6a 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -618,12 +618,12 @@ void mutt_progress_update(struct Progress *progress, long pos, int percent) void mutt_init_windows(void) { - MuttHelpWindow = safe_calloc(1, sizeof(struct MuttWindow)); - MuttIndexWindow = safe_calloc(1, sizeof(struct MuttWindow)); - MuttStatusWindow = safe_calloc(1, sizeof(struct MuttWindow)); - MuttMessageWindow = safe_calloc(1, sizeof(struct MuttWindow)); + MuttHelpWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + MuttIndexWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + MuttStatusWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + MuttMessageWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); #ifdef USE_SIDEBAR - MuttSidebarWindow = safe_calloc(1, sizeof(struct MuttWindow)); + MuttSidebarWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow)); #endif } @@ -931,7 +931,7 @@ int mutt_enter_fname_full(const char *prompt, char *buf, size_t blen, int buffy, } else { - char *pc = safe_malloc(mutt_strlen(prompt) + 3); + char *pc = mutt_mem_malloc(mutt_strlen(prompt) + 3); sprintf(pc, "%s: ", prompt); mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0); @@ -956,7 +956,7 @@ void mutt_unget_event(int ch, int op) tmp.op = op; if (UngetCount >= UngetLen) - safe_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event)); + mutt_mem_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event)); UngetKeyEvents[UngetCount++] = tmp; } @@ -985,7 +985,7 @@ void mutt_push_macro_event(int ch, int op) tmp.op = op; if (MacroBufferCount >= MacroBufferLen) - safe_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event)); + mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event)); MacroEvents[MacroBufferCount++] = tmp; } diff --git a/curs_main.c b/curs_main.c index 687f51e6478..5c1d1ab3ad7 100644 --- a/curs_main.c +++ b/curs_main.c @@ -372,7 +372,7 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun if (option(OPT_UNCOLLAPSE_NEW) && oldcount && check != MUTT_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) { - save_new = safe_malloc(sizeof(struct Header *) * (ctx->msgcount - oldcount)); + save_new = mutt_mem_malloc(sizeof(struct Header *) * (ctx->msgcount - oldcount)); for (int i = oldcount; i < ctx->msgcount; i++) save_new[i - oldcount] = ctx->hdrs[i]; } @@ -730,7 +730,7 @@ void mutt_draw_statusline(int cols, const char *buf, int buflen) if (!found) { chunks++; - safe_realloc(&syntax, chunks * sizeof(struct Syntax)); + mutt_mem_realloc(&syntax, chunks * sizeof(struct Syntax)); } i = chunks - 1; diff --git a/edit.c b/edit.c index 6027e64eca7..5ba30d953a1 100644 --- a/edit.c +++ b/edit.c @@ -96,12 +96,12 @@ static char **be_snarf_data(FILE *f, char **buf, int *bufmax, int *buflen, break; bytes -= mutt_strlen(p); if (*bufmax == *buflen) - safe_realloc(&buf, sizeof(char *) * (*bufmax += 25)); + mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25)); buf[(*buflen)++] = safe_strdup(tmp); } if (buf && *bufmax == *buflen) { /* Do not smash memory past buf */ - safe_realloc(&buf, sizeof(char *) * (++*bufmax)); + mutt_mem_realloc(&buf, sizeof(char *) * (++*bufmax)); } if (buf) buf[*buflen] = NULL; @@ -182,7 +182,7 @@ static char **be_include_messages(char *msg, char **buf, int *bufmax, } if (*bufmax == *buflen) - safe_realloc(&buf, sizeof(char *) * (*bufmax += 25)); + mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25)); buf[(*buflen)++] = safe_strdup(tmp); bytes = Context->hdrs[n]->content->length; @@ -196,7 +196,7 @@ static char **be_include_messages(char *msg, char **buf, int *bufmax, buf = be_snarf_data(Context->fp, buf, bufmax, buflen, offset, bytes, pfx); if (*bufmax == *buflen) - safe_realloc(&buf, sizeof(char *) * (*bufmax += 25)); + mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25)); buf[(*buflen)++] = safe_strdup("\n"); } else @@ -494,7 +494,7 @@ int mutt_builtin_editor(const char *path, struct Header *msg, struct Header *cur { safe_strcat(tmp, sizeof(tmp), "\n"); if (buflen == bufmax) - safe_realloc(&buf, sizeof(char *) * (bufmax += 25)); + mutt_mem_realloc(&buf, sizeof(char *) * (bufmax += 25)); buf[buflen++] = safe_strdup(tmp[1] == '~' ? tmp + 1 : tmp); } diff --git a/enter.c b/enter.c index c5ff00cd2c8..ae231ab35dc 100644 --- a/enter.c +++ b/enter.c @@ -76,7 +76,7 @@ static void replace_part(struct EnterState *state, size_t from, char *buf) if (savelen) { - savebuf = safe_calloc(savelen, sizeof(wchar_t)); + savebuf = mutt_mem_calloc(savelen, sizeof(wchar_t)); memcpy(savebuf, state->wbuf + state->curpos, savelen * sizeof(wchar_t)); } @@ -89,7 +89,7 @@ static void replace_part(struct EnterState *state, size_t from, char *buf) if (state->curpos + savelen > state->wbuflen) { state->wbuflen = state->curpos + savelen; - safe_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t)); + mutt_mem_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t)); } /* Restore suffix */ @@ -478,7 +478,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, int mul if (!mutt_complete(buf, buflen)) { templen = state->lastchar - i; - safe_realloc(&tempbuf, templen * sizeof(wchar_t)); + mutt_mem_realloc(&tempbuf, templen * sizeof(wchar_t)); } else BEEP(); @@ -597,7 +597,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, int mul if (!mutt_complete(buf, buflen)) { templen = state->lastchar; - safe_realloc(&tempbuf, templen * sizeof(wchar_t)); + mutt_mem_realloc(&tempbuf, templen * sizeof(wchar_t)); memcpy(tempbuf, state->wbuf, templen * sizeof(wchar_t)); } else @@ -709,7 +709,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, int mul { char **tfiles = NULL; *numfiles = 1; - tfiles = safe_calloc(*numfiles, sizeof(char *)); + tfiles = mutt_mem_calloc(*numfiles, sizeof(char *)); mutt_expand_path(buf, buflen); tfiles[0] = safe_strdup(buf); *files = tfiles; @@ -722,7 +722,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, int mul if (state->lastchar >= state->wbuflen) { state->wbuflen = state->lastchar + 20; - safe_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t)); + mutt_mem_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t)); } memmove(state->wbuf + state->curpos + 1, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof(wchar_t)); diff --git a/enter_state.h b/enter_state.h index c4d2474e960..b52d45ba043 100644 --- a/enter_state.h +++ b/enter_state.h @@ -41,7 +41,7 @@ struct EnterState static inline struct EnterState *mutt_new_enter_state(void) { - return safe_calloc(1, sizeof(struct EnterState)); + return mutt_mem_calloc(1, sizeof(struct EnterState)); } #endif /* _MUTT_ENTER_STATE_H */ diff --git a/envelope.c b/envelope.c index 1e36ba26455..88d2f280b9b 100644 --- a/envelope.c +++ b/envelope.c @@ -46,7 +46,7 @@ */ struct Envelope *mutt_new_envelope(void) { - struct Envelope *e = safe_calloc(1, sizeof(struct Envelope)); + struct Envelope *e = mutt_mem_calloc(1, sizeof(struct Envelope)); STAILQ_INIT(&e->references); STAILQ_INIT(&e->in_reply_to); STAILQ_INIT(&e->userhdrs); diff --git a/group.c b/group.c index 909d128c0af..faf8fd0429c 100644 --- a/group.c +++ b/group.c @@ -42,7 +42,7 @@ struct Group *mutt_pattern_group(const char *k) if (!p) { mutt_debug(2, "mutt_pattern_group: Creating group %s.\n", k); - p = safe_calloc(1, sizeof(struct Group)); + p = mutt_mem_calloc(1, sizeof(struct Group)); p->name = safe_strdup(k); mutt_hash_insert(Groups, p->name, p); } @@ -88,7 +88,7 @@ void mutt_group_context_add(struct GroupContext **ctx, struct Group *group) return; } - *ctx = safe_calloc(1, sizeof(struct GroupContext)); + *ctx = mutt_mem_calloc(1, sizeof(struct GroupContext)); (*ctx)->g = group; } diff --git a/handler.c b/handler.c index aff2cde2330..85fd2d6e1a8 100644 --- a/handler.c +++ b/handler.c @@ -613,7 +613,7 @@ static void enriched_flush(struct EnrichedState *stte, int wrap) if (stte->line_used > stte->line_max) { stte->line_max = stte->line_used; - safe_realloc(&stte->line, (stte->line_max + 1) * sizeof(wchar_t)); + mutt_mem_realloc(&stte->line, (stte->line_max + 1) * sizeof(wchar_t)); } wcscat(stte->line, stte->buffer); stte->line_len += stte->word_len; @@ -632,7 +632,7 @@ static void enriched_putwc(wchar_t c, struct EnrichedState *stte) if (stte->tag_level[RICH_COLOR]) { if (stte->param_used + 1 >= stte->param_len) - safe_realloc(&stte->param, (stte->param_len += STRING) * sizeof(wchar_t)); + mutt_mem_realloc(&stte->param, (stte->param_len += STRING) * sizeof(wchar_t)); stte->param[stte->param_used++] = c; } @@ -643,7 +643,7 @@ static void enriched_putwc(wchar_t c, struct EnrichedState *stte) if (stte->buff_len < stte->buff_used + 3) { stte->buff_len += LONG_STRING; - safe_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t)); + mutt_mem_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t)); } if ((!stte->tag_level[RICH_NOFILL] && iswspace(c)) || c == (wchar_t) '\0') @@ -698,7 +698,7 @@ static void enriched_puts(const char *s, struct EnrichedState *stte) if (stte->buff_len < stte->buff_used + mutt_strlen(s)) { stte->buff_len += LONG_STRING; - safe_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t)); + mutt_mem_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t)); } c = s; while (*c) @@ -814,8 +814,8 @@ static int text_enriched_handler(struct Body *a, struct State *s) (MuttIndexWindow->cols - 4) : ((MuttIndexWindow->cols - 4) < 72) ? (MuttIndexWindow->cols - 4) : 72); stte.line_max = stte.wrap_margin * 4; - stte.line = safe_calloc(1, (stte.line_max + 1) * sizeof(wchar_t)); - stte.param = safe_calloc(1, (STRING) * sizeof(wchar_t)); + stte.line = mutt_mem_calloc(1, (stte.line_max + 1) * sizeof(wchar_t)); + stte.param = mutt_mem_calloc(1, (STRING) * sizeof(wchar_t)); stte.param_len = STRING; stte.param_used = 0; diff --git a/hcache/bdb.c b/hcache/bdb.c index 830eeab58dc..1f9d594dcaf 100644 --- a/hcache/bdb.c +++ b/hcache/bdb.c @@ -77,7 +77,7 @@ static void *hcache_bdb_open(const char *path) u_int32_t createflags = DB_CREATE; int pagesize; - struct HcacheDbCtx *ctx = safe_malloc(sizeof(struct HcacheDbCtx)); + struct HcacheDbCtx *ctx = mutt_mem_malloc(sizeof(struct HcacheDbCtx)); if (mutt_atoi(HeaderCachePageSize, &pagesize) < 0 || pagesize <= 0) pagesize = 16384; diff --git a/hcache/hcache.c b/hcache/hcache.c index 906bd9a3549..d9f4377df71 100644 --- a/hcache/hcache.c +++ b/hcache/hcache.c @@ -140,7 +140,7 @@ static void *lazy_malloc(size_t siz) if (siz < 4096) siz = 4096; - return safe_malloc(siz); + return mutt_mem_malloc(siz); } static void lazy_realloc(void *ptr, size_t siz) @@ -150,7 +150,7 @@ static void lazy_realloc(void *ptr, size_t siz) if (p != NULL && siz < 4096) return; - safe_realloc(ptr, siz); + mutt_mem_realloc(ptr, siz); } static unsigned char *dump_int(unsigned int i, unsigned char *d, int *off) @@ -217,7 +217,7 @@ static void restore_char(char **c, const unsigned char *d, int *off, bool conver return; } - *c = safe_malloc(size); + *c = mutt_mem_malloc(size); memcpy(*c, d + *off, size); if (convert && !is_ascii(*c, size)) { @@ -336,7 +336,7 @@ static void restore_buffer(struct Buffer **b, const unsigned char *d, int *off, return; } - *b = safe_malloc(sizeof(struct Buffer)); + *b = mutt_mem_malloc(sizeof(struct Buffer)); restore_char(&(*b)->data, d, off, convert); restore_int(&offset, d, off); @@ -377,7 +377,7 @@ static void restore_parameter(struct Parameter **p, const unsigned char *d, while (counter) { - *p = safe_malloc(sizeof(struct Parameter)); + *p = mutt_mem_malloc(sizeof(struct Parameter)); restore_char(&(*p)->attribute, d, off, false); restore_char(&(*p)->value, d, off, convert); p = &(*p)->next; @@ -726,7 +726,7 @@ static char *get_foldername(const char *folder) /* if the folder is local, canonify the path to avoid * to ensure equivalent paths share the hcache */ - p = safe_malloc(PATH_MAX + 1); + p = mutt_mem_malloc(PATH_MAX + 1); if (!realpath(path, p)) mutt_str_replace(&p, path); @@ -739,7 +739,7 @@ header_cache_t *mutt_hcache_open(const char *path, const char *folder, hcache_na if (!ops) return NULL; - header_cache_t *h = safe_calloc(1, sizeof(header_cache_t)); + header_cache_t *h = mutt_mem_calloc(1, sizeof(header_cache_t)); /* Calculate the current hcache version from dynamic configuration */ if (hcachever == 0x0) diff --git a/hcache/lmdb.c b/hcache/lmdb.c index 50698e87358..512fae10e59 100644 --- a/hcache/lmdb.c +++ b/hcache/lmdb.c @@ -108,7 +108,7 @@ static void *hcache_lmdb_open(const char *path) { int rc; - struct HcacheLmdbCtx *ctx = safe_calloc(1, sizeof(struct HcacheLmdbCtx)); + struct HcacheLmdbCtx *ctx = mutt_mem_calloc(1, sizeof(struct HcacheLmdbCtx)); rc = mdb_env_create(&ctx->env); if (rc != MDB_SUCCESS) diff --git a/header.c b/header.c index 01b8a252ce5..7170326e8d6 100644 --- a/header.c +++ b/header.c @@ -378,7 +378,7 @@ void mutt_free_header(struct Header **h) struct Header *mutt_new_header(void) { - struct Header *h = safe_calloc(1, sizeof(struct Header)); + struct Header *h = mutt_mem_calloc(1, sizeof(struct Header)); #ifdef MIXMASTER STAILQ_INIT(&h->chain); #endif diff --git a/history.c b/history.c index 1f05d5fcf66..29069d4eead 100644 --- a/history.c +++ b/history.c @@ -107,7 +107,7 @@ static void init_history(struct History *h) } if (History) - h->hist = safe_calloc(History + 1, sizeof(char *)); + h->hist = mutt_mem_calloc(History + 1, sizeof(char *)); h->cur = 0; h->last = 0; diff --git a/hook.c b/hook.c index 98c355ee922..5d97ff78a93 100644 --- a/hook.c +++ b/hook.c @@ -226,7 +226,7 @@ int mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, else if (~data & MUTT_GLOBALHOOK) /* NOT a global hook */ { /* Hooks not allowing full patterns: Check syntax of regex */ - rx = safe_malloc(sizeof(regex_t)); + rx = mutt_mem_malloc(sizeof(regex_t)); #ifdef MUTT_CRYPTHOOK if ((rc = REGCOMP(rx, NONULL(pattern.data), ((data & (MUTT_CRYPTHOOK | MUTT_CHARSETHOOK | MUTT_ICONVHOOK)) ? REG_ICASE : 0))) != 0) @@ -241,7 +241,7 @@ int mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, } } - ptr = safe_calloc(1, sizeof(struct Hook)); + ptr = mutt_mem_calloc(1, sizeof(struct Hook)); ptr->type = data; ptr->command = command.data; ptr->pattern = pat; @@ -337,7 +337,7 @@ void mutt_folder_hook(const char *path) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); mutt_buffer_init(&token); TAILQ_FOREACH(tmp, &Hooks, entries) { @@ -392,7 +392,7 @@ void mutt_message_hook(struct Context *ctx, struct Header *hdr, int type) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); mutt_buffer_init(&token); memset(&cache, 0, sizeof(cache)); TAILQ_FOREACH(hook, &Hooks, entries) @@ -557,7 +557,7 @@ void mutt_account_hook(const char *url) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); mutt_buffer_init(&token); TAILQ_FOREACH(hook, &Hooks, entries) diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index 134cb290046..b4d3661f944 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -120,7 +120,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapData *idata, const char *method) mutt_message(_("Authenticating (%s)..."), mech); bufsize = ((olen * 2) > LONG_STRING) ? (olen * 2) : LONG_STRING; - buf = safe_malloc(bufsize); + buf = mutt_mem_malloc(bufsize); snprintf(buf, bufsize, "AUTHENTICATE %s", mech); if (mutt_bit_isset(idata->capabilities, SASL_IR) && client_start) @@ -162,7 +162,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapData *idata, const char *method) if (len > bufsize) { bufsize = len; - safe_realloc(&buf, bufsize); + mutt_mem_realloc(&buf, bufsize); } /* For sasl_decode64, the fourth parameter, outmax, doesn't * include space for the trailing null */ @@ -196,7 +196,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapData *idata, const char *method) if ((olen * 2) > bufsize) { bufsize = olen * 2; - safe_realloc(&buf, bufsize); + mutt_mem_realloc(&buf, bufsize); } if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK) { diff --git a/imap/browse.c b/imap/browse.c index 333aa0032e7..f8f46bfcf10 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -79,7 +79,7 @@ static void add_folder(char delim, char *folder, int noselect, int noinferiors, if (state->entrylen + 1 == state->entrymax) { - safe_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256)); + mutt_mem_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256)); memset(state->entry + state->entrylen, 0, (sizeof(struct FolderFile) * (state->entrymax - state->entrylen))); } diff --git a/imap/command.c b/imap/command.c index c02f3e2dcfc..26ce6301e89 100644 --- a/imap/command.c +++ b/imap/command.c @@ -943,7 +943,7 @@ int imap_cmd_step(struct ImapData *idata) { if (len == idata->blen) { - safe_realloc(&idata->buf, idata->blen + IMAP_CMD_BUFSIZE); + mutt_mem_realloc(&idata->buf, idata->blen + IMAP_CMD_BUFSIZE); idata->blen = idata->blen + IMAP_CMD_BUFSIZE; mutt_debug(3, "imap_cmd_step: grew buffer to %u bytes\n", idata->blen); } @@ -969,7 +969,7 @@ int imap_cmd_step(struct ImapData *idata) /* don't let one large string make cmd->buf hog memory forever */ if ((idata->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) { - safe_realloc(&idata->buf, IMAP_CMD_BUFSIZE); + mutt_mem_realloc(&idata->buf, IMAP_CMD_BUFSIZE); idata->blen = IMAP_CMD_BUFSIZE; mutt_debug(3, "imap_cmd_step: shrank buffer to %u bytes\n", idata->blen); } diff --git a/imap/imap.c b/imap/imap.c index 1b5d0cb39a0..7792caae441 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1231,7 +1231,7 @@ int imap_exec_msgset(struct ImapData *idata, const char *pre, const char *post, if (Sort != SORT_ORDER) { hdrs = idata->ctx->hdrs; - idata->ctx->hdrs = safe_malloc(idata->ctx->msgcount * sizeof(struct Header *)); + idata->ctx->hdrs = mutt_mem_malloc(idata->ctx->msgcount * sizeof(struct Header *)); memcpy(idata->ctx->hdrs, hdrs, idata->ctx->msgcount * sizeof(struct Header *)); Sort = SORT_ORDER; @@ -1644,7 +1644,7 @@ struct ImapStatus *imap_mboxcache_get(struct ImapData *idata, const char *mbox, /* lame */ if (create) { - struct ImapStatus *scache = safe_calloc(1, sizeof(struct ImapStatus)); + struct ImapStatus *scache = mutt_mem_calloc(1, sizeof(struct ImapStatus)); scache->name = (char *) mbox; mutt_list_insert_tail(&idata->mboxcache, (char *) scache); status = imap_mboxcache_get(idata, mbox, 0); @@ -2213,8 +2213,8 @@ static int imap_open_mailbox(struct Context *ctx) ctx->readonly = true; ctx->hdrmax = count; - ctx->hdrs = safe_calloc(count, sizeof(struct Header *)); - ctx->v2r = safe_calloc(count, sizeof(int)); + ctx->hdrs = mutt_mem_calloc(count, sizeof(struct Header *)); + ctx->v2r = mutt_mem_calloc(count, sizeof(int)); ctx->msgcount = 0; if (count && (imap_read_headers(idata, 1, count) < 0)) @@ -2500,7 +2500,7 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) if (Sort != SORT_ORDER) { hdrs = ctx->hdrs; - ctx->hdrs = safe_malloc(ctx->msgcount * sizeof(struct Header *)); + ctx->hdrs = mutt_mem_malloc(ctx->msgcount * sizeof(struct Header *)); memcpy(ctx->hdrs, hdrs, ctx->msgcount * sizeof(struct Header *)); Sort = SORT_ORDER; diff --git a/imap/message.c b/imap/message.c index 9bce11f2c5d..71bb35fde66 100644 --- a/imap/message.c +++ b/imap/message.c @@ -77,7 +77,7 @@ */ static struct ImapHeaderData *new_header_data(void) { - struct ImapHeaderData *d = safe_calloc(1, sizeof(struct ImapHeaderData)); + struct ImapHeaderData *d = mutt_mem_calloc(1, sizeof(struct ImapHeaderData)); return d; } @@ -492,10 +492,10 @@ static void alloc_msn_index(struct ImapData *idata, unsigned int msn_count) new_size = msn_count + 25; if (!idata->msn_index) - idata->msn_index = safe_calloc(new_size, sizeof(struct Header *)); + idata->msn_index = mutt_mem_calloc(new_size, sizeof(struct Header *)); else { - safe_realloc(&idata->msn_index, sizeof(struct Header *) * new_size); + mutt_mem_realloc(&idata->msn_index, sizeof(struct Header *) * new_size); memset(idata->msn_index + idata->msn_index_size, 0, sizeof(struct Header *) * (new_size - idata->msn_index_size)); } diff --git a/imap/utf7.c b/imap/utf7.c index a944ca522df..421005716f1 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -91,7 +91,7 @@ static char *utf7_to_utf8(const char *u7, size_t u7len, char **u8, size_t *u8len char *buf = NULL, *p = NULL; int b, ch, k; - p = buf = safe_malloc(u7len + u7len / 8 + 1); + p = buf = mutt_mem_malloc(u7len + u7len / 8 + 1); for (; u7len; u7++, u7len--) { @@ -162,7 +162,7 @@ static char *utf7_to_utf8(const char *u7, size_t u7len, char **u8, size_t *u8len if (u8len) *u8len = p - buf; - safe_realloc(&buf, p - buf); + mutt_mem_realloc(&buf, p - buf); if (u8) *u8 = buf; return buf; @@ -197,7 +197,7 @@ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len * In the worst case we convert 2 chars to 7 chars. For example: * "\x10&\x10&..." -> "&ABA-&-&ABA-&-...". */ - p = buf = safe_malloc((u8len / 2) * 7 + 6); + p = buf = mutt_mem_malloc((u8len / 2) * 7 + 6); while (u8len) { @@ -302,7 +302,7 @@ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len *p++ = '\0'; if (u7len) *u7len = p - buf; - safe_realloc(&buf, p - buf); + mutt_mem_realloc(&buf, p - buf); if (u7) *u7 = buf; return buf; diff --git a/imap/util.c b/imap/util.c index 098b41c9040..a55313e997b 100644 --- a/imap/util.c +++ b/imap/util.c @@ -509,8 +509,8 @@ int imap_mxcmp(const char *mx1, const char *mx2) if ((mutt_strcasecmp(mx1, "INBOX") == 0) && (mutt_strcasecmp(mx2, "INBOX") == 0)) return 0; - b1 = safe_malloc(strlen(mx1) + 1); - b2 = safe_malloc(strlen(mx2) + 1); + b1 = mutt_mem_malloc(strlen(mx1) + 1); + b2 = mutt_mem_malloc(strlen(mx2) + 1); imap_fix_path(NULL, mx1, b1, strlen(mx1) + 1); imap_fix_path(NULL, mx2, b2, strlen(mx2) + 1); @@ -611,14 +611,14 @@ void imap_error(const char *where, const char *msg) */ struct ImapData *imap_new_idata(void) { - struct ImapData *idata = safe_calloc(1, sizeof(struct ImapData)); + struct ImapData *idata = mutt_mem_calloc(1, sizeof(struct ImapData)); idata->cmdbuf = mutt_buffer_new(); if (!idata->cmdbuf) FREE(&idata); idata->cmdslots = ImapPipelineDepth + 2; - idata->cmds = safe_calloc(idata->cmdslots, sizeof(*idata->cmds)); + idata->cmds = mutt_mem_calloc(idata->cmdslots, sizeof(*idata->cmds)); if (!idata->cmds) { mutt_buffer_free(&idata->cmdbuf); diff --git a/init.c b/init.c index 40eb855c671..af81e83e22b 100644 --- a/init.c +++ b/init.c @@ -100,7 +100,7 @@ static void myvar_set(const char *var, const char *val) break; if (!*cur) - *cur = safe_calloc(1, sizeof(struct MyVar)); + *cur = mutt_mem_calloc(1, sizeof(struct MyVar)); if (!(*cur)->name) (*cur)->name = safe_strdup(var); @@ -167,7 +167,7 @@ static int parse_regex(int idx, struct Buffer *tmp, struct Buffer *err) } } - rx = safe_malloc(sizeof(regex_t)); + rx = mutt_mem_malloc(sizeof(regex_t)); e = REGCOMP(rx, p, flags); if (e != 0) { @@ -302,7 +302,7 @@ static struct MbTable *parse_mbtable(const char *s) mbstate_t mbstate; char *d = NULL; - t = safe_calloc(1, sizeof(struct MbTable)); + t = mutt_mem_calloc(1, sizeof(struct MbTable)); slen = mutt_strlen(s); if (!slen) return t; @@ -310,8 +310,8 @@ static struct MbTable *parse_mbtable(const char *s) t->orig_str = safe_strdup(s); /* This could be more space efficient. However, being used on tiny * strings (ToChars and StatusChars), the overhead is not great. */ - t->chars = safe_calloc(slen, sizeof(char *)); - d = t->segmented_str = safe_calloc(slen * 2, sizeof(char)); + t->chars = mutt_mem_calloc(slen, sizeof(char *)); + d = t->segmented_str = mutt_mem_calloc(slen * 2, sizeof(char)); memset(&mbstate, 0, sizeof(mbstate)); while (slen && (k = mbrtowc(NULL, s, slen, &mbstate))) @@ -647,7 +647,7 @@ int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags) { expnlen = mutt_strlen(expn.data); tok->dsize = expnlen + mutt_strlen(tok->dptr) + 1; - ptr = safe_malloc(tok->dsize); + ptr = mutt_mem_malloc(tok->dsize); memcpy(ptr, expn.data, expnlen); strcpy(ptr + expnlen, tok->dptr); if (tok->destroy) @@ -767,7 +767,7 @@ static void add_to_stailq(struct ListHead *head, const char *str) static struct RegexList *new_regex_list(void) { - return safe_calloc(1, sizeof(struct RegexList)); + return mutt_mem_calloc(1, sizeof(struct RegexList)); } int mutt_add_to_regex_list(struct RegexList **list, const char *s, int flags, @@ -856,7 +856,7 @@ static int remove_from_replace_list(struct ReplaceList **list, const char *pat) static struct ReplaceList *new_replace_list(void) { - return safe_calloc(1, sizeof(struct ReplaceList)); + return mutt_mem_calloc(1, sizeof(struct ReplaceList)); } static int add_to_replace_list(struct ReplaceList **list, const char *pat, @@ -1555,7 +1555,7 @@ static int parse_attach_list(struct Buffer *buf, struct Buffer *s, if (!buf->data || *buf->data == '\0') continue; - a = safe_malloc(sizeof(struct AttachMatch)); + a = mutt_mem_malloc(sizeof(struct AttachMatch)); /* some cheap hacks that I expect to remove */ if (mutt_strcasecmp(buf->data, "any") == 0) @@ -1577,7 +1577,7 @@ static int parse_attach_list(struct Buffer *buf, struct Buffer *s, } len = strlen(a->minor); - tmpminor = safe_malloc(len + 3); + tmpminor = mutt_mem_malloc(len + 3); strcpy(&tmpminor[1], a->minor); tmpminor[0] = '^'; tmpminor[len + 1] = '$'; @@ -1915,7 +1915,7 @@ static int parse_alias(struct Buffer *buf, struct Buffer *s, unsigned long data, if (!tmp) { /* create a new alias */ - tmp = safe_calloc(1, sizeof(struct Alias)); + tmp = mutt_mem_calloc(1, sizeof(struct Alias)); tmp->name = safe_strdup(buf->data); /* give the main addressbook code a chance */ if (CurrentMenu == MENU_ALIAS) @@ -2148,7 +2148,7 @@ static void restore_default(struct Option *p) int retval; char *s = (char *) p->init; - pp->regex = safe_calloc(1, sizeof(regex_t)); + pp->regex = mutt_mem_calloc(1, sizeof(regex_t)); pp->pattern = safe_strdup((char *) p->init); if (mutt_strcmp(p->option, "mask") != 0) flags |= mutt_which_case((const char *) p->init); @@ -2398,7 +2398,7 @@ void mutt_envlist_set(const char *name, const char *value, bool overwrite) /* If not found, add new slot */ else { - safe_realloc(&envlist, sizeof(char *) * (count + 2)); + mutt_mem_realloc(&envlist, sizeof(char *) * (count + 2)); envlist[count] = safe_strdup(work); envlist[count + 1] = NULL; } @@ -2472,7 +2472,7 @@ static int parse_setenv(struct Buffer *tmp, struct Buffer *s, count++; } *save = NULL; - safe_realloc(&envlist, sizeof(char *) * (count + 1)); + mutt_mem_realloc(&envlist, sizeof(char *) * (count + 1)); return 0; } envp++; @@ -3361,7 +3361,7 @@ static void matches_ensure_morespace(int current) extra_space = Matches_listsize - base_space; extra_space *= 2; space = base_space + extra_space; - safe_realloc(&Matches, space * sizeof(char *)); + mutt_mem_realloc(&Matches, space * sizeof(char *)); memset(&Matches[current + 1], 0, space - current); Matches_listsize = space; } @@ -3647,7 +3647,7 @@ static int complete_all_nm_tags(const char *pt) FREE(&nm_tags); } /* Allocate a new list, with sentinel. */ - nm_tags = safe_malloc((tag_count_1 + 1) * sizeof(char *)); + nm_tags = mutt_mem_malloc((tag_count_1 + 1) * sizeof(char *)); nm_tags[tag_count_1] = NULL; /* Get all the tags. */ @@ -3882,7 +3882,7 @@ int mutt_query_variables(struct ListHead *queries) mutt_buffer_init(&token); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); struct ListNode *np; STAILQ_FOREACH(np, queries, entries) @@ -3918,7 +3918,7 @@ int mutt_dump_variables(int hide_sensitive) mutt_buffer_init(&token); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); for (int i = 0; MuttVars[i].option; i++) { @@ -3954,7 +3954,7 @@ static int execute_commands(struct ListHead *p) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); mutt_buffer_init(&token); struct ListNode *np; STAILQ_FOREACH(np, p, entries) @@ -4018,7 +4018,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); err.dptr = err.data; Groups = mutt_hash_create(1031, 0); @@ -4112,12 +4112,12 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) /* now get FQDN. Use configured domain first, DNS next, then uname */ #ifdef DOMAIN /* we have a compile-time domain name, use that for Hostname */ - Hostname = safe_malloc(mutt_strlen(DOMAIN) + mutt_strlen(ShortHostname) + 2); + Hostname = mutt_mem_malloc(mutt_strlen(DOMAIN) + mutt_strlen(ShortHostname) + 2); sprintf(Hostname, "%s.%s", NONULL(ShortHostname), DOMAIN); #else if (!(getdnsdomainname(buffer, sizeof(buffer)))) { - Hostname = safe_malloc(mutt_strlen(buffer) + mutt_strlen(ShortHostname) + 2); + Hostname = mutt_mem_malloc(mutt_strlen(buffer) + mutt_strlen(ShortHostname) + 2); sprintf(Hostname, "%s.%s", NONULL(ShortHostname), buffer); } else @@ -4205,7 +4205,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) mutt_set_langinfo_charset(); mutt_set_charset(Charset); - Matches = safe_calloc(Matches_listsize, sizeof(char *)); + Matches = mutt_mem_calloc(Matches_listsize, sizeof(char *)); /* Set standard defaults */ for (int i = 0; MuttVars[i].option; i++) diff --git a/keymap.c b/keymap.c index ebc9ea3d2ef..730d3f62515 100644 --- a/keymap.c +++ b/keymap.c @@ -134,9 +134,9 @@ static struct Keymap *alloc_keys(int len, keycode_t *keys) { struct Keymap *p = NULL; - p = safe_calloc(1, sizeof(struct Keymap)); + p = mutt_mem_calloc(1, sizeof(struct Keymap)); p->len = len; - p->keys = safe_malloc(len * sizeof(keycode_t)); + p->keys = mutt_mem_malloc(len * sizeof(keycode_t)); memcpy(p->keys, keys, len * sizeof(keycode_t)); return p; } diff --git a/main.c b/main.c index 2104497647e..75f29027fc6 100644 --- a/main.c +++ b/main.c @@ -248,7 +248,7 @@ int main(int argc, char **argv, char **env) int count = 0; for (srcp = env; srcp && *srcp; srcp++) count++; - envlist = safe_calloc(count + 1, sizeof(char *)); + envlist = mutt_mem_calloc(count + 1, sizeof(char *)); for (srcp = env, dstp = envlist; srcp && *srcp; srcp++, dstp++) *dstp = safe_strdup(*srcp); } diff --git a/mbox.c b/mbox.c index 17c3830cc73..60cc273f6f0 100644 --- a/mbox.c +++ b/mbox.c @@ -1111,8 +1111,8 @@ static int mbox_sync_mailbox(struct Context *ctx, int *index_hint) offset -= (sizeof(MMDF_SEP) - 1); /* allocate space for the new offsets */ - newOffset = safe_calloc(ctx->msgcount - first, sizeof(struct MUpdate)); - oldOffset = safe_calloc(ctx->msgcount - first, sizeof(struct MUpdate)); + newOffset = mutt_mem_calloc(ctx->msgcount - first, sizeof(struct MUpdate)); + oldOffset = mutt_mem_calloc(ctx->msgcount - first, sizeof(struct MUpdate)); if (!ctx->quiet) { diff --git a/mbyte.c b/mbyte.c index 391c01737f5..c02620ed3b1 100644 --- a/mbyte.c +++ b/mbyte.c @@ -106,7 +106,7 @@ int mutt_filter_unprintable(char **s) mutt_buffer_addstr(b, scratch); } FREE(s); - *s = b->data ? b->data : safe_calloc(1, 1); + *s = b->data ? b->data : mutt_mem_calloc(1, 1); FREE(&b); return 0; } diff --git a/menu.c b/menu.c index 8797eb9e99c..45bc0316f35 100644 --- a/menu.c +++ b/menu.c @@ -800,7 +800,7 @@ void mutt_menu_init(void) struct Menu *mutt_new_menu(int menu) { - struct Menu *p = safe_calloc(1, sizeof(struct Menu)); + struct Menu *p = mutt_mem_calloc(1, sizeof(struct Menu)); if ((menu < 0) || (menu >= MENU_MAX)) menu = MENU_GENERIC; @@ -844,7 +844,7 @@ void mutt_push_current_menu(struct Menu *menu) if (MenuStackCount >= MenuStackLen) { MenuStackLen += 5; - safe_realloc(&MenuStack, MenuStackLen * sizeof(struct Menu *)); + mutt_mem_realloc(&MenuStack, MenuStackLen * sizeof(struct Menu *)); } MenuStack[MenuStackCount++] = menu; diff --git a/mh.c b/mh.c index 4f3d29f8047..3285159bd77 100644 --- a/mh.c +++ b/mh.c @@ -118,7 +118,7 @@ static void mhs_alloc(struct MhSequences *mhs, int i) { newmax = i + 128; j = mhs->flags ? mhs->max + 1 : 0; - safe_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1)); + mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1)); while (j <= newmax) mhs->flags[j++] = 0; @@ -884,7 +884,7 @@ static int maildir_parse_dir(struct Context *ctx, struct Maildir ***last, else h->path = safe_strdup(de->d_name); - entry = safe_calloc(1, sizeof(struct Maildir)); + entry = mutt_mem_calloc(1, sizeof(struct Maildir)); entry->h = h; entry->inode = de->d_ino; **last = entry; @@ -1272,7 +1272,7 @@ static int mh_read_dir(struct Context *ctx, const char *subdir) if (!ctx->data) { - ctx->data = safe_calloc(1, sizeof(struct MhData)); + ctx->data = mutt_mem_calloc(1, sizeof(struct MhData)); } data = mh_data(ctx); diff --git a/mutt/buffer.c b/mutt/buffer.c index 46f762427ef..f1c72499661 100644 --- a/mutt/buffer.c +++ b/mutt/buffer.c @@ -57,7 +57,7 @@ struct Buffer *mutt_buffer_new(void) { struct Buffer *b = NULL; - b = safe_malloc(sizeof(struct Buffer)); + b = mutt_mem_malloc(sizeof(struct Buffer)); mutt_buffer_init(b); @@ -128,7 +128,7 @@ static void mutt_buffer_add(struct Buffer *buf, const char *s, size_t len) { size_t offset = buf->dptr - buf->data; buf->dsize += (len < 128) ? 128 : len + 1; - safe_realloc(&buf->data, buf->dsize); + mutt_mem_realloc(&buf->data, buf->dsize); buf->dptr = buf->data + offset; } if (!buf->dptr) @@ -180,7 +180,7 @@ int mutt_buffer_printf(struct Buffer *buf, const char *fmt, ...) { blen = 128; buf->dsize += blen; - safe_realloc(&buf->data, buf->dsize); + mutt_mem_realloc(&buf->data, buf->dsize); buf->dptr = buf->data + doff; } len = vsnprintf(buf->dptr, blen, fmt, ap); @@ -190,7 +190,7 @@ int mutt_buffer_printf(struct Buffer *buf, const char *fmt, ...) if (blen < 128) blen = 128; buf->dsize += blen; - safe_realloc(&buf->data, buf->dsize); + mutt_mem_realloc(&buf->data, buf->dsize); buf->dptr = buf->data + doff; len = vsnprintf(buf->dptr, len, fmt, ap_retry); } diff --git a/mutt/file.c b/mutt/file.c index 2f0ffac9930..46c8e692765 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -643,7 +643,7 @@ char *mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) if (!s) { - s = safe_malloc(STRING); + s = mutt_mem_malloc(STRING); *size = STRING; } @@ -689,7 +689,7 @@ char *mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) /* There wasn't room for the line -- increase ``s'' */ offset = *size - 1; /* overwrite the terminating 0 */ *size += STRING; - safe_realloc(&s, *size); + mutt_mem_realloc(&s, *size); } } } diff --git a/mutt/hash.c b/mutt/hash.c index 9998233d988..81a3a38cfc0 100644 --- a/mutt/hash.c +++ b/mutt/hash.c @@ -150,11 +150,11 @@ static int cmp_int_key(union HashKey a, union HashKey b) */ static struct Hash *new_hash(int nelem) { - struct Hash *table = safe_calloc(1, sizeof(struct Hash)); + struct Hash *table = mutt_mem_calloc(1, sizeof(struct Hash)); if (nelem == 0) nelem = 2; table->nelem = nelem; - table->table = safe_calloc(nelem, sizeof(struct HashElem *)); + table->table = mutt_mem_calloc(nelem, sizeof(struct HashElem *)); return table; } @@ -171,7 +171,7 @@ static int union_hash_insert(struct Hash *table, union HashKey key, void *data) struct HashElem *ptr = NULL; unsigned int h; - ptr = safe_malloc(sizeof(struct HashElem)); + ptr = mutt_mem_malloc(sizeof(struct HashElem)); h = table->gen_hash(key, table->nelem); ptr->key = key; ptr->data = data; diff --git a/mutt/list.c b/mutt/list.c index 5885c7b22ee..34377d85684 100644 --- a/mutt/list.c +++ b/mutt/list.c @@ -51,7 +51,7 @@ */ struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s) { - struct ListNode *np = safe_calloc(1, sizeof(struct ListNode)); + struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode)); np->data = s; STAILQ_INSERT_HEAD(h, np, entries); return np; @@ -65,7 +65,7 @@ struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s) */ struct ListNode *mutt_list_insert_tail(struct ListHead *h, char *s) { - struct ListNode *np = safe_calloc(1, sizeof(struct ListNode)); + struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode)); np->data = s; STAILQ_INSERT_TAIL(h, np, entries); return np; @@ -80,7 +80,7 @@ struct ListNode *mutt_list_insert_tail(struct ListHead *h, char *s) */ struct ListNode *mutt_list_insert_after(struct ListHead *h, struct ListNode *n, char *s) { - struct ListNode *np = safe_calloc(1, sizeof(struct ListNode)); + struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode)); np->data = s; STAILQ_INSERT_AFTER(h, n, np, entries); return np; diff --git a/mutt/mbyte.c b/mutt/mbyte.c index 66ed7d8aa56..42b46d5df25 100644 --- a/mutt/mbyte.c +++ b/mutt/mbyte.c @@ -316,7 +316,7 @@ size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf) if (i >= wbuflen) { wbuflen = i + 20; - safe_realloc(&wbuf, wbuflen * sizeof(*wbuf)); + mutt_mem_realloc(&wbuf, wbuflen * sizeof(*wbuf)); } wbuf[i++] = wc; } @@ -325,7 +325,7 @@ size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf) if (i >= wbuflen) { wbuflen = i + 20; - safe_realloc(&wbuf, wbuflen * sizeof(*wbuf)); + mutt_mem_realloc(&wbuf, wbuflen * sizeof(*wbuf)); } wbuf[i++] = ReplacementChar; buf++; diff --git a/mutt/memory.c b/mutt/memory.c index 6e98e59f240..08f641916d1 100644 --- a/mutt/memory.c +++ b/mutt/memory.c @@ -28,12 +28,12 @@ * @note If any of the allocators fail, the user is notified and the program is * stopped immediately. * - * | Function | Description - * | :------------- | :----------------------------------- - * | safe_calloc() | Allocate zeroed memory on the heap - * | safe_free() | Release memory allocated on the heap - * | safe_malloc() | Allocate memory on the heap - * | safe_realloc() | Resize a block of memory on the heap + * | Function | Description + * | :----------------- | :----------------------------------- + * | mutt_mem_calloc() | Allocate zeroed memory on the heap + * | mutt_mem_free() | Release memory allocated on the heap + * | mutt_mem_malloc() | Allocate memory on the heap + * | mutt_mem_realloc() | Resize a block of memory on the heap */ #include "config.h" @@ -45,7 +45,7 @@ #include "message.h" /** - * safe_calloc - Allocate zeroed memory on the heap + * mutt_mem_calloc - Allocate zeroed memory on the heap * @param nmemb Number of blocks * @param size Size of blocks * @retval ptr Memory on the heap @@ -53,9 +53,9 @@ * @note This function will never return NULL. * It will print and error and exit the program. * - * The caller should call safe_free() to release the memory + * The caller should call mutt_mem_free() to release the memory */ -void *safe_calloc(size_t nmemb, size_t size) +void *mutt_mem_calloc(size_t nmemb, size_t size) { void *p = NULL; @@ -80,10 +80,10 @@ void *safe_calloc(size_t nmemb, size_t size) } /** - * safe_free - Release memory allocated on the heap + * mutt_mem_free - Release memory allocated on the heap * @param ptr Memory to release */ -void safe_free(void *ptr) +void mutt_mem_free(void *ptr) { if (!ptr) return; @@ -96,16 +96,16 @@ void safe_free(void *ptr) } /** - * safe_malloc - Allocate memory on the heap + * mutt_mem_malloc - Allocate memory on the heap * @param size Size of block to allocate * @retval ptr Memory on the heap * * @note This function will never return NULL. * It will print and error and exit the program. * - * The caller should call safe_free() to release the memory + * The caller should call mutt_mem_free() to release the memory */ -void *safe_malloc(size_t size) +void *mutt_mem_malloc(size_t size) { void *p = NULL; @@ -122,7 +122,7 @@ void *safe_malloc(size_t size) } /** - * safe_realloc - Resize a block of memory on the heap + * mutt_mem_realloc - Resize a block of memory on the heap * @param ptr Memory block to resize * @param size New size * @@ -131,7 +131,7 @@ void *safe_malloc(size_t size) * * If the new size is zero, the block will be freed. */ -void safe_realloc(void *ptr, size_t size) +void mutt_mem_realloc(void *ptr, size_t size) { void *r = NULL; void **p = (void **) ptr; diff --git a/mutt/memory.h b/mutt/memory.h index 52b461c15fb..ffd74a735c8 100644 --- a/mutt/memory.h +++ b/mutt/memory.h @@ -32,11 +32,11 @@ #define mutt_array_size(x) (sizeof(x) / sizeof((x)[0])) -void *safe_calloc(size_t nmemb, size_t size); -void safe_free(void *ptr); -void *safe_malloc(size_t size); -void safe_realloc(void *ptr, size_t size); +void *mutt_mem_calloc(size_t nmemb, size_t size); +void mutt_mem_free(void *ptr); +void *mutt_mem_malloc(size_t size); +void mutt_mem_realloc(void *ptr, size_t size); -#define FREE(x) safe_free(x) +#define FREE(x) mutt_mem_free(x) #endif /* _MUTT_MEMORY_H */ diff --git a/mutt/string.c b/mutt/string.c index 0f2694ebe06..e4ea87f3721 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -178,7 +178,7 @@ char *safe_strdup(const char *s) if (!s || !*s) return 0; l = strlen(s) + 1; - p = safe_malloc(l); + p = mutt_mem_malloc(l); memcpy(p, s, l); return p; } @@ -271,7 +271,7 @@ void mutt_str_append_item(char **str, const char *item, int sep) size_t sz = strlen(item); size_t ssz = *str ? strlen(*str) : 0; - safe_realloc(str, ssz + ((ssz && sep) ? 1 : 0) + sz + 1); + mutt_mem_realloc(str, ssz + ((ssz && sep) ? 1 : 0) + sz + 1); p = *str + ssz; if (sep && ssz) *p++ = sep; @@ -291,7 +291,7 @@ void mutt_str_adjust(char **p) { if (!p || !*p) return; - safe_realloc(p, strlen(*p) + 1); + mutt_mem_realloc(p, strlen(*p) + 1); } /** @@ -386,7 +386,7 @@ char *mutt_substrdup(const char *begin, const char *end) len = strlen(begin); } - p = safe_malloc(len + 1); + p = mutt_mem_malloc(len + 1); memcpy(p, begin, len); p[len] = '\0'; return p; diff --git a/mutt_idna.c b/mutt_idna.c index b5673f593d2..689af423262 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -186,7 +186,7 @@ static char *intl_to_local(char *orig_user, char *orig_domain, int flags) } } - mailbox = safe_malloc(mutt_strlen(local_user) + mutt_strlen(local_domain) + 2); + mailbox = mutt_mem_malloc(mutt_strlen(local_user) + mutt_strlen(local_domain) + 2); sprintf(mailbox, "%s@%s", NONULL(local_user), NONULL(local_domain)); cleanup: @@ -224,7 +224,7 @@ static char *local_to_intl(char *user, char *domain) } #endif /* HAVE_LIBIDN */ - mailbox = safe_malloc(mutt_strlen(intl_user) + mutt_strlen(intl_domain) + 2); + mailbox = mutt_mem_malloc(mutt_strlen(intl_user) + mutt_strlen(intl_domain) + 2); sprintf(mailbox, "%s@%s", NONULL(intl_user), NONULL(intl_domain)); cleanup: diff --git a/mutt_lua.c b/mutt_lua.c index 8b2cd84f5e8..cf912131cb4 100644 --- a/mutt_lua.c +++ b/mutt_lua.c @@ -70,7 +70,7 @@ static int lua_mutt_call(lua_State *l) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); if (lua_gettop(l) == 0) { @@ -274,7 +274,7 @@ static int lua_mutt_enter(lua_State *l) mutt_buffer_init(&token); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); if (mutt_parse_rc_line(buffer, &token, &err)) { diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 07f4ba67327..a99f444626f 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -232,7 +232,7 @@ static struct NmCtxData *new_ctxdata(const char *uri) if (!uri) return NULL; - data = safe_calloc(1, sizeof(struct NmCtxData)); + data = mutt_mem_calloc(1, sizeof(struct NmCtxData)); mutt_debug(1, "nm: initialize context data %p\n", (void *) data); data->db_limit = NmDbLimit; @@ -846,7 +846,7 @@ static char *nm2mutt_message_id(const char *id) if (!id) return NULL; sz = strlen(id) + 3; - mid = safe_malloc(sz); + mid = mutt_mem_malloc(sz); snprintf(mid, sz, "<%s>", id); return mid; @@ -861,7 +861,7 @@ static int init_header(struct Header *h, const char *path, notmuch_message_t *ms id = notmuch_message_get_message_id(msg); - h->data = safe_calloc(1, sizeof(struct NmHdrData)); + h->data = mutt_mem_calloc(1, sizeof(struct NmHdrData)); h->free_cb = deinit_header; /* diff --git a/mutt_tags.c b/mutt_tags.c index 28f8bd92478..1c199641971 100644 --- a/mutt_tags.c +++ b/mutt_tags.c @@ -146,7 +146,7 @@ static void driver_tags_add(struct TagHead *head, char *new_tag) { char *new_tag_transformed = mutt_hash_find(TagTransforms, new_tag); - struct TagNode *np = safe_calloc(1, sizeof(struct TagNode)); + struct TagNode *np = mutt_mem_calloc(1, sizeof(struct TagNode)); np->name = safe_strdup(new_tag); np->hidden = false; if (new_tag_transformed) diff --git a/muttlib.c b/muttlib.c index e40198c5e63..99f0984dd54 100644 --- a/muttlib.c +++ b/muttlib.c @@ -815,7 +815,7 @@ char *mutt_apply_replace(char *dbuf, size_t dlen, char *sbuf, struct ReplaceList /* If this pattern needs more matches, expand pmatch. */ if (l->nmatch > nmatch) { - safe_realloc(&pmatch, l->nmatch * sizeof(regmatch_t)); + mutt_mem_realloc(&pmatch, l->nmatch * sizeof(regmatch_t)); nmatch = l->nmatch; } @@ -1544,9 +1544,9 @@ const char *mutt_make_version(void) struct Regex *mutt_compile_regex(const char *s, int flags) { - struct Regex *pp = safe_calloc(1, sizeof(struct Regex)); + struct Regex *pp = mutt_mem_calloc(1, sizeof(struct Regex)); pp->pattern = safe_strdup(s); - pp->regex = safe_calloc(1, sizeof(regex_t)); + pp->regex = mutt_mem_calloc(1, sizeof(regex_t)); if (REGCOMP(pp->regex, NONULL(s), flags) != 0) mutt_free_regex(&pp); @@ -1638,7 +1638,7 @@ bool mutt_match_spam_list(const char *s, struct ReplaceList *l, char *text, int /* If this pattern needs more matches, expand pmatch. */ if (l->nmatch > nmatch) { - safe_realloc(&pmatch, l->nmatch * sizeof(regmatch_t)); + mutt_mem_realloc(&pmatch, l->nmatch * sizeof(regmatch_t)); nmatch = l->nmatch; } diff --git a/mx.c b/mx.c index 4dfbcbf0c8e..1783d45c335 100644 --- a/mx.c +++ b/mx.c @@ -414,7 +414,7 @@ struct Context *mx_open_mailbox(const char *path, int flags, struct Context *pct return NULL; if (!ctx) - ctx = safe_malloc(sizeof(struct Context)); + ctx = mutt_mem_malloc(sizeof(struct Context)); memset(ctx, 0, sizeof(struct Context)); ctx->path = safe_strdup(path); @@ -1135,7 +1135,7 @@ struct Message *mx_open_new_message(struct Context *dest, struct Header *hdr, in return NULL; } - msg = safe_calloc(1, sizeof(struct Message)); + msg = mutt_mem_calloc(1, sizeof(struct Message)); msg->write = true; if (hdr) @@ -1205,7 +1205,7 @@ struct Message *mx_open_message(struct Context *ctx, int msgno) return NULL; } - msg = safe_calloc(1, sizeof(struct Message)); + msg = mutt_mem_calloc(1, sizeof(struct Message)); if (ctx->mx_ops->open_msg(ctx, msg, msgno)) FREE(&msg); @@ -1267,13 +1267,13 @@ void mx_alloc_memory(struct Context *ctx) if (ctx->hdrs) { - safe_realloc(&ctx->hdrs, sizeof(struct Header *) * (ctx->hdrmax += 25)); - safe_realloc(&ctx->v2r, sizeof(int) * ctx->hdrmax); + mutt_mem_realloc(&ctx->hdrs, sizeof(struct Header *) * (ctx->hdrmax += 25)); + mutt_mem_realloc(&ctx->v2r, sizeof(int) * ctx->hdrmax); } else { - ctx->hdrs = safe_calloc((ctx->hdrmax += 25), sizeof(struct Header *)); - ctx->v2r = safe_calloc(ctx->hdrmax, sizeof(int)); + ctx->hdrs = mutt_mem_calloc((ctx->hdrmax += 25), sizeof(struct Header *)); + ctx->v2r = mutt_mem_calloc(ctx->hdrmax, sizeof(int)); } for (int i = ctx->msgcount; i < ctx->hdrmax; i++) { diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 5f115ac7dcb..bca944a5d66 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -870,7 +870,7 @@ int crypt_get_keys(struct Header *msg, char **keylist, int oppenc_mode) if (!oppenc_mode && self_encrypt && *self_encrypt) { keylist_size = mutt_strlen(*keylist); - safe_realloc(keylist, keylist_size + mutt_strlen(self_encrypt) + 2); + mutt_mem_realloc(keylist, keylist_size + mutt_strlen(self_encrypt) + 2); sprintf(*keylist + keylist_size, " %s", self_encrypt); } @@ -919,7 +919,7 @@ static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, in else { if ((*n % 5) == 0) - safe_realloc(signatures, (*n + 6) * sizeof(struct Body **)); + mutt_mem_realloc(signatures, (*n + 6) * sizeof(struct Body **)); (*signatures)[(*n)++] = a; } diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index b864190832e..6c0cff50c74 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -174,7 +174,7 @@ static void print_utf8(FILE *fp, const char *buf, size_t len) { char *tstr = NULL; - tstr = safe_malloc(len + 1); + tstr = mutt_mem_malloc(len + 1); memcpy(tstr, buf, len); tstr[len] = 0; @@ -333,7 +333,7 @@ static struct CryptKeyInfo *crypt_copy_key(struct CryptKeyInfo *key) { struct CryptKeyInfo *k = NULL; - k = safe_calloc(1, sizeof(*k)); + k = mutt_mem_calloc(1, sizeof(*k)); k->kobj = key->kobj; gpgme_key_ref(key->kobj); k->idx = key->idx; @@ -766,7 +766,7 @@ static gpgme_key_t *create_recipient_set(const char *keylist, gpgme_protocol_t p else err = gpgme_get_key(context, buf, &key, 0); - safe_realloc(&rset, sizeof(*rset) * (rset_n + 1)); + mutt_mem_realloc(&rset, sizeof(*rset) * (rset_n + 1)); if (!err) rset[rset_n++] = key; else @@ -782,7 +782,7 @@ static gpgme_key_t *create_recipient_set(const char *keylist, gpgme_protocol_t p } /* NULL terminate. */ - safe_realloc(&rset, sizeof(*rset) * (rset_n + 1)); + mutt_mem_realloc(&rset, sizeof(*rset) * (rset_n + 1)); rset[rset_n++] = NULL; if (context) @@ -1379,7 +1379,7 @@ static void show_fingerprint(gpgme_key_t key, struct State *state) return; is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP); - buf = safe_malloc(strlen(prefix) + strlen(s) * 4 + 2); + buf = mutt_mem_malloc(strlen(prefix) + strlen(s) * 4 + 2); strcpy(buf, prefix); p = buf + strlen(buf); if (is_pgp && strlen(s) == 40) @@ -3317,7 +3317,7 @@ static const char *parse_dn_part(struct DnArray *array, const char *string) n = s - string; if (!n) return NULL; /* empty key */ - array->key = safe_malloc(n + 1); + array->key = mutt_mem_malloc(n + 1); p = array->key; memcpy(p, string, n); /* fixme: trim trailing spaces */ p[n] = 0; @@ -3332,7 +3332,7 @@ static const char *parse_dn_part(struct DnArray *array, const char *string) if (!n || (n & 1)) return NULL; /* empty or odd number of digits */ n /= 2; - p = safe_malloc(n + 1); + p = mutt_mem_malloc(n + 1); array->value = (char *) p; for (s1 = string; n; s1 += 2, n--) sscanf(s1, "%2hhx", (unsigned char *) p++); @@ -3365,7 +3365,7 @@ static const char *parse_dn_part(struct DnArray *array, const char *string) n++; } - p = safe_malloc(n + 1); + p = mutt_mem_malloc(n + 1); array->value = (char *) p; for (s = string; n; s++, n--) { @@ -3400,7 +3400,7 @@ static struct DnArray *parse_dn(const char *string) size_t arrayidx, arraysize; arraysize = 7; /* C,ST,L,O,OU,CN,email */ - array = safe_malloc((arraysize + 1) * sizeof(*array)); + array = mutt_mem_malloc((arraysize + 1) * sizeof(*array)); arrayidx = 0; while (*string) { @@ -3410,11 +3410,11 @@ static struct DnArray *parse_dn(const char *string) break; /* ready */ if (arrayidx >= arraysize) { - /* neomutt lacks a real safe_realloc - so we need to copy */ + /* neomutt lacks a real mutt_mem_realloc - so we need to copy */ struct DnArray *a2 = NULL; arraysize += 5; - a2 = safe_malloc((arraysize + 1) * sizeof(*array)); + a2 = mutt_mem_malloc((arraysize + 1) * sizeof(*array)); for (int i = 0; i < arrayidx; i++) { a2[i].key = array[i].key; @@ -3913,7 +3913,7 @@ static char *list_to_pattern(struct ListHead *list) n++; /* delimiter or end of string */ } n++; /* make sure to allocate at least one byte */ - pattern = p = safe_calloc(1, n); + pattern = p = mutt_mem_calloc(1, n); STAILQ_FOREACH(np, list, entries) { s = np->data; @@ -3992,7 +3992,7 @@ static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int if (!n) goto no_pgphints; - char **patarr = safe_calloc(n + 1, sizeof(*patarr)); + char **patarr = mutt_mem_calloc(n + 1, sizeof(*patarr)); n = 0; STAILQ_FOREACH(np, hints, entries) { @@ -4030,7 +4030,7 @@ static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { - k = safe_calloc(1, sizeof(*k)); + k = mutt_mem_calloc(1, sizeof(*k)); k->kobj = key; gpgme_key_ref(k->kobj); k->idx = idx; @@ -4074,7 +4074,7 @@ static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { - k = safe_calloc(1, sizeof(*k)); + k = mutt_mem_calloc(1, sizeof(*k)); k->kobj = key; gpgme_key_ref(k->kobj); k->idx = idx; @@ -4156,7 +4156,7 @@ static struct CryptKeyInfo *crypt_select_key(struct CryptKeyInfo *keys, if (i == keymax) { keymax += 20; - safe_realloc(&key_table, sizeof(struct CryptKeyInfo *) * keymax); + mutt_mem_realloc(&key_table, sizeof(struct CryptKeyInfo *) * keymax); } key_table[i++] = k; @@ -4560,7 +4560,7 @@ static struct CryptKeyInfo *crypt_ask_for_key(char *tag, char *whatfor, short ab mutt_str_replace(&l->dflt, resp); else { - l = safe_malloc(sizeof(struct CryptCache)); + l = mutt_mem_malloc(sizeof(struct CryptCache)); l->next = id_defaults; id_defaults = l; l->what = safe_strdup(whatfor); @@ -4687,7 +4687,7 @@ static char *find_keys(struct Address *adrlist, unsigned int app, int oppenc_mod bypass_selection: keylist_size += mutt_strlen(keyID) + 4 + 1; - safe_realloc(&keylist, keylist_size); + mutt_mem_realloc(&keylist, keylist_size); sprintf(keylist + keylist_used, "%s0x%s%s", keylist_used ? " " : "", keyID, forced_valid ? "!" : ""); keylist_used = mutt_strlen(keylist); diff --git a/ncrypt/crypt_mod.c b/ncrypt/crypt_mod.c index 940ab4b1cc1..04fd38b91f0 100644 --- a/ncrypt/crypt_mod.c +++ b/ncrypt/crypt_mod.c @@ -43,7 +43,7 @@ modules = STAILQ_HEAD_INITIALIZER(modules); */ void crypto_module_register(struct CryptModuleSpecs *specs) { - struct CryptModule *module = safe_calloc(1, sizeof(struct CryptModule)); + struct CryptModule *module = mutt_mem_calloc(1, sizeof(struct CryptModule)); module->specs = specs; STAILQ_INSERT_HEAD(&modules, module, entries); } diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index 14e00c8d306..6ea64c4ee13 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -98,7 +98,7 @@ static void fix_uid(char *uid) char *ob = NULL; size_t ibl, obl; - buf = safe_malloc(n + 1); + buf = mutt_mem_malloc(n + 1); ib = uid; ibl = d - uid + 1; ob = buf; @@ -312,7 +312,7 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, int *is_subkey, struct PgpKe mutt_debug(2, "user ID: %s\n", NONULL(p)); - uid = safe_calloc(1, sizeof(struct PgpUid)); + uid = mutt_mem_calloc(1, sizeof(struct PgpUid)); fix_uid(p); uid->addr = safe_strdup(p); uid->trust = trust; @@ -364,7 +364,7 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, int *is_subkey, struct PgpKe /* merge temp key back into real key */ if (!(is_uid || is_fpr || (*is_subkey && option(OPT_PGP_IGNORE_SUBKEYS)))) - k = safe_malloc(sizeof(*k)); + k = mutt_mem_malloc(sizeof(*k)); memcpy(k, &tmp, sizeof(*k)); /* fixup parentship of uids after merging the temp key into * the real key */ diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 3592b0b17b1..29b20322d2e 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -1332,7 +1332,7 @@ char *pgp_find_keys(struct Address *adrlist, int oppenc_mode) bypass_selection: keylist_size += mutt_strlen(keyID) + 4; - safe_realloc(&keylist, keylist_size); + mutt_mem_realloc(&keylist, keylist_size); sprintf(keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", keyID); keylist_used = mutt_strlen(keylist); diff --git a/ncrypt/pgpkey.c b/ncrypt/pgpkey.c index 144b54ee88a..7d732b49d35 100644 --- a/ncrypt/pgpkey.c +++ b/ncrypt/pgpkey.c @@ -486,7 +486,7 @@ static struct PgpKeyInfo *pgp_select_key(struct PgpKeyInfo *keys, if (i == keymax) { keymax += 5; - safe_realloc(&KeyTable, sizeof(struct PgpUid *) * keymax); + mutt_mem_realloc(&KeyTable, sizeof(struct PgpUid *) * keymax); } KeyTable[i++] = a; @@ -690,7 +690,7 @@ struct PgpKeyInfo *pgp_ask_for_key(char *tag, char *whatfor, short abilities, en mutt_str_replace(&l->dflt, resp); else { - l = safe_malloc(sizeof(struct PgpCache)); + l = mutt_mem_malloc(sizeof(struct PgpCache)); l->next = id_defaults; id_defaults = l; l->what = safe_strdup(whatfor); diff --git a/ncrypt/pgplib.c b/ncrypt/pgplib.c index a3b7e03b4d0..fbe7a673b9d 100644 --- a/ncrypt/pgplib.c +++ b/ncrypt/pgplib.c @@ -128,7 +128,7 @@ struct PgpUid *pgp_copy_uids(struct PgpUid *up, struct PgpKeyInfo *parent) for (; up; up = up->next) { - *lp = safe_calloc(1, sizeof(struct PgpUid)); + *lp = mutt_mem_calloc(1, sizeof(struct PgpUid)); (*lp)->trust = up->trust; (*lp)->flags = up->flags; (*lp)->addr = safe_strdup(up->addr); diff --git a/ncrypt/pgplib.h b/ncrypt/pgplib.h index 1d198b72243..c1c0274caa0 100644 --- a/ncrypt/pgplib.h +++ b/ncrypt/pgplib.h @@ -86,7 +86,7 @@ struct PgpKeyInfo * pgp_remove_key(struct PgpKeyInfo * *klist, struct PgpKeyInfo static inline struct PgpKeyInfo *pgp_new_keyinfo(void) { - return safe_calloc(1, sizeof(struct PgpKeyInfo)); + return mutt_mem_calloc(1, sizeof(struct PgpKeyInfo)); } #endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/ncrypt/pgppacket.c b/ncrypt/pgppacket.c index 110ffa23a6c..308b7c8d2a8 100644 --- a/ncrypt/pgppacket.c +++ b/ncrypt/pgppacket.c @@ -75,7 +75,7 @@ unsigned char *pgp_read_packet(FILE *fp, size_t *len) if (!plen) { plen = CHUNKSIZE; - pbuf = safe_malloc(plen); + pbuf = mutt_mem_malloc(plen); } if (fread(&ctb, 1, 1, fp) < 1) diff --git a/ncrypt/smime.c b/ncrypt/smime.c index e7c749bee6d..a886c893113 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -106,7 +106,7 @@ static struct SmimeKey *smime_copy_key(struct SmimeKey *key) if (!key) return NULL; - copy = safe_calloc(1, sizeof(struct SmimeKey)); + copy = mutt_mem_calloc(1, sizeof(struct SmimeKey)); copy->email = safe_strdup(key->email); copy->hash = safe_strdup(key->hash); copy->label = safe_strdup(key->label); @@ -402,7 +402,7 @@ static struct SmimeKey *smime_select_key(struct SmimeKey *keys, char *query) if (table_index == table_size) { table_size += 5; - safe_realloc(&table, sizeof(struct SmimeKey *) * table_size); + mutt_mem_realloc(&table, sizeof(struct SmimeKey *) * table_size); } table[table_index++] = key; @@ -485,7 +485,7 @@ static struct SmimeKey *smime_parse_key(char *buf) char *pend = NULL, *p = NULL; int field = 0; - key = safe_calloc(1, sizeof(struct SmimeKey)); + key = mutt_mem_calloc(1, sizeof(struct SmimeKey)); for (p = buf; p; p = pend) { @@ -889,7 +889,7 @@ char *smime_find_keys(struct Address *adrlist, int oppenc_mode) keyID = key->hash; keylist_size += mutt_strlen(keyID) + 2; - safe_realloc(&keylist, keylist_size); + mutt_mem_realloc(&keylist, keylist_size); sprintf(keylist + keylist_used, "%s%s", keylist_used ? " " : "", keyID); keylist_used = mutt_strlen(keylist); @@ -971,7 +971,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, if (copy && buffer && num) { (*num) = count; - *buffer = safe_calloc(count, sizeof(char *)); + *buffer = mutt_mem_calloc(count, sizeof(char *)); count = 0; rewind(fpout); @@ -980,7 +980,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, len = mutt_strlen(email); if (len && (email[len - 1] == '\n')) email[len - 1] = '\0'; - (*buffer)[count] = safe_calloc(mutt_strlen(email) + 1, sizeof(char)); + (*buffer)[count] = mutt_mem_calloc(mutt_strlen(email) + 1, sizeof(char)); strncpy((*buffer)[count], email, mutt_strlen(email)); count++; } @@ -1456,7 +1456,7 @@ static char *openssl_md_to_smime_micalg(char *md) if (mutt_strncasecmp("sha", md, 3) == 0) { l = strlen(md) + 2; - micalg = safe_malloc(l); + micalg = mutt_mem_malloc(l); snprintf(micalg, l, "sha-%s", md + 3); } else diff --git a/newsrc.c b/newsrc.c index 8193e4a2c4c..c2c75d5b471 100644 --- a/newsrc.c +++ b/newsrc.c @@ -66,7 +66,7 @@ static struct NntpData *nntp_data_find(struct NntpServer *nserv, const char *gro { int len = strlen(group) + 1; /* create NntpData structure and add it to hash */ - nntp_data = safe_calloc(1, sizeof(struct NntpData) + len); + nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len); nntp_data->group = (char *) nntp_data + sizeof(struct NntpData); strfcpy(nntp_data->group, group, len); nntp_data->nserv = nserv; @@ -77,7 +77,7 @@ static struct NntpData *nntp_data_find(struct NntpServer *nserv, const char *gro if (nserv->groups_num >= nserv->groups_max) { nserv->groups_max *= 2; - safe_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data)); + mutt_mem_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data)); } nserv->groups_list[nserv->groups_num++] = nntp_data; } @@ -223,7 +223,7 @@ int nntp_newsrc_parse(struct NntpServer *nserv) FREE(&nntp_data->newsrc_ent); } - line = safe_malloc(sb.st_size + 1); + line = mutt_mem_malloc(sb.st_size + 1); while (sb.st_size && fgets(line, sb.st_size + 1, nserv->newsrc_fp)) { char *b = NULL, *h = NULL, *p = NULL; @@ -250,7 +250,7 @@ int nntp_newsrc_parse(struct NntpServer *nserv) while (*b) if (*b++ == ',') j++; - nntp_data->newsrc_ent = safe_calloc(j, sizeof(struct NewsrcEntry)); + nntp_data->newsrc_ent = mutt_mem_calloc(j, sizeof(struct NewsrcEntry)); nntp_data->subscribed = subs; /* parse entries */ @@ -284,7 +284,7 @@ int nntp_newsrc_parse(struct NntpServer *nserv) if (nntp_data->last_message == 0) nntp_data->last_message = nntp_data->newsrc_ent[j - 1].last; nntp_data->newsrc_len = j; - safe_realloc(&nntp_data->newsrc_ent, j * sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, j * sizeof(struct NewsrcEntry)); nntp_group_unread_stat(nntp_data); mutt_debug(2, "nntp_newsrc_parse: %s\n", nntp_data->group); } @@ -314,7 +314,7 @@ void nntp_newsrc_gen_entries(struct Context *ctx) if (!entries) { entries = 5; - nntp_data->newsrc_ent = safe_calloc(entries, sizeof(struct NewsrcEntry)); + nntp_data->newsrc_ent = mutt_mem_calloc(entries, sizeof(struct NewsrcEntry)); } /* Set up to fake initial sequence from 1 to the article before the @@ -335,7 +335,7 @@ void nntp_newsrc_gen_entries(struct Context *ctx) if (nntp_data->newsrc_len >= entries) { entries *= 2; - safe_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry)); } nntp_data->newsrc_ent[nntp_data->newsrc_len].first = first; nntp_data->newsrc_ent[nntp_data->newsrc_len].last = last - 1; @@ -361,13 +361,13 @@ void nntp_newsrc_gen_entries(struct Context *ctx) if (nntp_data->newsrc_len >= entries) { entries++; - safe_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry)); } nntp_data->newsrc_ent[nntp_data->newsrc_len].first = first; nntp_data->newsrc_ent[nntp_data->newsrc_len].last = nntp_data->last_loaded; nntp_data->newsrc_len++; } - safe_realloc(&nntp_data->newsrc_ent, nntp_data->newsrc_len * sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, nntp_data->newsrc_len * sizeof(struct NewsrcEntry)); if (save_sort != Sort) { @@ -438,7 +438,7 @@ int nntp_newsrc_update(struct NntpServer *nserv) return -1; buflen = 10 * LONG_STRING; - buf = safe_calloc(1, buflen); + buf = mutt_mem_calloc(1, buflen); off = 0; /* we will generate full newsrc here */ @@ -453,7 +453,7 @@ int nntp_newsrc_update(struct NntpServer *nserv) if (off + strlen(nntp_data->group) + 3 > buflen) { buflen *= 2; - safe_realloc(&buf, buflen); + mutt_mem_realloc(&buf, buflen); } snprintf(buf + off, buflen - off, "%s%c ", nntp_data->group, nntp_data->subscribed ? ':' : '!'); @@ -465,7 +465,7 @@ int nntp_newsrc_update(struct NntpServer *nserv) if (off + LONG_STRING > buflen) { buflen *= 2; - safe_realloc(&buf, buflen); + mutt_mem_realloc(&buf, buflen); } if (j) buf[off++] = ','; @@ -623,7 +623,7 @@ int nntp_active_save_cache(struct NntpServer *nserv) return 0; buflen = 10 * LONG_STRING; - buf = safe_calloc(1, buflen); + buf = mutt_mem_calloc(1, buflen); snprintf(buf, buflen, "%lu\n", (unsigned long) nserv->newgroups_time); off = strlen(buf); @@ -637,7 +637,7 @@ int nntp_active_save_cache(struct NntpServer *nserv) if (off + strlen(nntp_data->group) + (nntp_data->desc ? strlen(nntp_data->desc) : 0) + 50 > buflen) { buflen *= 2; - safe_realloc(&buf, buflen); + mutt_mem_realloc(&buf, buflen); } snprintf(buf + off, buflen - off, "%s %d %d %c%s%s\n", nntp_data->group, nntp_data->last_message, nntp_data->first_message, @@ -1006,11 +1006,11 @@ struct NntpServer *nntp_select_server(char *server, bool leave_lock) } /* new news server */ - nserv = safe_calloc(1, sizeof(struct NntpServer)); + nserv = mutt_mem_calloc(1, sizeof(struct NntpServer)); nserv->conn = conn; nserv->groups_hash = mutt_hash_create(1009, 0); nserv->groups_max = 16; - nserv->groups_list = safe_malloc(nserv->groups_max * sizeof(nntp_data)); + nserv->groups_list = mutt_mem_malloc(nserv->groups_max * sizeof(nntp_data)); rc = nntp_open_connection(nserv); @@ -1178,7 +1178,7 @@ struct NntpData *mutt_newsgroup_subscribe(struct NntpServer *nserv, char *group) nntp_data->subscribed = true; if (!nntp_data->newsrc_ent) { - nntp_data->newsrc_ent = safe_calloc(1, sizeof(struct NewsrcEntry)); + nntp_data->newsrc_ent = mutt_mem_calloc(1, sizeof(struct NewsrcEntry)); nntp_data->newsrc_len = 1; nntp_data->newsrc_ent[0].first = 1; nntp_data->newsrc_ent[0].last = 0; @@ -1225,7 +1225,7 @@ struct NntpData *mutt_newsgroup_catchup(struct NntpServer *nserv, char *group) if (nntp_data->newsrc_ent) { - safe_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry)); nntp_data->newsrc_len = 1; nntp_data->newsrc_ent[0].first = 1; nntp_data->newsrc_ent[0].last = nntp_data->last_message; @@ -1255,7 +1255,7 @@ struct NntpData *mutt_newsgroup_uncatchup(struct NntpServer *nserv, char *group) if (nntp_data->newsrc_ent) { - safe_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry)); nntp_data->newsrc_len = 1; nntp_data->newsrc_ent[0].first = 1; nntp_data->newsrc_ent[0].last = nntp_data->first_message - 1; diff --git a/nntp.c b/nntp.c index ea9b3d03a2e..1b69ac35041 100644 --- a/nntp.c +++ b/nntp.c @@ -246,14 +246,14 @@ static int nntp_attempt_features(struct NntpServer *nserv) if (nserv->overview_fmt) FREE(&nserv->overview_fmt); - nserv->overview_fmt = safe_malloc(buflen); + nserv->overview_fmt = mutt_mem_malloc(buflen); while (true) { if (buflen - off < LONG_STRING) { buflen *= 2; - safe_realloc(&nserv->overview_fmt, buflen); + mutt_mem_realloc(&nserv->overview_fmt, buflen); } chunk = mutt_socket_readln(nserv->overview_fmt + off, buflen - off, conn); @@ -293,7 +293,7 @@ static int nntp_attempt_features(struct NntpServer *nserv) } } nserv->overview_fmt[off++] = '\0'; - safe_realloc(&nserv->overview_fmt, off); + mutt_mem_realloc(&nserv->overview_fmt, off); } } return 0; @@ -843,7 +843,7 @@ static int nntp_fetch_lines(struct NntpData *nntp_data, char *query, size_t qlen return 1; } - line = safe_malloc(sizeof(buf)); + line = mutt_mem_malloc(sizeof(buf)); rc = 0; while (true) @@ -883,7 +883,7 @@ static int nntp_fetch_lines(struct NntpData *nntp_data, char *query, size_t qlen off = 0; } - safe_realloc(&line, off + sizeof(buf)); + mutt_mem_realloc(&line, off + sizeof(buf)); } FREE(&line); funct(NULL, data); @@ -1178,7 +1178,7 @@ static int parse_overview_line(char *line, void *data) hdr->read = false; hdr->old = false; hdr->deleted = false; - hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData)); + hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); NHDR(hdr)->article_num = anum; if (fc->restore) hdr->changed = true; @@ -1227,7 +1227,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, fc.first = first; fc.last = last; fc.restore = restore; - fc.messages = safe_calloc(last - first + 1, sizeof(unsigned char)); + fc.messages = mutt_mem_calloc(last - first + 1, sizeof(unsigned char)); #ifdef USE_HCACHE fc.hc = hc; #endif @@ -1393,7 +1393,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, hdr->read = false; hdr->old = false; hdr->deleted = false; - hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData)); + hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); NHDR(hdr)->article_num = current; if (restore) hdr->changed = true; @@ -1804,7 +1804,7 @@ static int nntp_group_poll(struct NntpData *nntp_data, int update_stat) nntp_data->last_cached = 0; if (nntp_data->newsrc_len) { - safe_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry)); + mutt_mem_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry)); nntp_data->newsrc_len = 1; nntp_data->newsrc_ent[0].first = 1; nntp_data->newsrc_ent[0].last = 0; @@ -1888,7 +1888,7 @@ static int check_mailbox(struct Context *ctx) if (NntpContext && nntp_data->last_message - first + 1 > NntpContext) first = nntp_data->last_message - NntpContext + 1; - messages = safe_calloc(nntp_data->last_loaded - first + 1, sizeof(unsigned char)); + messages = mutt_mem_calloc(nntp_data->last_loaded - first + 1, sizeof(unsigned char)); hc = nntp_hcache_open(nntp_data); nntp_hcache_update(nntp_data, hc); #endif @@ -1977,7 +1977,7 @@ static int check_mailbox(struct Context *ctx) ctx->msgcount++; hdr->read = false; hdr->old = false; - hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData)); + hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); NHDR(hdr)->article_num = anum; nntp_article_status(ctx, hdr, NULL, anum); if (!hdr->read) @@ -2393,7 +2393,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) if (ctx->msgcount == ctx->hdrmax) mx_alloc_memory(ctx); hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header(); - hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData)); + hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); hdr->env = mutt_read_rfc822_header(fp, hdr, 0, 0); mutt_file_fclose(&fp); unlink(tempfile); @@ -2450,7 +2450,7 @@ static int fetch_children(char *line, void *data) if (cc->num >= cc->max) { cc->max *= 2; - safe_realloc(&cc->child, sizeof(anum_t) * cc->max); + mutt_mem_realloc(&cc->child, sizeof(anum_t) * cc->max); } cc->child[cc->num++] = anum; return 0; @@ -2477,7 +2477,7 @@ int nntp_check_children(struct Context *ctx, const char *msgid) cc.ctx = ctx; cc.num = 0; cc.max = 10; - cc.child = safe_malloc(sizeof(anum_t) * cc.max); + cc.child = mutt_mem_malloc(sizeof(anum_t) * cc.max); /* fetch numbers of child messages */ snprintf(buf, sizeof(buf), "XPAT References %d-%d *%s*\r\n", diff --git a/pager.c b/pager.c index c3f098bab68..3104b62baae 100644 --- a/pager.c +++ b/pager.c @@ -447,7 +447,7 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt if (!*quote_list) { - class = safe_calloc(1, sizeof(struct QClass)); + class = mutt_mem_calloc(1, sizeof(struct QClass)); class->color = ColorQuote[0]; *quote_list = class; } @@ -472,8 +472,8 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt if (!tmp) { /* add a node above q_list */ - tmp = safe_calloc(1, sizeof(struct QClass)); - tmp->prefix = safe_calloc(1, length + 1); + tmp = mutt_mem_calloc(1, sizeof(struct QClass)); + tmp->prefix = mutt_mem_calloc(1, length + 1); strncpy(tmp->prefix, qptr, length); tmp->length = length; @@ -582,8 +582,8 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt if (!tmp) { /* add a node above q_list */ - tmp = safe_calloc(1, sizeof(struct QClass)); - tmp->prefix = safe_calloc(1, length + 1); + tmp = mutt_mem_calloc(1, sizeof(struct QClass)); + tmp->prefix = mutt_mem_calloc(1, length + 1); strncpy(tmp->prefix, qptr, length); tmp->length = length; @@ -684,8 +684,8 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt /* still not found so far: add it as a sibling to the current node */ if (!class) { - tmp = safe_calloc(1, sizeof(struct QClass)); - tmp->prefix = safe_calloc(1, length + 1); + tmp = mutt_mem_calloc(1, sizeof(struct QClass)); + tmp->prefix = mutt_mem_calloc(1, length + 1); strncpy(tmp->prefix, qptr, length); tmp->length = length; @@ -721,8 +721,8 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt if (!class) { /* not found so far: add it as a top level class */ - class = safe_calloc(1, sizeof(struct QClass)); - class->prefix = safe_calloc(1, length + 1); + class = mutt_mem_calloc(1, sizeof(struct QClass)); + class->prefix = mutt_mem_calloc(1, length + 1); strncpy(class->prefix, qptr, length); class->length = length; new_class_color(class, q_level); @@ -840,7 +840,7 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, if (line_info[i].chunks) { line_info[i].chunks = 0; - safe_realloc(&(line_info[n].syntax), sizeof(struct Syntax)); + mutt_mem_realloc(&(line_info[n].syntax), sizeof(struct Syntax)); } line_info[i++].type = MT_COLOR_SIGNATURE; } @@ -930,8 +930,8 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, break; } if (++(line_info[n].chunks) > 1) - safe_realloc(&(line_info[n].syntax), - (line_info[n].chunks) * sizeof(struct Syntax)); + mutt_mem_realloc(&(line_info[n].syntax), + (line_info[n].chunks) * sizeof(struct Syntax)); } i = line_info[n].chunks - 1; pmatch[0].rm_so += offset; @@ -991,8 +991,8 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, if (!found) { if (++(line_info[n].chunks) > 1) - safe_realloc(&(line_info[n].syntax), - (line_info[n].chunks) * sizeof(struct Syntax)); + mutt_mem_realloc(&(line_info[n].syntax), + (line_info[n].chunks) * sizeof(struct Syntax)); } i = line_info[n].chunks - 1; pmatch[0].rm_so += offset; @@ -1164,7 +1164,7 @@ static int fill_buffer(FILE *f, LOFF_T *last_pos, LOFF_T offset, unsigned char * b_read = (int) (*last_pos - offset); *buf_ready = 1; - safe_realloc(fmt, *blen); + mutt_mem_realloc(fmt, *blen); /* incomplete mbyte characters trigger a segfault in regex processing for * certain versions of glibc. Trim them if necessary. */ @@ -1439,13 +1439,13 @@ static int display_line(FILE *f, LOFF_T *last_pos, struct Line **line_info, if (*last == *max) { - safe_realloc(line_info, sizeof(struct Line) * (*max += LINES)); + mutt_mem_realloc(line_info, sizeof(struct Line) * (*max += LINES)); for (ch = *last; ch < *max; ch++) { memset(&((*line_info)[ch]), 0, sizeof(struct Line)); (*line_info)[ch].type = -1; (*line_info)[ch].search_cnt = -1; - (*line_info)[ch].syntax = safe_malloc(sizeof(struct Syntax)); + (*line_info)[ch].syntax = mutt_mem_malloc(sizeof(struct Syntax)); ((*line_info)[ch].syntax)[0].first = ((*line_info)[ch].syntax)[0].last = -1; } } @@ -1514,10 +1514,10 @@ static int display_line(FILE *f, LOFF_T *last_pos, struct Line **line_info, (offset ? REG_NOTBOL : 0)) == 0) { if (++((*line_info)[n].search_cnt) > 1) - safe_realloc(&((*line_info)[n].search), - ((*line_info)[n].search_cnt) * sizeof(struct Syntax)); + mutt_mem_realloc(&((*line_info)[n].search), + ((*line_info)[n].search_cnt) * sizeof(struct Syntax)); else - (*line_info)[n].search = safe_malloc(sizeof(struct Syntax)); + (*line_info)[n].search = mutt_mem_malloc(sizeof(struct Syntax)); pmatch[0].rm_so += offset; pmatch[0].rm_eo += offset; ((*line_info)[n].search)[(*line_info)[n].search_cnt - 1].first = pmatch[0].rm_so; @@ -1882,7 +1882,7 @@ static void pager_menu_redraw(struct Menu *pager_menu) rd->line_info[i].search_cnt = -1; rd->line_info[i].quote = NULL; - safe_realloc(&(rd->line_info[i].syntax), sizeof(struct Syntax)); + mutt_mem_realloc(&(rd->line_info[i].syntax), sizeof(struct Syntax)); if (rd->search_compiled && rd->line_info[i].search) FREE(&(rd->line_info[i].search)); } @@ -2086,12 +2086,12 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e } rd.max_line = LINES; /* number of lines on screen, from curses */ - rd.line_info = safe_calloc(rd.max_line, sizeof(struct Line)); + rd.line_info = mutt_mem_calloc(rd.max_line, sizeof(struct Line)); for (i = 0; i < rd.max_line; i++) { rd.line_info[i].type = -1; rd.line_info[i].search_cnt = -1; - rd.line_info[i].syntax = safe_malloc(sizeof(struct Syntax)); + rd.line_info[i].syntax = mutt_mem_malloc(sizeof(struct Syntax)); (rd.line_info[i].syntax)[0].first = (rd.line_info[i].syntax)[0].last = -1; } @@ -2113,10 +2113,10 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e snprintf(helpstr, sizeof(helpstr), "%s %s", tmphelp, buffer); } - rd.index_status_window = safe_calloc(1, sizeof(struct MuttWindow)); - rd.index_window = safe_calloc(1, sizeof(struct MuttWindow)); - rd.pager_status_window = safe_calloc(1, sizeof(struct MuttWindow)); - rd.pager_window = safe_calloc(1, sizeof(struct MuttWindow)); + rd.index_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + rd.index_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + rd.pager_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); + rd.pager_window = mutt_mem_calloc(1, sizeof(struct MuttWindow)); pager_menu = mutt_new_menu(MENU_PAGER); pager_menu->custom_menu_redraw = pager_menu_redraw; @@ -2254,7 +2254,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e if (!rd.line_info[i].continuation) rd.lines++; - Resize = safe_malloc(sizeof(struct Resize)); + Resize = mutt_mem_malloc(sizeof(struct Resize)); Resize->line = rd.lines; Resize->search_compiled = rd.search_compiled; diff --git a/parameter.h b/parameter.h index f37f1c49ec1..c7f54e7020d 100644 --- a/parameter.h +++ b/parameter.h @@ -41,7 +41,7 @@ struct Parameter */ static inline struct Parameter *mutt_new_parameter(void) { - return safe_calloc(1, sizeof(struct Parameter)); + return mutt_mem_calloc(1, sizeof(struct Parameter)); } void mutt_delete_parameter(const char *attribute, struct Parameter **p); diff --git a/parse.c b/parse.c index cc8bdcea420..bd98b2c2b71 100644 --- a/parse.c +++ b/parse.c @@ -106,7 +106,7 @@ char *mutt_read_rfc822_line(FILE *f, char *line, size_t *linelen) { /* grow the buffer */ *linelen += STRING; - safe_realloc(&line, *linelen); + mutt_mem_realloc(&line, *linelen); buf = line + offset; } } @@ -423,7 +423,7 @@ struct Body *mutt_read_mime_header(FILE *fp, int digest) { struct Body *p = mutt_new_body(); char *c = NULL; - char *line = safe_malloc(LONG_STRING); + char *line = mutt_mem_malloc(LONG_STRING); size_t linelen = LONG_STRING; p->hdr_offset = ftello(fp); @@ -702,7 +702,7 @@ char *mutt_extract_message_id(const char *s, const char **saveptr) if (*p == '>') { size_t olen = onull - o, slen = p - s + 1; - ret = safe_malloc(olen + slen + 1); + ret = mutt_mem_malloc(olen + slen + 1); if (o) memcpy(ret, o, olen); memcpy(ret + olen, s, slen); @@ -1150,7 +1150,7 @@ struct Envelope *mutt_read_rfc822_header(FILE *f, struct Header *hdr, short user_hdrs, short weed) { struct Envelope *e = mutt_new_envelope(); - char *line = safe_malloc(LONG_STRING); + char *line = mutt_mem_malloc(LONG_STRING); char *p = NULL; LOFF_T loc; size_t linelen = LONG_STRING; diff --git a/pattern.c b/pattern.c index dad2f08c447..9491f9ea97e 100644 --- a/pattern.c +++ b/pattern.c @@ -111,7 +111,7 @@ static bool eat_regex(struct Pattern *pat, struct Buffer *s, struct Buffer *err) } else { - pat->p.regex = safe_malloc(sizeof(regex_t)); + pat->p.regex = mutt_mem_malloc(sizeof(regex_t)); r = REGCOMP(pat->p.regex, buf.data, REG_NEWLINE | REG_NOSUB | mutt_which_case(buf.data)); if (r != 0) @@ -1040,7 +1040,7 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno) } blen = STRING; - buf = safe_malloc(blen); + buf = mutt_mem_malloc(blen); /* search the file "fp" */ while (lng > 0) @@ -1931,7 +1931,7 @@ int mutt_pattern_func(int op, char *prompt) mutt_buffer_init(&err); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); pat = mutt_pattern_comp(buf, MUTT_FULL_MSG, &err); if (!pat) { @@ -2066,7 +2066,7 @@ int mutt_search_command(int cur, int op) mutt_message(_("Compiling search pattern...")); mutt_pattern_free(&SearchPattern); err.dsize = STRING; - err.data = safe_malloc(err.dsize); + err.data = mutt_mem_malloc(err.dsize); SearchPattern = mutt_pattern_comp(temp, MUTT_FULL_MSG, &err); if (!SearchPattern) { diff --git a/pattern.h b/pattern.h index 114bb8c3632..663a43bb53b 100644 --- a/pattern.h +++ b/pattern.h @@ -86,7 +86,7 @@ struct PatternCache static inline struct Pattern *new_pattern(void) { - return safe_calloc(1, sizeof(struct Pattern)); + return mutt_mem_calloc(1, sizeof(struct Pattern)); } int mutt_pattern_exec(struct Pattern *pat, enum PatternExecFlag flags, diff --git a/pgppubring.c b/pgppubring.c index de1653df060..3eb894b1370 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -224,7 +224,7 @@ static char *binary_fingerprint_to_string(unsigned char *buff, size_t length) { char *fingerprint = NULL, *pf = NULL; - pf = fingerprint = safe_malloc((length * 2) + 1); + pf = fingerprint = mutt_mem_malloc((length * 2) + 1); for (int i = 0; i < length; i++) { @@ -685,7 +685,8 @@ static struct PgpKeyInfo *pgp_parse_keyblock(FILE *fp) { if (lsig) { - struct PgpSignature *signature = safe_calloc(1, sizeof(struct PgpSignature)); + struct PgpSignature *signature = + mutt_mem_calloc(1, sizeof(struct PgpSignature)); *lsig = signature; lsig = &signature->next; @@ -717,14 +718,14 @@ static struct PgpKeyInfo *pgp_parse_keyblock(FILE *fp) if (!addr) break; - chr = safe_malloc(l); + chr = mutt_mem_malloc(l); if (l > 0) { memcpy(chr, buff + 1, l - 1); chr[l - 1] = '\0'; } - *addr = uid = safe_calloc(1, sizeof(struct PgpUid)); /* XXX */ + *addr = uid = mutt_mem_calloc(1, sizeof(struct PgpUid)); /* XXX */ uid->addr = chr; uid->parent = p; uid->trust = 0; @@ -776,7 +777,7 @@ static void pgpring_find_candidates(char *ringfile, const char *hints[], int nhi size_t error_buf_len; error_buf_len = sizeof("fopen: ") - 1 + strlen(ringfile) + 1; - error_buf = safe_malloc(error_buf_len); + error_buf = mutt_mem_malloc(error_buf_len); snprintf(error_buf, error_buf_len, "fopen: %s", ringfile); perror(error_buf); FREE(&error_buf); @@ -799,7 +800,7 @@ static void pgpring_find_candidates(char *ringfile, const char *hints[], int nhi } else if (pt == PT_NAME) { - char *tmp = safe_malloc(l); + char *tmp = mutt_mem_malloc(l); memcpy(tmp, buff + 1, l - 1); tmp[l - 1] = '\0'; diff --git a/pop.c b/pop.c index e0d18a23a10..9e886c238f8 100644 --- a/pop.c +++ b/pop.c @@ -449,7 +449,7 @@ static int pop_open_mailbox(struct Context *ctx) ctx->path = safe_strdup(buf); ctx->realpath = safe_strdup(ctx->path); - pop_data = safe_calloc(1, sizeof(struct PopData)); + pop_data = mutt_mem_calloc(1, sizeof(struct PopData)); pop_data->conn = conn; ctx->data = pop_data; @@ -832,7 +832,7 @@ void pop_fetch_mail(void) return; } - url = p = safe_calloc(strlen(PopHost) + 7, sizeof(char)); + url = p = mutt_mem_calloc(strlen(PopHost) + 7, sizeof(char)); if (url_check_scheme(PopHost) == U_UNKNOWN) { strcpy(url, "pop://"); @@ -852,7 +852,7 @@ void pop_fetch_mail(void) if (!conn) return; - pop_data = safe_calloc(1, sizeof(struct PopData)); + pop_data = mutt_mem_calloc(1, sizeof(struct PopData)); pop_data->conn = conn; if (pop_open_connection(pop_data) < 0) diff --git a/pop_auth.c b/pop_auth.c index 8fcf2a4ca8b..a85a646c838 100644 --- a/pop_auth.c +++ b/pop_auth.c @@ -90,7 +90,7 @@ static enum PopAuthRes pop_auth_sasl(struct PopData *pop_data, const char *metho mutt_message(_("Authenticating (SASL)...")); bufsize = ((olen * 2) > LONG_STRING) ? (olen * 2) : LONG_STRING; - buf = safe_malloc(bufsize); + buf = mutt_mem_malloc(bufsize); snprintf(buf, bufsize, "AUTH %s", mech); olen = strlen(buf); @@ -149,7 +149,7 @@ static enum PopAuthRes pop_auth_sasl(struct PopData *pop_data, const char *metho if ((olen * 2) > bufsize) { bufsize = olen * 2; - safe_realloc(&buf, bufsize); + mutt_mem_realloc(&buf, bufsize); } if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK) { diff --git a/pop_lib.c b/pop_lib.c index 01a36cf4557..659b01abbfb 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -162,12 +162,12 @@ static int fetch_auth(char *line, void *data) if (!pop_data->auth_list) { - pop_data->auth_list = safe_malloc(strlen(line) + 1); + pop_data->auth_list = mutt_mem_malloc(strlen(line) + 1); *pop_data->auth_list = '\0'; } else { - safe_realloc(&pop_data->auth_list, strlen(pop_data->auth_list) + strlen(line) + 2); + mutt_mem_realloc(&pop_data->auth_list, strlen(pop_data->auth_list) + strlen(line) + 2); strcat(pop_data->auth_list, " "); } strcat(pop_data->auth_list, line); @@ -523,7 +523,7 @@ int pop_fetch_data(struct PopData *pop_data, char *query, struct Progress *progr if (ret < 0) return ret; - inbuf = safe_malloc(sizeof(buf)); + inbuf = mutt_mem_malloc(sizeof(buf)); while (true) { @@ -560,7 +560,7 @@ int pop_fetch_data(struct PopData *pop_data, char *query, struct Progress *progr lenbuf = 0; } - safe_realloc(&inbuf, lenbuf + sizeof(buf)); + mutt_mem_realloc(&inbuf, lenbuf + sizeof(buf)); } FREE(&inbuf); diff --git a/query.c b/query.c index c4357170078..41611fd1dfb 100644 --- a/query.c +++ b/query.c @@ -144,12 +144,12 @@ static struct Query *run_query(char *s, int quiet) { if (!first) { - first = safe_calloc(1, sizeof(struct Query)); + first = mutt_mem_calloc(1, sizeof(struct Query)); cur = first; } else { - cur->next = safe_calloc(1, sizeof(struct Query)); + cur->next = mutt_mem_calloc(1, sizeof(struct Query)); cur = cur->next; } @@ -309,7 +309,7 @@ static void query_menu(char *buf, size_t buflen, struct Query *results, int retb for (queryp = results; queryp; queryp = queryp->next) menu->max++; - menu->data = QueryTable = safe_calloc(menu->max, sizeof(struct Entry)); + menu->data = QueryTable = mutt_mem_calloc(menu->max, sizeof(struct Entry)); for (i = 0, queryp = results; queryp; queryp = queryp->next, i++) QueryTable[i].data = queryp; @@ -363,7 +363,8 @@ static void query_menu(char *buf, size_t buflen, struct Query *results, int retb if (op == OP_QUERY) { - menu->data = QueryTable = safe_calloc(menu->max, sizeof(struct Entry)); + menu->data = QueryTable = + mutt_mem_calloc(menu->max, sizeof(struct Entry)); for (i = 0, queryp = results; queryp; queryp = queryp->next, i++) QueryTable[i].data = queryp; @@ -373,7 +374,7 @@ static void query_menu(char *buf, size_t buflen, struct Query *results, int retb bool clear = false; /* append */ - safe_realloc(&QueryTable, menu->max * sizeof(struct Entry)); + mutt_mem_realloc(&QueryTable, menu->max * sizeof(struct Entry)); menu->data = QueryTable; diff --git a/recvattach.c b/recvattach.c index 3bbbab30295..50b9438d91d 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1016,7 +1016,7 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Header } else { - new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); + new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr)); mutt_actx_add_attach(actx, new); new->content = m; @@ -1137,7 +1137,7 @@ void mutt_view_attachments(struct Header *hdr) menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_ATTACH, AttachHelp); mutt_push_current_menu(menu); - actx = safe_calloc(sizeof(struct AttachCtx), 1); + actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1); actx->hdr = hdr; actx->root_fp = msg->fp; mutt_update_recvattach_menu(actx, menu, 1); diff --git a/remailer.c b/remailer.c index 4830c22b2e7..ee7863a8e98 100644 --- a/remailer.c +++ b/remailer.c @@ -100,7 +100,7 @@ static void mix_add_entry(struct Remailer ***type2_list, struct Remailer *entry, if (*used == *slots) { *slots += 5; - safe_realloc(type2_list, sizeof(struct Remailer *) * (*slots)); + mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots)); } (*type2_list)[(*used)++] = entry; @@ -110,7 +110,7 @@ static void mix_add_entry(struct Remailer ***type2_list, struct Remailer *entry, static struct Remailer *mix_new_remailer(void) { - return safe_calloc(1, sizeof(struct Remailer)); + return mutt_mem_calloc(1, sizeof(struct Remailer)); } static void mix_free_remailer(struct Remailer **r) @@ -232,7 +232,7 @@ static void mix_screen_coordinates(struct Remailer **type2_list, struct Coord ** if (!chain->cl) return; - safe_realloc(coordsp, sizeof(struct Coord) * chain->cl); + mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl); coords = *coordsp; @@ -481,7 +481,7 @@ void mix_make_chain(struct ListHead *chainhead) return; } - chain = safe_calloc(1, sizeof(struct MixChain)); + chain = mutt_mem_calloc(1, sizeof(struct MixChain)); struct ListNode *p; STAILQ_FOREACH(p, chainhead, entries) diff --git a/rfc1524.c b/rfc1524.c index 1b070109966..6dfd4ca7402 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -300,7 +300,7 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, if (get_field_text(field + 4, &test_command, type, filename, line) && test_command) { len = mutt_strlen(test_command) + STRING; - safe_realloc(&test_command, len); + mutt_mem_realloc(&test_command, len); rfc1524_expand_command(a, a->filename, type, test_command, len); if (mutt_system(test_command) != 0) { @@ -362,7 +362,7 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, */ struct Rfc1524MailcapEntry *rfc1524_new_entry(void) { - return safe_calloc(1, sizeof(struct Rfc1524MailcapEntry)); + return mutt_mem_calloc(1, sizeof(struct Rfc1524MailcapEntry)); } /** diff --git a/rfc2047.c b/rfc2047.c index 0da5fd1b721..fb1087c6034 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -67,7 +67,7 @@ static size_t convert_string(ICONV_CONST char *f, size_t flen, const char *from, if (cd == (iconv_t)(-1)) return (size_t)(-1); obl = 4 * flen + 1; - ob = buf = safe_malloc(obl); + ob = buf = mutt_mem_malloc(obl); n = iconv(cd, &f, &flen, &ob, &obl); if (n == (size_t)(-1) || iconv(cd, 0, 0, &ob, &obl) == (size_t)(-1)) { @@ -81,7 +81,7 @@ static size_t convert_string(ICONV_CONST char *f, size_t flen, const char *from, *tlen = ob - buf; - safe_realloc(&buf, ob - buf + 1); + mutt_mem_realloc(&buf, ob - buf + 1); *t = buf; iconv_close(cd); @@ -108,7 +108,7 @@ int convert_nonmime_string(char **ps) n = c1 ? c1 - c : mutt_strlen(c); if (!n) return 0; - fromcode = safe_malloc(n + 1); + fromcode = mutt_mem_malloc(n + 1); strfcpy(fromcode, c, n + 1); m = convert_string(u, ulen, fromcode, Charset, &s, &slen); FREE(&fromcode); @@ -143,7 +143,7 @@ char *mutt_choose_charset(const char *fromcode, const char *charsets, char *u, if (!n) continue; - t = safe_malloc(n + 1); + t = mutt_mem_malloc(n + 1); memcpy(t, p, n); t[n] = '\0'; @@ -444,7 +444,7 @@ static int rfc2047_encode(ICONV_CONST char *d, size_t dlen, int col, const char { ret = 1; icode = 0; - safe_realloc(&u, (ulen = dlen) + 1); + mutt_mem_realloc(&u, (ulen = dlen) + 1); memcpy(u, d, dlen); u[ulen] = 0; } @@ -537,7 +537,7 @@ static int rfc2047_encode(ICONV_CONST char *d, size_t dlen, int col, const char /* Initialise the output buffer with the us-ascii prefix. */ buflen = 2 * ulen; - buf = safe_malloc(buflen); + buf = mutt_mem_malloc(buflen); bufpos = t0 - u; memcpy(buf, u, t0 - u); @@ -580,7 +580,7 @@ static int rfc2047_encode(ICONV_CONST char *d, size_t dlen, int col, const char if ((bufpos + wlen + lb_len) > buflen) { buflen = bufpos + wlen + lb_len; - safe_realloc(&buf, buflen); + mutt_mem_realloc(&buf, buflen); } r = encode_block(buf + bufpos, t, n, icode, tocode, encoder); assert(r == wlen); @@ -595,7 +595,7 @@ static int rfc2047_encode(ICONV_CONST char *d, size_t dlen, int col, const char /* Add last encoded word and us-ascii suffix to buffer. */ buflen = bufpos + wlen + (u + ulen - t1); - safe_realloc(&buf, buflen + 1); + mutt_mem_realloc(&buf, buflen + 1); r = encode_block(buf + bufpos, t, t1 - t, icode, tocode, encoder); assert(r == wlen); bufpos += wlen; @@ -655,7 +655,7 @@ static int rfc2047_decode_word(char *d, const char *s, size_t len) char *charset = NULL; int rv = -1; - pd = d0 = safe_malloc(strlen(s) + 1); + pd = d0 = mutt_mem_malloc(strlen(s) + 1); for (pp = s; (pp1 = strchr(pp, '?')); pp = pp1 + 1) { @@ -798,7 +798,7 @@ void rfc2047_decode(char **pd) return; dlen = 4 * strlen(s); /* should be enough */ - d = d0 = safe_malloc(dlen + 1); + d = d0 = mutt_mem_malloc(dlen + 1); while (*s && dlen > 0) { @@ -826,7 +826,7 @@ void rfc2047_decode(char **pd) size_t tlen; n = mutt_strlen(s); - t = safe_malloc(n + 1); + t = mutt_mem_malloc(n + 1); strfcpy(t, s, n + 1); convert_nonmime_string(&t); tlen = mutt_strlen(t); diff --git a/rfc2231.c b/rfc2231.c index ed23aa573de..41d3e0d1b8a 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -116,7 +116,7 @@ static void rfc2231_decode_one(char *dest, char *src) static struct Rfc2231Parameter *rfc2231_new_parameter(void) { - return safe_calloc(1, sizeof(struct Rfc2231Parameter)); + return mutt_mem_calloc(1, sizeof(struct Rfc2231Parameter)); } /** @@ -189,7 +189,7 @@ static void rfc2231_join_continuations(struct Parameter **head, struct Rfc2231Pa vl = strlen(par->value); - safe_realloc(&value, l + vl + 1); + mutt_mem_realloc(&value, l + vl + 1); strcpy(value + l, par->value); l += vl; @@ -349,7 +349,7 @@ int rfc2231_encode_string(char **pd) if (encode) { - e = safe_malloc(dlen + 2 * ext + strlen(charset) + 3); + e = mutt_mem_malloc(dlen + 2 * ext + strlen(charset) + 3); sprintf(e, "%s''", charset); t = e + strlen(e); for (s = d, slen = dlen; slen; s++, slen--) diff --git a/rfc822.c b/rfc822.c index 3d604c0e824..4560ee32ba7 100644 --- a/rfc822.c +++ b/rfc822.c @@ -647,7 +647,7 @@ void rfc822_qualify(struct Address *addr, const char *host) for (; addr; addr = addr->next) if (!addr->group && addr->mailbox && strchr(addr->mailbox, '@') == NULL) { - p = safe_malloc(mutt_strlen(addr->mailbox) + mutt_strlen(host) + 2); + p = mutt_mem_malloc(mutt_strlen(addr->mailbox) + mutt_strlen(host) + 2); sprintf(p, "%s@%s", addr->mailbox, host); FREE(&addr->mailbox); addr->mailbox = p; diff --git a/rfc822.h b/rfc822.h index cc63232ddd2..b4c287b249f 100644 --- a/rfc822.h +++ b/rfc822.h @@ -68,7 +68,7 @@ extern const char *const RFC822Errors[]; */ static inline struct Address *rfc822_new_address(void) { - return safe_calloc(1, sizeof(struct Address)); + return mutt_mem_calloc(1, sizeof(struct Address)); } #endif /* _MUTT_RFC822_H */ diff --git a/safe_asprintf.c b/safe_asprintf.c index f9e35ef7cd5..56e51f532db 100644 --- a/safe_asprintf.c +++ b/safe_asprintf.c @@ -69,7 +69,7 @@ int safe_asprintf(char **strp, const char *fmt, ...) int rlen = STRING; int n; - *strp = safe_malloc(rlen); + *strp = mutt_mem_malloc(rlen); for (;;) { va_list ap; @@ -90,12 +90,12 @@ int safe_asprintf(char **strp, const char *fmt, ...) if (n == 0) /* convention is to use NULL for zero-length strings. */ FREE(strp); else if (n != rlen - 1) - safe_realloc(strp, n + 1); + mutt_mem_realloc(strp, n + 1); return n; } /* increase size and try again */ rlen = n + 1; - safe_realloc(strp, rlen); + mutt_mem_realloc(strp, rlen); } /* not reached */ } diff --git a/score.c b/score.c index c9b5db88cba..d728ab821d0 100644 --- a/score.c +++ b/score.c @@ -109,7 +109,7 @@ int mutt_parse_score(struct Buffer *buf, struct Buffer *s, unsigned long data, FREE(&pattern); return -1; } - ptr = safe_calloc(1, sizeof(struct Score)); + ptr = mutt_mem_calloc(1, sizeof(struct Score)); if (last) last->next = ptr; else diff --git a/send.c b/send.c index 0859e2e1324..6ae6909a5c3 100644 --- a/send.c +++ b/send.c @@ -715,7 +715,7 @@ void mutt_make_misc_reply_headers(struct Envelope *env, struct Context *ctx, if (curenv->real_subj) { FREE(&env->subject); - env->subject = safe_malloc(mutt_strlen(curenv->real_subj) + 5); + env->subject = mutt_mem_malloc(mutt_strlen(curenv->real_subj) + 5); sprintf(env->subject, "Re: %s", curenv->real_subj); } else if (!env->subject) @@ -1073,7 +1073,7 @@ struct Address *mutt_default_from(void) else if (option(OPT_USE_DOMAIN)) { adr = rfc822_new_address(); - adr->mailbox = safe_malloc(mutt_strlen(Username) + mutt_strlen(fqdn) + 2); + adr->mailbox = mutt_mem_malloc(mutt_strlen(Username) + mutt_strlen(fqdn) + 2); sprintf(adr->mailbox, "%s@%s", NONULL(Username), NONULL(fqdn)); } else @@ -1290,7 +1290,7 @@ static int search_attach_keyword(char *filename) if (!attf) return 0; - char *inputline = safe_malloc(LONG_STRING); + char *inputline = mutt_mem_malloc(LONG_STRING); int found = 0; while (!feof(attf)) { diff --git a/sendlib.c b/sendlib.c index aa7a904fff4..640e4870a4f 100644 --- a/sendlib.c +++ b/sendlib.c @@ -694,10 +694,10 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, if (cd1 == (iconv_t)(-1)) return -1; - cd = safe_calloc(ncodes, sizeof(iconv_t)); - score = safe_calloc(ncodes, sizeof(size_t)); - states = safe_calloc(ncodes, sizeof(struct ContentState)); - infos = safe_calloc(ncodes, sizeof(struct Content)); + cd = mutt_mem_calloc(ncodes, sizeof(iconv_t)); + score = mutt_mem_calloc(ncodes, sizeof(size_t)); + states = mutt_mem_calloc(ncodes, sizeof(struct ContentState)); + infos = mutt_mem_calloc(ncodes, sizeof(struct Content)); for (int i = 0; i < ncodes; i++) { @@ -845,7 +845,7 @@ static size_t convert_file_from_to(FILE *file, const char *fromcodes, const char } /* Copy them */ - tcode = safe_malloc(ncodes * sizeof(char *)); + tcode = mutt_mem_malloc(ncodes * sizeof(char *)); for (c = tocodes, i = 0; c; c = c1 ? c1 + 1 : 0, i++) { c1 = strchr(c, ':'); @@ -937,7 +937,7 @@ struct Content *mutt_get_content_info(const char *fname, struct Body *b) return NULL; } - info = safe_calloc(1, sizeof(struct Content)); + info = mutt_mem_calloc(1, sizeof(struct Content)); memset(&state, 0, sizeof(state)); if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) @@ -1656,7 +1656,7 @@ void mutt_write_references(const struct ListHead *r, FILE *f, size_t trim) break; } - struct ListNode **ref = safe_calloc(length, sizeof(struct ListNode *)); + struct ListNode **ref = mutt_mem_calloc(length, sizeof(struct ListNode *)); // store in reverse order size_t tmp = length; @@ -2202,7 +2202,7 @@ static void encode_headers(struct ListHead *h) continue; rfc2047_encode_string32(&tmp); - safe_realloc(&np->data, mutt_strlen(np->data) + 2 + mutt_strlen(tmp) + 1); + mutt_mem_realloc(&np->data, mutt_strlen(np->data) + 2 + mutt_strlen(tmp) + 1); sprintf(np->data + i, ": %s", NONULL(tmp)); @@ -2440,7 +2440,7 @@ static char **add_args(char **args, size_t *argslen, size_t *argsmax, struct Add if (addr->mailbox && !addr->group) { if (*argslen == *argsmax) - safe_realloc(&args, (*argsmax += 5) * sizeof(char *)); + mutt_mem_realloc(&args, (*argsmax += 5) * sizeof(char *)); args[(*argslen)++] = addr->mailbox; } } @@ -2450,7 +2450,7 @@ static char **add_args(char **args, size_t *argslen, size_t *argsmax, struct Add static char **add_option(char **args, size_t *argslen, size_t *argsmax, char *s) { if (*argslen == *argsmax) - safe_realloc(&args, (*argsmax += 5) * sizeof(char *)); + mutt_mem_realloc(&args, (*argsmax += 5) * sizeof(char *)); args[(*argslen)++] = s; return args; } @@ -2506,7 +2506,7 @@ int mutt_invoke_sendmail(struct Address *from, struct Address *to, struct Addres while ((ps = strtok(ps, " "))) { if (argslen == argsmax) - safe_realloc(&args, sizeof(char *) * (argsmax += 5)); + mutt_mem_realloc(&args, sizeof(char *) * (argsmax += 5)); if (i) { @@ -2540,7 +2540,7 @@ int mutt_invoke_sendmail(struct Address *from, struct Address *to, struct Addres while ((ps = strtok(ps, " "))) { if (extra_argslen == extra_argsmax) - safe_realloc(&extra_args, sizeof(char *) * (extra_argsmax += 5)); + mutt_mem_realloc(&extra_args, sizeof(char *) * (extra_argsmax += 5)); extra_args[extra_argslen++] = ps; ps = NULL; @@ -2585,7 +2585,7 @@ int mutt_invoke_sendmail(struct Address *from, struct Address *to, struct Addres #endif if (argslen == argsmax) - safe_realloc(&args, sizeof(char *) * (++argsmax)); + mutt_mem_realloc(&args, sizeof(char *) * (++argsmax)); args[argslen++] = NULL; diff --git a/sidebar.c b/sidebar.c index 3681e51a60e..00865833383 100644 --- a/sidebar.c +++ b/sidebar.c @@ -910,7 +910,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) tmp_folder_name += lastsep; /* basename */ int sfn_len = mutt_strlen(tmp_folder_name) + sidebar_folder_depth * mutt_strlen(SidebarIndentString) + 1; - sidebar_folder_name = safe_malloc(sfn_len); + sidebar_folder_name = mutt_mem_malloc(sfn_len); sidebar_folder_name[0] = 0; for (int i = 0; i < sidebar_folder_depth; i++) safe_strcat(sidebar_folder_name, sfn_len, NONULL(SidebarIndentString)); @@ -1112,9 +1112,9 @@ void mutt_sb_notify_mailbox(struct Buffy *b, int created) if (EntryCount >= EntryLen) { EntryLen += 10; - safe_realloc(&Entries, EntryLen * sizeof(struct SbEntry *)); + mutt_mem_realloc(&Entries, EntryLen * sizeof(struct SbEntry *)); } - Entries[EntryCount] = safe_calloc(1, sizeof(struct SbEntry)); + Entries[EntryCount] = mutt_mem_calloc(1, sizeof(struct SbEntry)); Entries[EntryCount]->buffy = b; if (TopIndex < 0) diff --git a/smtp.c b/smtp.c index 9e34099812f..60074275e7b 100644 --- a/smtp.c +++ b/smtp.c @@ -389,7 +389,7 @@ static int smtp_auth_sasl(struct Connection *conn, const char *mechlist) mutt_message(_("Authenticating (%s)..."), mech); bufsize = ((len * 2) > LONG_STRING) ? (len * 2) : LONG_STRING; - buf = safe_malloc(bufsize); + buf = mutt_mem_malloc(bufsize); snprintf(buf, bufsize, "AUTH %s", mech); if (len) @@ -435,7 +435,7 @@ static int smtp_auth_sasl(struct Connection *conn, const char *mechlist) if ((len * 2) > bufsize) { bufsize = len * 2; - safe_realloc(&buf, bufsize); + mutt_mem_realloc(&buf, bufsize); } if (sasl_encode64(data, len, buf, bufsize, &len) != SASL_OK) { diff --git a/thread.c b/thread.c index 2991928db72..b177f6620c6 100644 --- a/thread.c +++ b/thread.c @@ -267,8 +267,8 @@ void mutt_draw_tree(struct Context *ctx) * From now on we can simply ignore invisible subtrees */ calculate_visibility(ctx, &max_depth); - pfx = safe_malloc(width * max_depth + 2); - arrow = safe_malloc(width * max_depth + 2); + pfx = mutt_mem_malloc(width * max_depth + 2); + arrow = mutt_mem_malloc(width * max_depth + 2); while (tree) { if (depth) @@ -289,7 +289,7 @@ void mutt_draw_tree(struct Context *ctx) { myarrow[width] = MUTT_TREE_RARROW; myarrow[width + 1] = 0; - new_tree = safe_malloc((2 + depth * width)); + new_tree = mutt_mem_malloc((2 + depth * width)); if (start_depth > 1) { strncpy(new_tree, pfx, (start_depth - 1) * width); @@ -639,7 +639,7 @@ struct MuttThread *mutt_sort_subthreads(struct MuttThread *thread, int init) top = thread; - array = safe_calloc((array_size = 256), sizeof(struct MuttThread *)); + array = mutt_mem_calloc((array_size = 256), sizeof(struct MuttThread *)); while (true) { if (init || !thread->sort_key) @@ -678,7 +678,7 @@ struct MuttThread *mutt_sort_subthreads(struct MuttThread *thread, int init) for (i = 0; thread; i++, thread = thread->prev) { if (i >= array_size) - safe_realloc(&array, (array_size *= 2) * sizeof(struct MuttThread *)); + mutt_mem_realloc(&array, (array_size *= 2) * sizeof(struct MuttThread *)); array[i] = thread; } @@ -865,7 +865,7 @@ void mutt_sort_threads(struct Context *ctx, int init) { new = (option(OPT_DUPLICATE_THREADS) ? thread : NULL); - thread = safe_calloc(1, sizeof(struct MuttThread)); + thread = mutt_mem_calloc(1, sizeof(struct MuttThread)); thread->message = cur; thread->check_subject = true; cur->thread = thread; @@ -958,7 +958,7 @@ void mutt_sort_threads(struct Context *ctx, int init) new = mutt_hash_find(ctx->thread_hash, ref->data); if (!new) { - new = safe_calloc(1, sizeof(struct MuttThread)); + new = mutt_mem_calloc(1, sizeof(struct MuttThread)); mutt_hash_insert(ctx->thread_hash, ref->data, new); } else diff --git a/url.c b/url.c index 37567d27446..6e2ad4ea6df 100644 --- a/url.c +++ b/url.c @@ -104,7 +104,7 @@ static int parse_query_string(struct Url *u, char *src) while (src && *src) { - qs = safe_calloc(1, sizeof(struct UrlQueryString)); + qs = mutt_mem_calloc(1, sizeof(struct UrlQueryString)); if ((k = strchr(src, '&'))) *k = '\0';