/* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
#define EXIM_DBCREATE_CURSOR(db, cursor) { \
- *(cursor) = malloc(sizeof(TDB_DATA)); (*(cursor))->dptr = NULL; }
+ *(cursor) = store_malloc(sizeof(TDB_DATA)); (*(cursor))->dptr = NULL; }
/* EXIM_DBSCAN - This is complicated because we have to free the last datum
free() must not die when passed NULL */
static error_block *
add_to_eblock(error_block *eblock, uschar *t1, uschar *t2)
{
-error_block *eb = malloc(sizeof(error_block));
+error_block *eb = store_malloc(sizeof(error_block));
if (eblock == NULL)
eblock = eb;
else
/* Ensure we have a buffer for constructing log entries. Use malloc directly,
because store_malloc writes a log entry on failure. */
-log_buffer = (uschar *)malloc(LOG_BUFFER_SIZE);
-if (log_buffer == NULL)
+if (!(log_buffer = US malloc(LOG_BUFFER_SIZE)))
{
fprintf(stderr, "exim: failed to get store for log buffer\n");
exit(EXIT_FAILURE);
"syslog_processname is longer than 32 chars: aborting");
if (log_oneline)
- {
if (admin_user)
{
log_write(0, LOG_MAIN, "%s", log_oneline);
}
else
return EXIT_FAILURE;
- }
/* In some operating systems, the environment variable TMPDIR controls where
temporary files are created; Exim doesn't use these (apart from when delivering
#ifdef EXIM_TMPDIR
{
uschar **p;
- if (environ) for (p = USS environ; *p != NULL; p++)
- {
- if (Ustrncmp(*p, "TMPDIR=", 7) == 0 &&
- Ustrcmp(*p+7, EXIM_TMPDIR) != 0)
+ if (environ) for (p = USS environ; *p; p++)
+ if (Ustrncmp(*p, "TMPDIR=", 7) == 0 && Ustrcmp(*p+7, EXIM_TMPDIR) != 0)
{
- uschar *newp = malloc(Ustrlen(EXIM_TMPDIR) + 8);
+ uschar * newp = store_malloc(Ustrlen(EXIM_TMPDIR) + 8);
sprintf(CS newp, "TMPDIR=%s", EXIM_TMPDIR);
*p = newp;
DEBUG(D_any) debug_printf("reset TMPDIR=%s in environment\n", EXIM_TMPDIR);
}
- }
}
#endif
this. We have to make a new environment if TZ is wrong, but don't bother if
timestamps_utc is set, because then all times are in UTC anyway. */
-if (timezone_string != NULL && strcmpic(timezone_string, US"UTC") == 0)
- {
+if (timezone_string && strcmpic(timezone_string, US"UTC") == 0)
timestamps_utc = TRUE;
- }
else
{
uschar *envtz = US getenv("TZ");
- if ((envtz == NULL && timezone_string != NULL) ||
- (envtz != NULL &&
- (timezone_string == NULL ||
- Ustrcmp(timezone_string, envtz) != 0)))
+ if (envtz ? !timezone_string || Ustrcmp(timezone_string, envtz) != 0 : timezone_string)
{
uschar **p = USS environ;
uschar **new;
uschar **newp;
int count = 0;
- if (environ) while (*p++ != NULL) count++;
- if (envtz == NULL) count++;
- newp = new = malloc(sizeof(uschar *) * (count + 1));
- if (environ) for (p = USS environ; *p != NULL; p++)
- {
- if (Ustrncmp(*p, "TZ=", 3) == 0) continue;
- *newp++ = *p;
- }
- if (timezone_string != NULL)
+ if (environ) while (*p++) count++;
+ if (!envtz) count++;
+ newp = new = store_malloc(sizeof(uschar *) * (count + 1));
+ if (environ) for (p = USS environ; *p; p++)
+ if (Ustrncmp(*p, "TZ=", 3) != 0) *newp++ = *p;
+ if (timezone_string)
{
- *newp = malloc(Ustrlen(timezone_string) + 4);
+ *newp = store_malloc(Ustrlen(timezone_string) + 4);
sprintf(CS *newp++, "TZ=%s", timezone_string);
}
*newp = NULL;
are recursing (can't open the panic log either), the pointer will already be
set. */
-if (panic_save_buffer == NULL)
- {
- panic_save_buffer = (uschar *)malloc(LOG_BUFFER_SIZE);
- if (panic_save_buffer != NULL)
+if (!panic_save_buffer)
+ if ((panic_save_buffer = US malloc(LOG_BUFFER_SIZE)))
memcpy(panic_save_buffer, log_buffer, LOG_BUFFER_SIZE);
- }
log_write(0, LOG_PANIC_DIE, "Cannot open %s log file \"%s\": %s: "
"euid=%d egid=%d", log_names[type], buffer, strerror(errno), euid, getegid());
{
int save_errno = errno;
-if (panic_save_buffer == NULL)
- {
- panic_save_buffer = (uschar *)malloc(LOG_BUFFER_SIZE);
- if (panic_save_buffer != NULL)
+if (!panic_save_buffer)
+ if ((panic_save_buffer = US malloc(LOG_BUFFER_SIZE)))
memcpy(panic_save_buffer, log_buffer, LOG_BUFFER_SIZE);
- }
log_write(0, LOG_PANIC_DIE, "failed to write to %s: length=%d result=%d "
"errno=%d (%s)", name, length, rc, save_errno,
/* Ensure we have a buffer (see comment above); this should never be obeyed
when running Exim proper, only when running utilities. */
-if (log_buffer == NULL)
- {
- log_buffer = (uschar *)malloc(LOG_BUFFER_SIZE);
- if (log_buffer == NULL)
+if (!log_buffer)
+ if (!(log_buffer = US malloc(LOG_BUFFER_SIZE)))
{
fprintf(stderr, "exim: failed to get store for log buffer\n");
exim_exit(EXIT_FAILURE);
}
- }
/* If we haven't already done so, inspect the setting of log_file_path to
determine whether to log to files and/or to syslog. Bits in logging_mode
sock);
}
- if (!(drweb_fbuf = (uschar *) malloc (fsize_uint)))
+ if (!(drweb_fbuf = US malloc(fsize_uint)))
{
(void)close(drweb_fd);
return m_errlog_defer_3(scanent, NULL,
}
lseek(clam_fd, 0, SEEK_SET);
- if (!(clamav_fbuf = (uschar *) malloc (fsize_uint)))
+ if (!(clamav_fbuf = US malloc(fsize_uint)))
{
CLOSE_SOCKDATA; (void)close(clam_fd);
return m_errlog_defer_3(scanent, NULL,
mime_get_decode_file(uschar *pname, uschar *fname)
{
FILE *f = NULL;
-uschar *filename;
-
-filename = (uschar *)malloc(2048);
+uschar *filename = NULL;
if (pname && fname)
{
- (void)string_format(filename, 2048, "%s/%s", pname, fname);
+ filename = string_sprintf("%s/%s", pname, fname);
f = modefopen(filename,"wb+",SPOOL_MODE);
}
else if (!pname)
do
{
struct stat mystat;
- (void)string_format(filename, 2048,
- "%s/%s-%05u", pname, message_id, file_nr++);
+ filename = string_sprintf("%s/%s-%05u", pname, message_id, file_nr++);
/* security break */
if (file_nr >= 1024)
break;
}
/* set expansion variable */
+/*XXX ? not set if !pname ? */
mime_decoded_filename = filename;
return f;
we don't know what allocations the SHA routines might
do, not safe to use store_get()/store_reset(). */
- relaxed_data = malloc(len+1);
+ relaxed_data = store_malloc(len+1);
for (p = data; *p; p++)
{
sig = sig->next;
}
-if (relaxed_data) free(relaxed_data);
+if (relaxed_data) store_free(relaxed_data);
return PDKIM_OK;
}
queue_filename *first = NULL;
queue_filename **append = &first;
-while (a != NULL && b != NULL)
- {
+while (a && b)
if (Ustrcmp(a->text, b->text) < 0)
{
*append = a;
append= &b->next;
b = b->next;
}
- }
-*append=((a != NULL)? a : b);
+*append = a ? a : b;
return first;
}
current time. Use the bottom 16 and just keep re-using them if necessary. When
not randomizing, initialize the sublists for the bottom-up merge sort. */
-if (randomize) resetflags = time(NULL) & 0xFFFF;
- else for (i = 0; i < LOG2_MAXNODES; i++) root[i] = NULL;
+if (randomize)
+ resetflags = time(NULL) & 0xFFFF;
+else
+ for (i = 0; i < LOG2_MAXNODES; i++)
+ root[i] = NULL;
/* If processing the full queue, or just the top-level, start at the base
directory, and initialize the first subdirectory name (as none). Otherwise,
subdirs[0] = 0;
*subcount = 0;
}
-else i = subdiroffset;
+else
+ i = subdiroffset;
/* Set up prototype for the directory name. */
/* Now scan the directory. */
- while ((ent = readdir(dd)) != NULL)
+ while ((ent = readdir(dd)))
{
uschar *name = US ent->d_name;
int len = Ustrlen(name);
to store the number with each item. */
if (randomize)
- {
- if (yield == NULL)
+ if (!yield)
{
next->next = NULL;
yield = last = next;
}
else
{
- if (flags == 0) flags = resetflags;
+ if (flags == 0)
+ flags = resetflags;
if ((flags & 1) == 0)
{
next->next = yield;
}
flags = flags >> 1;
}
- }
/* Otherwise do a bottom-up merge sort based on the name. */
int j;
next->next = NULL;
for (j = 0; j < LOG2_MAXNODES; j++)
- {
- if (root[j] != NULL)
+ if (root[j])
{
next = merge_queue_lists(next, root[j]);
root[j] = (j == LOG2_MAXNODES - 1)? next : NULL;
root[j] = next;
break;
}
- }
}
}
}
/* If we have just scanned the base directory, and subdiroffset is 0,
we do not want to continue scanning the sub-directories. */
- else
- {
- if (subdiroffset == 0) break;
- }
+ else if (subdiroffset == 0)
+ break;
} /* Loop for multiple subdirectories */
/* When using a bottom-up merge sort, do the final merging of the sublists.
}
for (f = queue_get_spool_list(i, subdirs, &subcount, !queue_run_in_order);
- f != NULL;
+ f;
f = f->next)
{
pid_t pid;
check that the load average is low enough to permit deliveries. */
if (!queue_run_force && deliver_queue_load_max >= 0)
- {
- load_average = os_getloadavg();
- if (load_average > deliver_queue_load_max)
+ if ((load_average = os_getloadavg()) > deliver_queue_load_max)
{
log_write(L_queue_run, LOG_MAIN, "Abandon queue run: %s (load %.2f, max %.2f)",
log_detail,
break;
}
else
- {
DEBUG(D_load) debug_printf("load average = %.2f max = %.2f\n",
(double)load_average/1000.0,
(double)deliver_queue_load_max/1000.0);
- }
- }
/* Skip this message unless it's within the ID limits */
- if (stop_id != NULL && Ustrncmp(f->text, stop_id, MESSAGE_ID_LENGTH) > 0)
+ if (stop_id && Ustrncmp(f->text, stop_id, MESSAGE_ID_LENGTH) > 0)
continue;
- if (start_id != NULL && Ustrncmp(f->text, start_id, MESSAGE_ID_LENGTH) < 0)
+ if (start_id && Ustrncmp(f->text, start_id, MESSAGE_ID_LENGTH) < 0)
continue;
/* Check that the message still exists */
delivering, but it's cheaper than forking a delivery process for each
message when many are not going to be delivered. */
- if (deliver_selectstring != NULL || deliver_selectstring_sender != NULL ||
+ if (deliver_selectstring || deliver_selectstring_sender ||
queue_run_first_delivery)
{
BOOL wanted = TRUE;
wanted = FALSE;
}
- /* Check for a matching address if deliver_selectstring[_sender} is set.
+ /* Check for a matching address if deliver_selectstring[_sender] is set.
If so, we do a fully delivery - don't want to omit other addresses since
their routing might trigger re-writing etc. */
/* Sender matching */
- else if (deliver_selectstring_sender != NULL &&
- !(deliver_selectstring_sender_regex?
- (pcre_exec(selectstring_regex_sender, NULL, CS sender_address,
- Ustrlen(sender_address), 0, PCRE_EOPT, NULL, 0) >= 0)
- :
- (strstric(sender_address, deliver_selectstring_sender, FALSE)
- != NULL)))
+ else if ( deliver_selectstring_sender
+ && !(deliver_selectstring_sender_regex
+ ? (pcre_exec(selectstring_regex_sender, NULL,
+ CS sender_address, Ustrlen(sender_address), 0, PCRE_EOPT,
+ NULL, 0) >= 0)
+ : (strstric(sender_address, deliver_selectstring_sender, FALSE)
+ != NULL)
+ ) )
{
DEBUG(D_queue_run) debug_printf("%s: sender address did not match %s\n",
f->text, deliver_selectstring_sender);
/* Recipient matching */
- else if (deliver_selectstring != NULL)
+ else if (deliver_selectstring)
{
int i;
for (i = 0; i < recipients_count; i++)
{
uschar *address = recipients_list[i].address;
- if ((deliver_selectstring_regex?
- (pcre_exec(selectstring_regex, NULL, CS address,
- Ustrlen(address), 0, PCRE_EOPT, NULL, 0) >= 0)
- :
- (strstric(address, deliver_selectstring, FALSE) != NULL))
- &&
- tree_search(tree_nonrecipients, address) == NULL)
+ if ( (deliver_selectstring_regex
+ ? (pcre_exec(selectstring_regex, NULL, CS address,
+ Ustrlen(address), 0, PCRE_EOPT, NULL, 0) >= 0)
+ : (strstric(address, deliver_selectstring, FALSE) != NULL)
+ )
+ && tree_search(tree_nonrecipients, address) == NULL
+ )
break;
}
pretty cheap. */
if (pipe(pfd) < 0)
- {
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to create pipe in queue "
"runner process %d: %s", queue_run_pid, strerror(errno));
- }
queue_run_pipe = pfd[pipe_write]; /* To ensure it gets passed on. */
/* Make sure it isn't stdin. This seems unlikely, but just to be on the
/* If the process crashed, tell somebody */
else if ((status & 0x00ff) != 0)
- {
log_write(0, LOG_MAIN|LOG_PANIC,
"queue run: process %d crashed with signal %d while delivering %s",
(int)pid, status & 0x00ff, f->text);
- }
/* Before continuing, wait till the pipe gets closed at the far end. This
tells us that any children created by the delivery to re-use any SMTP
/* Allow for trailing 0 in the command and data buffers. */
-smtp_cmd_buffer = (uschar *)malloc(2*smtp_cmd_buffer_size + 2);
-if (smtp_cmd_buffer == NULL)
+if (!(smtp_cmd_buffer = US malloc(2*smtp_cmd_buffer_size + 2)))
log_write(0, LOG_MAIN|LOG_PANIC_DIE,
"malloc() failed for SMTP command buffer");
+
smtp_cmd_buffer[0] = 0;
smtp_data_buffer = smtp_cmd_buffer + smtp_cmd_buffer_size + 1;
if (smtp_batched_input)
{
- if (received_protocol == NULL) received_protocol = US"local-bsmtp";
+ if (!received_protocol) received_protocol = US"local-bsmtp";
}
/* For non-batched SMTP input, the protocol setting is forced here. It will be
/* Set up the buffer for inputting using direct read() calls, and arrange to
call the local functions instead of the standard C ones. */
-smtp_inbuffer = (uschar *)malloc(in_buffer_size);
-if (smtp_inbuffer == NULL)
+if (!(smtp_inbuffer = (uschar *)malloc(in_buffer_size)))
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "malloc() failed for SMTP input buffer");
+
receive_getc = smtp_getc;
receive_get_cache = smtp_get_cache;
receive_ungetc = smtp_ungetc;
void *yield;
if (size < 16) size = 16;
-yield = malloc((size_t)size);
-if (yield == NULL)
+if (!(yield = malloc((size_t)size)))
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to malloc %d bytes of memory: "
"called from line %d of %s", size, linenumber, filename);
(void)close(fd);
return tls_error(US"TLS cache not a file", NULL, NULL);
}
- fp = fdopen(fd, "rb");
- if (!fp)
+ if (!(fp = fdopen(fd, "rb")))
{
saved_errno = errno;
(void)close(fd);
}
m.size = statbuf.st_size;
- m.data = malloc(m.size);
- if (m.data == NULL)
+ if (!(m.data = malloc(m.size)))
{
fclose(fp);
return tls_error(US"malloc failed", strerror(errno), NULL);
}
- sz = fread(m.data, m.size, 1, fp);
- if (!sz)
+ if (!(sz = fread(m.data, m.size, 1, fp)))
{
saved_errno = errno;
fclose(fp);
if (rc != GNUTLS_E_SHORT_MEMORY_BUFFER)
exim_gnutls_err_check(US"gnutls_dh_params_export_pkcs3(NULL) sizing");
m.size = sz;
- m.data = malloc(m.size);
- if (m.data == NULL)
+ if (!(m.data = malloc(m.size)))
return tls_error(US"memory allocation failed", strerror(errno), NULL);
+
/* this will return a size 1 less than the allocation size above */
rc = gnutls_dh_params_export_pkcs3(dh_server_params, GNUTLS_X509_FMT_PEM,
m.data, &sz);
/* create an array to read entire message queue into memory for processing */
- msgq = (msgq_t*) malloc(sizeof(msgq_t) * host_record->count);
+ msgq = store_malloc(sizeof(msgq_t) * host_record->count);
msgq_count = host_record->count;
msgq_actual = msgq_count;
if (bFound) /* Usual exit from main loop */
{
- free (msgq);
+ store_free (msgq);
break;
}
return FALSE;
}
- free(msgq);
+ store_free(msgq);
} /* we need to process a continuation record */
/* Control gets here when an existing message has been encountered; its