Skip to content

Commit

Permalink
rename memory functions
Browse files Browse the repository at this point in the history
  • Loading branch information
flatcap committed Nov 16, 2017
1 parent 9f844b4 commit 03f5fec
Show file tree
Hide file tree
Showing 98 changed files with 403 additions and 401 deletions.
2 changes: 1 addition & 1 deletion addrbook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion bcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion body.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion buffy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions color.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion conn/getdomain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions conn/sasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion conn/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions conn/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions conn/ssl_gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 03f5fec

Please sign in to comment.