While at it, get rid of lots of pointless explicit casts.
-const char actions_rcs[] = "$Id: actions.c,v 1.94 2016/01/16 12:29:30 fabiankeil Exp $";
+const char actions_rcs[] = "$Id: actions.c,v 1.95 2016/01/16 12:33:35 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/actions.c,v $
return 1; /* never get here */
}
- fs->f = last_perm = (struct url_actions *)zalloc(sizeof(*last_perm));
- if (last_perm == NULL)
- {
- log_error(LOG_LEVEL_FATAL, "can't load actions file '%s': out of memory!",
- csp->config->actions_file[fileid]);
- return 1; /* never get here */
- }
+ fs->f = last_perm = zalloc_or_die(sizeof(*last_perm));
if ((fp = fopen(csp->config->actions_file[fileid], "r")) == NULL)
{
cur_action = NULL;
}
cur_action_used = 0;
- cur_action = (struct action_spec *)zalloc(sizeof(*cur_action));
- if (cur_action == NULL)
- {
- fclose(fp);
- log_error(LOG_LEVEL_FATAL,
- "can't load actions file '%s': out of memory",
- csp->config->actions_file[fileid]);
- return 1; /* never get here */
- }
+ cur_action = zalloc_or_die(sizeof(*cur_action));
init_action(cur_action);
/*
return 1; /* never get here */
}
- if ((new_alias = zalloc(sizeof(*new_alias))) == NULL)
- {
- fclose(fp);
- log_error(LOG_LEVEL_FATAL,
- "can't load actions file '%s': out of memory!",
- csp->config->actions_file[fileid]);
- return 1; /* never get here */
- }
+ new_alias = zalloc_or_die(sizeof(*new_alias));
/* Eat any the whitespace before the '=' */
end--;
/* it's an URL pattern */
/* allocate a new node */
- if ((perm = zalloc(sizeof(*perm))) == NULL)
- {
- fclose(fp);
- log_error(LOG_LEVEL_FATAL,
- "can't load actions file '%s': out of memory!",
- csp->config->actions_file[fileid]);
- return 1; /* never get here */
- }
+ perm = zalloc_or_die(sizeof(*perm));
perm->action = cur_action;
cur_action_used = 1;
-const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.86 2014/10/18 11:29:48 fabiankeil Exp $";
+const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.87 2014/10/18 11:31:52 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $
return JB_ERR_PARSE;
}
- if ((new_alias = zalloc(sizeof(*new_alias))) == NULL)
- {
- /* Out of memory */
- free(name);
- free(value);
- free_alias_list(alias_list);
- return JB_ERR_MEMORY;
- }
+ new_alias = zalloc_or_die(sizeof(*new_alias));
err = get_actions(value, alias_list, new_alias->action);
if (err)
*pfile = NULL;
- cur_line = first_line = zalloc(sizeof(struct file_line));
- if (cur_line == NULL)
- {
- return JB_ERR_MEMORY;
- }
+ cur_line = first_line = zalloc_or_die(sizeof(struct file_line));
cur_line->type = FILE_LINE_UNPROCESSED;
do
{
prev_line = cur_line;
- cur_line = prev_line->next = zalloc(sizeof(struct file_line));
- if (cur_line == NULL)
- {
- /* Out of memory */
- edit_free_file_lines(first_line);
- return JB_ERR_MEMORY;
- }
+ cur_line = prev_line->next = zalloc_or_die(sizeof(struct file_line));
cur_line->type = FILE_LINE_UNPROCESSED;
return err;
}
- file = (struct editable_file *) zalloc(sizeof(*file));
- if (file == NULL)
- {
- edit_free_file_lines(lines);
- return err;
- }
+ file = zalloc_or_die(sizeof(*file));
file->lines = lines;
file->newline = newline;
/* At this point, the section header is in cur_line - add after this. */
/* Allocate the new line */
- new_line = (struct file_line *)zalloc(sizeof(*new_line));
- if (new_line == NULL)
- {
- free(new_pattern);
- edit_free_file(file);
- return JB_ERR_MEMORY;
- }
+ new_line = zalloc_or_die(sizeof(*new_line));
/* Fill in the data members of the new line */
new_line->raw = NULL;
}
/* Allocate the new line */
- new_line = (struct file_line *)zalloc(sizeof(*new_line));
- if (new_line == NULL)
- {
- free(new_text);
- edit_free_file(file);
- return JB_ERR_MEMORY;
- }
+ new_line = zalloc_or_die(sizeof(*new_line));
/* Fill in the data members of the new line */
new_line->raw = NULL;
-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.131 2014/10/18 11:28:49 fabiankeil Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.132 2015/11/06 13:38:13 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
filename);
}
- *buffer = (char *)zalloc(*length + 1);
- if (NULL == *buffer)
- {
- err = JB_ERR_MEMORY;
- }
- else if (1 != fread(*buffer, *length, 1, fp))
+ *buffer = zalloc_or_die(*length + 1);
+
+ if (1 != fread(*buffer, *length, 1, fp))
{
/*
* May theoretically happen if the file size changes between
-const char deanimate_rcs[] = "$Id: deanimate.c,v 1.22 2011/12/31 14:47:44 fabiankeil Exp $";
+const char deanimate_rcs[] = "$Id: deanimate.c,v 1.23 2012/03/09 16:24:36 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/deanimate.c,v $
/*
* Reserve a buffer for the current image block
*/
- if (NULL == (image = (struct binbuffer *)zalloc(sizeof(*image))))
- {
- return 1;
- }
+ image = zalloc_or_die(sizeof(*image));
/*
* Parse the GIF block by block and copy the relevant
-const char errlog_rcs[] = "$Id: errlog.c,v 1.124 2016/01/21 20:53:01 diem Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.125 2016/01/26 17:12:14 diem Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
if (NULL == outbuf_save)
{
- outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
- if (NULL == outbuf_save)
- {
- snprintf(tempbuf, sizeof(tempbuf),
- "%s %08lx Fatal error: Out of memory in log_error().",
- timestamp, thread_id);
- fatal_error(tempbuf); /* Exit */
- return;
- }
+ outbuf_save = zalloc_or_die(log_buffer_size + 1); /* +1 for paranoia */
}
outbuf = outbuf_save;
-const char filters_rcs[] = "$Id: filters.c,v 1.198 2016/01/16 12:30:43 fabiankeil Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.199 2016/01/16 12:33:35 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.c,v $
size = (size_t)(csp->iob->eod - csp->iob->cur);
- if ( (NULL == (in = (struct binbuffer *)zalloc(sizeof *in )))
- || (NULL == (out = (struct binbuffer *)zalloc(sizeof *out))) )
- {
- log_error(LOG_LEVEL_DEANIMATE, "failed! (no mem)");
- return NULL;
- }
+ in = zalloc_or_die(sizeof(*in));
+ out = zalloc_or_die(sizeof(*out));
in->buffer = csp->iob->cur;
in->size = size;
* the lifetime of this request. Save its location
* in csp as well, so sweep() can free it later on.
*/
- fwd = csp->fwd = zalloc(sizeof(*fwd));
- if (NULL == fwd)
- {
- log_error(LOG_LEVEL_FATAL,
- "can't allocate memory for forward-override{%s}", forward_override_line);
- /* Never get here - LOG_LEVEL_FATAL causes program exit */
- return NULL;
- }
+ fwd = csp->fwd = zalloc_or_die(sizeof(*fwd));
vec_count = ssplit(forward_settings, " \t", vec, SZ(vec));
if ((vec_count == 2) && !strcasecmp(vec[0], "forward"))
-const char jcc_rcs[] = "$Id: jcc.c,v 1.439 2016/01/16 12:33:03 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.440 2016/01/16 12:33:36 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
}
#endif
- csp_list = (struct client_states *)zalloc(sizeof(*csp_list));
- if (NULL == csp_list)
- {
- log_error(LOG_LEVEL_FATAL,
- "malloc(%d) for csp_list failed: %E", sizeof(*csp_list));
- continue;
- }
+ csp_list = zalloc_or_die(sizeof(*csp_list));
csp = &csp_list->csp;
log_error(LOG_LEVEL_CONNECT,
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.144 2015/12/27 12:50:42 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.145 2016/01/16 12:33:36 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
global_toggle_state = 1;
#endif /* def FEATURE_TOGGLE */
- fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config));
-
- if (NULL == config)
- {
- freez(fs->filename);
- freez(fs);
- log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
- return NULL;
- }
+ fs->f = config = zalloc_or_die(sizeof(*config));
/*
* This is backwards from how it's usually done.
}
/* allocate a new node */
- cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
-
- if (cur_acl == NULL)
- {
- log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
- /* Never get here - LOG_LEVEL_FATAL causes program exit */
- break;
- }
+ cur_acl = zalloc_or_die(sizeof(*cur_acl));
cur_acl->action = ACL_DENY;
if (acl_addr(vec[0], cur_acl->src) < 0)
}
/* allocate a new node */
- cur_fwd = zalloc(sizeof(*cur_fwd));
- if (cur_fwd == NULL)
- {
- log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
- /* Never get here - LOG_LEVEL_FATAL causes program exit */
- break;
- }
-
+ cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
cur_fwd->type = SOCKS_NONE;
/* Save the URL pattern */
}
/* allocate a new node */
- cur_fwd = zalloc(sizeof(*cur_fwd));
- if (cur_fwd == NULL)
- {
- log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
- /* Never get here - LOG_LEVEL_FATAL causes program exit */
- break;
- }
-
+ cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
cur_fwd->type = SOCKS_4;
/* Save the URL pattern */
}
/* allocate a new node */
- cur_fwd = zalloc(sizeof(*cur_fwd));
- if (cur_fwd == NULL)
- {
- log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
- /* Never get here - LOG_LEVEL_FATAL causes program exit */
- break;
- }
+ cur_fwd = zalloc_or_die(sizeof(*cur_fwd));
if (directive_hash == hash_forward_socks4a)
{
}
/* allocate a new node */
- cur_acl = (struct access_control_list *) zalloc(sizeof(*cur_acl));
-
- if (cur_acl == NULL)
- {
- log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration");
- /* Never get here - LOG_LEVEL_FATAL causes program exit */
- break;
- }
+ cur_acl = zalloc_or_die(sizeof(*cur_acl));
cur_acl->action = ACL_PERMIT;
if (acl_addr(vec[0], cur_acl->src) < 0)
*
* Need to set up a fake csp, so they can get to the config.
*/
- fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp));
+ fake_csp = zalloc_or_die(sizeof(*fake_csp));
fake_csp->config = config;
if (run_loader(fake_csp))
-const char loaders_rcs[] = "$Id: loaders.c,v 1.99 2014/06/02 06:22:21 fabiankeil Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.100 2015/01/24 16:40:21 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
return 0;
}
- fs = (struct file_list *)zalloc(sizeof(struct file_list));
- if (fs == NULL)
- {
- /* Out of memory error */
- return 1;
- }
-
-
+ fs = zalloc_or_die(sizeof(struct file_list));
fs->filename = strdup(filename);
fs->lastmodified = statbuf->st_mtime;
goto load_trustfile_error;
}
- fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- goto load_trustfile_error;
- }
+ fs->f = bl = zalloc_or_die(sizeof(*bl));
if ((fp = fopen(csp->config->trustfile, "r")) == NULL)
{
}
/* allocate a new node */
- if ((b = zalloc(sizeof(*b))) == NULL)
- {
- fclose(fp);
- goto load_trustfile_error;
- }
+ b = zalloc_or_die(sizeof(*b));
/* add it to the list */
b->next = bl->next;
*/
if (new_filter != FT_INVALID_FILTER)
{
- new_bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl));
- if (new_bl == NULL)
- {
- goto load_re_filterfile_error;
- }
+ new_bl = zalloc_or_die(sizeof(*bl));
if (new_filter == FT_CONTENT_FILTER)
{
new_bl->name = chomp(buf + 7);
-const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.85 2014/07/25 11:56:26 fabiankeil Exp $";
+const char urlmatch_rcs[] = "$Id: urlmatch.c,v 1.86 2015/12/27 12:47:17 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/urlmatch.c,v $
* 4 : regex = Where the compiled regex should be stored.
*
* Returns : JB_ERR_OK - Success
- * JB_ERR_MEMORY - Out of memory
* JB_ERR_PARSE - Cannot parse regex
*
*********************************************************************/
"Invalid anchoring in compile_pattern %d", anchoring);
}
- *regex = zalloc(sizeof(**regex));
- if (NULL == *regex)
- {
- free_pattern_spec(url);
- return JB_ERR_MEMORY;
- }
+ *regex = zalloc_or_die(sizeof(**regex));
snprintf(rebuf, sizeof(rebuf), fmt, pattern);