This makes the code more readable and less prone to copy-paste errors.
In addition, it allows to place some __builtin_constant_p() predicates
to trigger a link-time error in case the compiler knows that the freed
area is constant. It will also produce compile-time error if trying to
free something that is not a regular pointer (e.g. a function).
The DEBUG_MEM_STATS macro now also defines an instance for ha_free()
so that all these calls can be checked.
178 occurrences were converted. The vast majority of them were handled
by the following Coccinelle script, some slightly refined to better deal
with "&*x" or with long lines:
@ rule @
expression E;
@@
- free(E);
- E = NULL;
+ ha_free(&E);
It was verified that the resulting code is the same, more or less a
handful of cases where the compiler optimized slightly differently
the temporary variable that holds the copy of the pointer.
A non-negligible amount of {free(str);str=NULL;str_len=0;} are still
present in the config part (mostly header names in proxies). These
ones should also be cleaned for the same reasons, and probably be
turned into ist strings.
#define BUG_ON(cond)
#endif
+/* more reliable free() that clears the pointer */
+#define ha_free(x) do { \
+ typeof(x) __x = (x); \
+ if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \
+ /* provoke a build-time error */ \
+ extern volatile int call_to_ha_free_attempts_to_free_a_constant; \
+ call_to_ha_free_attempts_to_free_a_constant = 1; \
+ } \
+ free(*__x); \
+ *__x = NULL; \
+ } while (0)
#if defined(DEBUG_MEM_STATS)
#include <stdlib.h>
free(__x); \
})
+#undef ha_free
+#define ha_free(x) ({ \
+ typeof(x) __x = (x); \
+ static struct mem_stats _ __attribute__((used,__section__("mem_stats"))) = { \
+ .file = __FILE__, .line = __LINE__, \
+ .type = MEM_STATS_TYPE_FREE, \
+ }; \
+ __asm__(".globl __start_mem_stats"); \
+ __asm__(".globl __stop_mem_stats"); \
+ if (__builtin_constant_p((x)) || __builtin_constant_p(*(x))) { \
+ /* provoke a build-time error */ \
+ extern volatile int call_to_ha_free_attempts_to_free_a_constant; \
+ call_to_ha_free_attempts_to_free_a_constant = 1; \
+ } \
+ if (*__x) \
+ _HA_ATOMIC_ADD(&_.calls, 1); \
+ free(*__x); \
+ *__x = NULL; \
+})
+
#undef malloc
#define malloc(x) ({ \
size_t __x = (x); \
#endif
fiftyoneDegreesDataSetFree(&global_51degrees.data_set);
- free(global_51degrees.data_file_path); global_51degrees.data_file_path = NULL;
+ ha_free(&global_51degrees.data_file_path);
list_for_each_entry_safe(_51d_prop_name, _51d_prop_nameb, &global_51degrees.property_names, list) {
LIST_DEL(&_51d_prop_name->list);
free(_51d_prop_name);
goto out_free_smp;
}
}
- free(ckw);
- ckw = NULL;
+ ha_free(&ckw);
}
else {
/* This is not an ACL keyword, so we hope this is a sample fetch
* in between, there is no arg at all.
*/
if (!pos) {
- free(*argp);
- *argp = NULL;
+ ha_free(argp);
}
if (pos >= min_arg)
curuser->u.groups = grl;
}
- free(ag->groupusers);
- ag->groupusers = NULL;
+ ha_free(&ag->groupusers);
}
#ifdef DEBUG_AUTH
return err_code;
}
out:
- free(tmp_cache_config);
- tmp_cache_config = NULL;
+ ha_free(&tmp_cache_config);
return err_code;
}
curproxy->ck_opts = 0;
curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0;
- free(curproxy->cookie_domain); curproxy->cookie_domain = NULL;
+ ha_free(&curproxy->cookie_domain);
free(curproxy->cookie_name);
curproxy->cookie_name = strdup(args[1]);
curproxy->cookie_len = strlen(curproxy->cookie_name);
if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out;
- free(curproxy->server_state_file_name);
- curproxy->server_state_file_name = NULL;
+ ha_free(&curproxy->server_state_file_name);
if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
curproxy->server_state_file_name = strdup(curproxy->id);
/* we must first clear any optional default setting */
curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK;
- free(curproxy->conn_src.iface_name);
- curproxy->conn_src.iface_name = NULL;
+ ha_free(&curproxy->conn_src.iface_name);
curproxy->conn_src.iface_len = 0;
sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
ssl_load_global_issuer_from_BIO(in, fp, &warn);
if (warn) {
ha_warning("%s", warn);
- free(warn);
- warn = NULL;
+ ha_free(&warn);
}
next:
if (in)
static int srv_parse_no_check_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
{
newsrv->check.use_ssl = -1;
- free(newsrv->ssl_ctx.ciphers);
- newsrv->ssl_ctx.ciphers = NULL;
+ ha_free(&newsrv->ssl_ctx.ciphers);
newsrv->ssl_ctx.options &= ~global_ssl.connect_default_ssloptions;
return 0;
}
if (newsrv->use_ssl == 1)
ssl_sock_init_srv(newsrv);
else {
- free(newsrv->ssl_ctx.ciphers);
- newsrv->ssl_ctx.ciphers = NULL;
+ ha_free(&newsrv->ssl_ctx.ciphers);
}
newsrv->use_ssl = -1;
return 0;
void free_email_alert(struct proxy *p)
{
- free(p->email_alert.mailers.name);
- p->email_alert.mailers.name = NULL;
- free(p->email_alert.from);
- p->email_alert.from = NULL;
- free(p->email_alert.to);
- p->email_alert.to = NULL;
- free(p->email_alert.myhostname);
- p->email_alert.myhostname = NULL;
+ ha_free(&p->email_alert.mailers.name);
+ ha_free(&p->email_alert.from);
+ ha_free(&p->email_alert.to);
+ ha_free(&p->email_alert.myhostname);
}
err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT;
}
err:
- free(cfg_scope);
- cfg_scope = NULL;
+ ha_free(&cfg_scope);
cursection = NULL;
free(thisline);
free(outline);
* allocated yet) but let's skip them.
*/
if (curproxy->table) {
- free((void *)curproxy->table->peers.name);
- curproxy->table->peers.name = NULL;
+ ha_free(&curproxy->table->peers.name);
curproxy->table->peers.p = NULL;
}
continue;
cfgerr++;
}
if (clear) {
- free(curproxy->check_command);
- curproxy->check_command = NULL;
+ ha_free(&curproxy->check_command);
}
}
ha_warning("config : '%s' will be ignored for %s '%s' (requires 'option external-check').\n",
"external-check path", proxy_type_str(curproxy), curproxy->id);
err_code |= ERR_WARN;
- free(curproxy->check_path);
- curproxy->check_path = NULL;
+ ha_free(&curproxy->check_path);
}
}
LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list);
if (curproxy->uri_auth->auth_realm) {
- free(curproxy->uri_auth->auth_realm);
- curproxy->uri_auth->auth_realm = NULL;
+ ha_free(&curproxy->uri_auth->auth_realm);
}
curproxy->uri_auth->flags |= STAT_CONVDONE;
}
curproxy->conf.logformat_string != clf_http_log_format)
free(curproxy->conf.logformat_string);
curproxy->conf.logformat_string = NULL;
- free(curproxy->conf.lfs_file);
- curproxy->conf.lfs_file = NULL;
+ ha_free(&curproxy->conf.lfs_file);
curproxy->conf.lfs_line = 0;
if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
free(curproxy->conf.logformat_sd_string);
curproxy->conf.logformat_sd_string = NULL;
- free(curproxy->conf.lfsd_file);
- curproxy->conf.lfsd_file = NULL;
+ ha_free(&curproxy->conf.lfsd_file);
curproxy->conf.lfsd_line = 0;
}
newsrv->tracknext = srv->trackers;
srv->trackers = newsrv;
- free(newsrv->trackit);
- newsrv->trackit = NULL;
+ ha_free(&newsrv->trackit);
}
next_srv:
check_release_buf(check, &check->bi);
check_release_buf(check, &check->bo);
if (check->cs) {
- free(check->cs->conn);
- check->cs->conn = NULL;
+ ha_free(&check->cs->conn);
cs_free(check->cs);
check->cs = NULL;
}
{
if (srv->agent.tcpcheck_rules) {
free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars);
- free(srv->agent.tcpcheck_rules);
- srv->agent.tcpcheck_rules = NULL;
+ ha_free(&srv->agent.tcpcheck_rules);
}
if (srv->agent.state & CHK_ST_CONFIGURED)
struct buffer *tmp = get_trash_chunk();
struct buffer out;
- free(dynamic_usage_msg);
- dynamic_usage_msg = NULL;
+ ha_free(&dynamic_usage_msg);
if (LIST_ISEMPTY(&cli_keywords.list))
goto end;
if (cli_output_msg(res, msg, sev, cli_get_severity_output(appctx)) != -1) {
if (appctx->st0 == CLI_ST_PRINT_FREE ||
appctx->st0 == CLI_ST_PRINT_DYN) {
- free(appctx->ctx.cli.err);
- appctx->ctx.cli.err = NULL;
+ ha_free(&appctx->ctx.cli.err);
}
appctx->st0 = CLI_ST_PROMPT;
}
appctx->io_release = NULL;
}
else if (appctx->st0 == CLI_ST_PRINT_FREE || appctx->st0 == CLI_ST_PRINT_DYN) {
- free(appctx->ctx.cli.err);
- appctx->ctx.cli.err = NULL;
+ ha_free(&appctx->ctx.cli.err);
}
}
&errmsg, NULL, NULL, PA_O_STREAM)) == 0) {
goto error;
}
- free(msg);
- msg = NULL;
+ ha_free(&msg);
if (!proto->connect) {
goto error;
list_for_each_entry(child, &proc_list, list) {
free((char *)child->srv->conf.file); /* cast because of const char * */
free(child->srv->id);
- free(child->srv);
- child->srv = NULL;
+ ha_free(&child->srv);
}
free(mworker_proxy->id);
free(mworker_proxy->conf.file);
- free(mworker_proxy);
- mworker_proxy = NULL;
+ ha_free(&mworker_proxy);
free(errmsg);
free(msg);
ha_alert("Cannot create a CLI sockpair listener for process #%d\n", proc);
goto error;
}
- free(path);
- path = NULL;
+ ha_free(&path);
list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->accept = session_accept_fd;
return de;
err:
- free(de->value.key);
- de->value.key = NULL;
+ ha_free(&de->value.key);
de->len = 0;
free(de);
return NULL;
static void free_dict_entry(struct dict_entry *de)
{
de->refcount = 0;
- free(de->value.key);
- de->value.key = NULL;
+ ha_free(&de->value.key);
free(de);
}
void deinit_dns_buffers()
{
- free(dns_msg_trash);
- dns_msg_trash = NULL;
+ ha_free(&dns_msg_trash);
}
REGISTER_PER_THREAD_ALLOC(init_dns_buffers);
if (MAX_THREADS > 1 && tid)
close(epoll_fd[tid]);
- free(epoll_events);
- epoll_events = NULL;
+ ha_free(&epoll_events);
}
/*
return 1;
fail_fd:
- free(evports_evlist);
- evports_evlist = NULL;
+ ha_free(&evports_evlist);
evports_evlist_max = 0;
fail_alloc:
return 0;
if (MAX_THREADS > 1 && tid)
close(evports_fd[tid]);
- free(evports_evlist);
- evports_evlist = NULL;
+ ha_free(&evports_evlist);
evports_evlist_max = 0;
}
p->private = NULL;
p->pref = 0;
- free(evports_evlist);
- evports_evlist = NULL;
+ ha_free(&evports_evlist);
evports_evlist_max = 0;
}
if (MAX_THREADS > 1 && tid)
close(kqueue_fd[tid]);
- free(kev);
- kev = NULL;
+ ha_free(&kev);
}
/*
return 1;
fail_fd:
- free(kev_out);
- kev_out = NULL;
+ ha_free(&kev_out);
fail_alloc:
p->pref = 0;
return 0;
p->private = NULL;
p->pref = 0;
if (kev_out) {
- free(kev_out);
- kev_out = NULL;
+ ha_free(&kev_out);
}
}
static void deinit_poll_per_thread()
{
- free(poll_events);
- poll_events = NULL;
+ ha_free(&poll_events);
}
/*
static void deinit_select_per_thread()
{
- free(tmp_evts[DIR_WR]);
- tmp_evts[DIR_WR] = NULL;
- free(tmp_evts[DIR_RD]);
- tmp_evts[DIR_RD] = NULL;
+ ha_free(&tmp_evts[DIR_WR]);
+ ha_free(&tmp_evts[DIR_RD]);
}
/*
if (check->envp) {
for (i = 0; i < EXTCHK_SIZE; i++)
free(check->envp[i]);
- free(check->envp);
- check->envp = NULL;
+ ha_free(&check->envp);
}
if (check->argv) {
for (i = 1; i < 5; i++)
free(check->argv[i]);
- free(check->argv);
- check->argv = NULL;
+ ha_free(&check->argv);
}
return 0;
}
/* Place the filter at its right position */
LIST_DEL(&f->list);
free(f);
- free(name);
- name = NULL;
+ ha_free(&name);
break;
}
/* Release the pollers per thread, to be called late */
static void free_pollers_per_thread()
{
- free(fd_updt);
- fd_updt = NULL;
+ ha_free(&fd_updt);
}
/*
bp->term(bp);
}
- free(fdinfo); fdinfo = NULL;
- free(fdtab); fdtab = NULL;
- free(polled_mask); polled_mask = NULL;
+ ha_free(&fdinfo);
+ ha_free(&fdtab);
+ ha_free(&polled_mask);
}
/*
}
}
- free(conf->agent->b.name);
- conf->agent->b.name = NULL;
+ ha_free(&conf->agent->b.name);
conf->agent->b.be = target;
return 0;
}
execvp(next_argv[0], next_argv);
ha_warning("Failed to reexecute the master process [%d]: %s\n", pid, strerror(errno));
- free(next_argv);
- next_argv = NULL;
+ ha_free(&next_argv);
return;
alloc_error:
- free(next_argv);
- next_argv = NULL;
+ ha_free(&next_argv);
ha_warning("Failed to reexecute the master process [%d]: Cannot allocate memory\n", pid);
return;
}
list_for_each_entry(pdf, &post_deinit_list, list)
pdf->fct();
- free(global.log_send_hostname); global.log_send_hostname = NULL;
+ ha_free(&global.log_send_hostname);
chunk_destroy(&global.log_tag);
- free(global.chroot); global.chroot = NULL;
- free(global.pidfile); global.pidfile = NULL;
- free(global.node); global.node = NULL;
- free(global.desc); global.desc = NULL;
- free(oldpids); oldpids = NULL;
- free(old_argv); old_argv = NULL;
- free(localpeer); localpeer = NULL;
- free(global.server_state_base); global.server_state_base = NULL;
- free(global.server_state_file); global.server_state_file = NULL;
+ ha_free(&global.chroot);
+ ha_free(&global.pidfile);
+ ha_free(&global.node);
+ ha_free(&global.desc);
+ ha_free(&oldpids);
+ ha_free(&old_argv);
+ ha_free(&localpeer);
+ ha_free(&global.server_state_base);
+ ha_free(&global.server_state_file);
task_destroy(idle_conn_task);
idle_conn_task = NULL;
if ((getenv("HAPROXY_MWORKER_REEXEC") == NULL)) {
nb_oldpids = 0;
- free(oldpids);
- oldpids = NULL;
+ ha_free(&oldpids);
}
}
/* We won't ever use this anymore */
- free(global.pidfile); global.pidfile = NULL;
+ ha_free(&global.pidfile);
if (proc == global.nbproc) {
if (global.mode & (MODE_MWORKER|MODE_MWORKER_WAIT)) {
}
}
- free(global.chroot);
- global.chroot = NULL;
+ ha_free(&global.chroot);
set_identity(argv[0]);
/* pass through every cli socket, and check if it's bound to
static void free_raw_htx_chunk_per_thread()
{
- free(static_raw_htx_buf);
- static_raw_htx_buf = NULL;
+ ha_free(&static_raw_htx_buf);
}
REGISTER_PER_THREAD_ALLOC(alloc_raw_htx_chunk_per_thread);
if (!http_reply)
return;
- free(http_reply->ctype);
- http_reply->ctype = NULL;
+ ha_free(&http_reply->ctype);
list_for_each_entry_safe(hdr, hdrb, &http_reply->hdrs, list) {
LIST_DEL(&hdr->list);
list_for_each_entry_safe(lf, lfb, &hdr->value, list) {
}
if (http_reply->type == HTTP_REPLY_ERRFILES) {
- free(http_reply->body.http_errors);
- http_reply->body.http_errors = NULL;
+ ha_free(&http_reply->body.http_errors);
}
else if (http_reply->type == HTTP_REPLY_RAW)
chunk_destroy(&http_reply->body.obj);
}
/* Reset errmsg */
- free(errmsg);
- errmsg = NULL;
+ ha_free(&errmsg);
http_err_chunks[rc] = chk;
http_err_replies[rc].type = HTTP_REPLY_ERRMSG;
ha_warning("parsing [%s:%d] : content-type '%s' ignored by the http reply because"
" neither errorfile nor payload defined.\n",
px->conf.args.file, px->conf.args.line, reply->ctype);
- free(reply->ctype);
- reply->ctype = NULL;
+ ha_free(&reply->ctype);
}
}
else if (reply->type == HTTP_REPLY_ERRFILES || reply->type == HTTP_REPLY_ERRMSG) { /* errorfiles or errorfile */
ha_warning("parsing [%s:%d] : content-type '%s' ignored by the http reply when used "
"with an erorrfile.\n",
px->conf.args.file, px->conf.args.line, reply->ctype);
- free(reply->ctype);
- reply->ctype = NULL;
+ ha_free(&reply->ctype);
}
if (!LIST_ISEMPTY(&reply->hdrs)) {
ha_warning("parsing [%s:%d] : hdr parameters ignored by the http reply when used "
ha_warning("parsing [%s:%d] : content-type '%s' ignored by the http reply when used "
"with an empty payload.\n",
px->conf.args.file, px->conf.args.line, reply->ctype);
- free(reply->ctype);
- reply->ctype = NULL;
+ ha_free(&reply->ctype);
}
if (b_room(&reply->body.obj) < global.tune.maxrewrite) {
ha_warning("parsing [%s:%d] : http reply payload runs over the buffer space reserved to headers rewriting."
free_tcpcheck(rule, 1);
}
free_tcpcheck_vars(&alert->rules.preset_vars);
- free(alert->rules.list);
- alert->rules.list = NULL;
+ ha_free(&alert->rules.list);
}
pool_free(pool_head_email_alert, alert);
}
static void cli_release_mlook(struct appctx *appctx)
{
- free(appctx->ctx.map.chunk.area);
- appctx->ctx.map.chunk.area = NULL;
+ ha_free(&appctx->ctx.map.chunk.area);
}
int i;
for (i = 0; ext_child->command[i]; i++) {
- free(ext_child->command[i]);
- ext_child->command[i] = NULL;
+ ha_free(&ext_child->command[i]);
}
- free(ext_child->command);
- ext_child->command = NULL;
+ ha_free(&ext_child->command);
}
- free(ext_child->id);
- ext_child->id = NULL;
+ ha_free(&ext_child->id);
}
- free(ext_child);
- ext_child = NULL;
+ ha_free(&ext_child);
out:
return err_code;
chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>", "<version>");
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", (unsigned int)getpid(), "master", 0, proc_self->reloads, uptime, haproxy_version);
- free(uptime);
- uptime = NULL;
+ ha_free(&uptime);
/* displays current processes */
}
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime, child->version);
- free(uptime);
- uptime = NULL;
+ ha_free(&uptime);
}
/* displays old processes */
memprintf(&msg, "[was: %u]", child->relative_pid);
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, "worker", msg, child->reloads, uptime, child->version);
- free(uptime);
- uptime = NULL;
+ ha_free(&uptime);
}
}
free(msg);
}
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-");
- free(uptime);
- uptime = NULL;
+ ha_free(&uptime);
}
if (old) {
if (child->options & PROC_O_LEAVING) {
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-");
- free(uptime);
- uptime = NULL;
+ ha_free(&uptime);
}
}
}
for (i = 0; child->command[i]; i++) {
if (child->command[i]) {
- free(child->command[i]);
- child->command[i] = NULL;
+ ha_free(&child->command[i]);
}
}
- free(child->command);
- child->command = NULL;
+ ha_free(&child->command);
}
if (child->id) {
- free(child->id);
- child->id = NULL;
+ ha_free(&child->id);
}
if (child->version) {
- free(child->version);
- child->version = NULL;
+ ha_free(&child->version);
}
free(child);
}
*err = *merr;
} else {
memprintf(err, "%s, %s", *err, *merr);
- free(*merr);
- *merr = NULL;
+ ha_free(merr);
}
}
}
else if (lerr & ERR_WARN)
ha_warning("Starting %s %s: %s\n",
proxy_type_str(px), px->id, errmsg);
- free(errmsg); errmsg = NULL;
+ ha_free(&errmsg);
}
if (lerr & ERR_ABORT)
break;
*/
void proxy_free_defaults(struct proxy *defproxy)
{
- free(defproxy->id); defproxy->id = NULL;
- free(defproxy->conf.file); defproxy->conf.file = NULL;
- free(defproxy->check_command); defproxy->check_command = NULL;
- free(defproxy->check_path); defproxy->check_path = NULL;
- free(defproxy->cookie_name); defproxy->cookie_name = NULL;
- free(defproxy->rdp_cookie_name); defproxy->rdp_cookie_name = NULL;
- free(defproxy->dyncookie_key); defproxy->dyncookie_key = NULL;
- free(defproxy->cookie_domain); defproxy->cookie_domain = NULL;
- free(defproxy->cookie_attrs); defproxy->cookie_attrs = NULL;
- free(defproxy->lbprm.arg_str); defproxy->lbprm.arg_str = NULL;
- free(defproxy->capture_name); defproxy->capture_name = NULL;
- free(defproxy->monitor_uri); defproxy->monitor_uri = NULL;
- free(defproxy->defbe.name); defproxy->defbe.name = NULL;
- free(defproxy->conn_src.iface_name); defproxy->conn_src.iface_name = NULL;
- free(defproxy->fwdfor_hdr_name); defproxy->fwdfor_hdr_name = NULL; defproxy->fwdfor_hdr_len = 0;
- free(defproxy->orgto_hdr_name); defproxy->orgto_hdr_name = NULL; defproxy->orgto_hdr_len = 0;
- free(defproxy->server_id_hdr_name); defproxy->server_id_hdr_name = NULL; defproxy->server_id_hdr_len = 0;
+ ha_free(&defproxy->id);
+ ha_free(&defproxy->conf.file);
+ ha_free(&defproxy->check_command);
+ ha_free(&defproxy->check_path);
+ ha_free(&defproxy->cookie_name);
+ ha_free(&defproxy->rdp_cookie_name);
+ ha_free(&defproxy->dyncookie_key);
+ ha_free(&defproxy->cookie_domain);
+ ha_free(&defproxy->cookie_attrs);
+ ha_free(&defproxy->lbprm.arg_str);
+ ha_free(&defproxy->capture_name);
+ ha_free(&defproxy->monitor_uri);
+ ha_free(&defproxy->defbe.name);
+ ha_free(&defproxy->conn_src.iface_name);
+ ha_free(&defproxy->fwdfor_hdr_name); defproxy->fwdfor_hdr_len = 0;
+ ha_free(&defproxy->orgto_hdr_name); defproxy->orgto_hdr_len = 0;
+ ha_free(&defproxy->server_id_hdr_name); defproxy->server_id_hdr_len = 0;
if (defproxy->conf.logformat_string != default_http_log_format &&
defproxy->conf.logformat_string != default_tcp_log_format &&
defproxy->conf.logformat_string != clf_http_log_format) {
- free(defproxy->conf.logformat_string);
- defproxy->conf.logformat_string = NULL;
+ ha_free(&defproxy->conf.logformat_string);
}
- if (defproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) {
- free(defproxy->conf.logformat_sd_string);
- defproxy->conf.logformat_sd_string = NULL;
- }
+ if (defproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format)
+ ha_free(&defproxy->conf.logformat_sd_string);
- free(defproxy->conf.uniqueid_format_string); defproxy->conf.uniqueid_format_string = NULL;
- free(defproxy->conf.lfs_file); defproxy->conf.lfs_file = NULL;
- free(defproxy->conf.lfsd_file); defproxy->conf.lfsd_file = NULL;
- free(defproxy->conf.uif_file); defproxy->conf.uif_file = NULL;
+ ha_free(&defproxy->conf.uniqueid_format_string);
+ ha_free(&defproxy->conf.lfs_file);
+ ha_free(&defproxy->conf.lfsd_file);
+ ha_free(&defproxy->conf.uif_file);
chunk_destroy(&defproxy->log_tag);
free_email_alert(defproxy);
for (s = px->srv; s != NULL; s = s->next) {
HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
- if (!(s->flags & SRV_F_COOKIESET)) {
- free(s->cookie);
- s->cookie = NULL;
- }
+ if (!(s->flags & SRV_F_COOKIESET))
+ ha_free(&s->cookie);
HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
}
item->data_len == srv->hostname_dn_len &&
!resolv_hostname_cmp(srv->hostname_dn, item->target, item->data_len)) {
snr_update_srv_status(srv, 1);
- free(srv->hostname);
- free(srv->hostname_dn);
- srv->hostname = NULL;
- srv->hostname_dn = NULL;
+ ha_free(&srv->hostname);
+ ha_free(&srv->hostname_dn);
srv->hostname_dn_len = 0;
memset(&srv->addr, 0, sizeof(srv->addr));
srv->svc_port = 0;
return 0;
err:
- free(stream->resolv_ctx.hostname_dn); stream->resolv_ctx.hostname_dn = NULL;
+ ha_free(&stream->resolv_ctx.hostname_dn);
resolv_failed_resolutions += 1;
return -1;
}
return ret;
release_requester:
- free(s->resolv_ctx.hostname_dn);
- s->resolv_ctx.hostname_dn = NULL;
+ ha_free(&s->resolv_ctx.hostname_dn);
s->resolv_ctx.hostname_dn_len = 0;
if (s->resolv_ctx.requester) {
resolv_unlink_resolution(s->resolv_ctx.requester);
return ACT_RET_PRS_OK;
do_resolve_parse_error:
- free(rule->arg.resolv.varname); rule->arg.resolv.varname = NULL;
- free(rule->arg.resolv.resolvers_id); rule->arg.resolv.resolvers_id = NULL;
+ ha_free(&rule->arg.resolv.varname);
+ ha_free(&rule->arg.resolv.resolvers_id);
memprintf(err, "Can't parse '%s'. Expects 'do-resolve(<varname>,<resolvers>[,<options>]) <expr>'. Available options are 'ipv4' and 'ipv6'",
args[cur_arg]);
return ACT_RET_PRS_ERR;
return 0;
err:
- free(srv->hostname); srv->hostname = NULL;
- free(srv->hostname_dn); srv->hostname_dn = NULL;
+ ha_free(&srv->hostname);
+ ha_free(&srv->hostname_dn);
return -1;
}
return sink;
err:
- free(sink->name); sink->name = NULL;
- free(sink->desc); sink->desc = NULL;
- free(sink); sink = NULL;
+ ha_free(&sink->name);
+ ha_free(&sink->desc);
+ ha_free(&sink);
return NULL;
}
socklen = sizeof(xfer_sock->addr);
if (getsockname(fd, (struct sockaddr *)&xfer_sock->addr, &socklen) != 0) {
ha_warning("Failed to get socket address\n");
- free(xfer_sock);
- xfer_sock = NULL;
+ ha_free(&xfer_sock);
continue;
}
sctl = calloc(1, sizeof(*sctl));
if (!chunk_dup(sctl, src)) {
- free(sctl);
- sctl = NULL;
+ ha_free(&sctl);
goto end;
}
/* no error, fill ckch with new context, old context must be free */
if (ckch->sctl) {
- free(ckch->sctl->area);
- ckch->sctl->area = NULL;
+ ha_free(&ckch->sctl->area);
free(ckch->sctl);
}
ckch->sctl = sctl;
ocsp_response = calloc(1, sizeof(*ocsp_response));
if (!chunk_dup(ocsp_response, src)) {
- free(ocsp_response);
- ocsp_response = NULL;
+ ha_free(&ocsp_response);
goto end;
}
/* no error, fill ckch with new context, old context must be free */
if (ckch->ocsp_response) {
- free(ckch->ocsp_response->area);
- ckch->ocsp_response->area = NULL;
+ ha_free(&ckch->ocsp_response->area);
free(ckch->ocsp_response);
}
ckch->ocsp_response = ocsp_response;
/* once it loaded the PEM, it should remove everything else in the ckch */
if (ckch->ocsp_response) {
- free(ckch->ocsp_response->area);
- ckch->ocsp_response->area = NULL;
- free(ckch->ocsp_response);
- ckch->ocsp_response = NULL;
+ ha_free(&ckch->ocsp_response->area);
+ ha_free(&ckch->ocsp_response);
}
if (ckch->sctl) {
- free(ckch->sctl->area);
- ckch->sctl->area = NULL;
- free(ckch->sctl);
- ckch->sctl = NULL;
+ ha_free(&ckch->sctl->area);
+ ha_free(&ckch->sctl);
}
if (ckch->ocsp_issuer) {
ckch->dh = NULL;
if (ckch->sctl) {
- free(ckch->sctl->area);
- ckch->sctl->area = NULL;
- free(ckch->sctl);
- ckch->sctl = NULL;
+ ha_free(&ckch->sctl->area);
+ ha_free(&ckch->sctl);
}
if (ckch->ocsp_response) {
- free(ckch->ocsp_response->area);
- ckch->ocsp_response->area = NULL;
- free(ckch->ocsp_response);
- ckch->ocsp_response = NULL;
+ ha_free(&ckch->ocsp_response->area);
+ ha_free(&ckch->ocsp_response);
}
if (ckch->ocsp_issuer)
sctl = calloc(1, sizeof(*sctl));
if (!chunk_dup(sctl, src->sctl)) {
- free(sctl);
- sctl = NULL;
+ ha_free(&sctl);
goto error;
}
dst->sctl = sctl;
ocsp_response = calloc(1, sizeof(*ocsp_response));
if (!chunk_dup(ocsp_response, src->ocsp_response)) {
- free(ocsp_response);
- ocsp_response = NULL;
+ ha_free(&ocsp_response);
goto error;
}
dst->ocsp_response = ocsp_response;
ssl_sock_free_cert_key_and_chain_contents(store->ckch);
- free(store->ckch);
- store->ckch = NULL;
+ ha_free(&store->ckch);
list_for_each_entry_safe(inst, inst_s, &store->ckch_inst, by_ckchs) {
ckch_inst_free(inst);
ckchi->server->ssl_ctx.inst = ckchi;
/* flush the session cache of the server */
- for (i = 0; i < global.nbthread; i++) {
- free(ckchi->server->ssl_ctx.reused_sess[i].ptr);
- ckchi->server->ssl_ctx.reused_sess[i].ptr = NULL;
- }
+ for (i = 0; i < global.nbthread; i++)
+ ha_free(&ckchi->server->ssl_ctx.reused_sess[i].ptr);
+
HA_RWLOCK_WRUNLOCK(SSL_SERVER_LOCK, &ckchi->server->ssl_ctx.lock);
} else {
/* fallthrough */
case SETCERT_ST_FIN:
/* we achieved the transaction, we can set everything to NULL */
- free(ckchs_transaction.path);
- ckchs_transaction.path = NULL;
+ ha_free(&ckchs_transaction.path);
ckchs_transaction.new_ckchs = NULL;
ckchs_transaction.old_ckchs = NULL;
goto end;
appctx->ctx.ssl.old_ckchs = NULL;
- free(appctx->ctx.ssl.path);
- appctx->ctx.ssl.path = NULL;
+ ha_free(&appctx->ctx.ssl.path);
HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
return cli_dynerr(appctx, memprintf(&err, "%sCan't update %s!\n", err ? err : "", args[3]));
ckch_store_free(ckchs_transaction.new_ckchs);
ckchs_transaction.new_ckchs = NULL;
ckchs_transaction.old_ckchs = NULL;
- free(ckchs_transaction.path);
- ckchs_transaction.path = NULL;
+ ha_free(&ckchs_transaction.path);
HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
{
if (conf) {
#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
- free(conf->npn_str);
- conf->npn_str = NULL;
+ ha_free(&conf->npn_str);
#endif
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
- free(conf->alpn_str);
- conf->alpn_str = NULL;
+ ha_free(&conf->alpn_str);
#endif
- free(conf->ca_file);
- conf->ca_file = NULL;
- free(conf->ca_verify_file);
- conf->ca_verify_file = NULL;
- free(conf->crl_file);
- conf->crl_file = NULL;
- free(conf->ciphers);
- conf->ciphers = NULL;
+ ha_free(&conf->ca_file);
+ ha_free(&conf->ca_verify_file);
+ ha_free(&conf->crl_file);
+ ha_free(&conf->ciphers);
#ifdef HAVE_SSL_CTX_SET_CIPHERSUITES
- free(conf->ciphersuites);
- conf->ciphersuites = NULL;
+ ha_free(&conf->ciphersuites);
#endif
- free(conf->curves);
- conf->curves = NULL;
- free(conf->ecdhe);
- conf->ecdhe = NULL;
+ ha_free(&conf->curves);
+ ha_free(&conf->ecdhe);
}
}
crtlist_free_filters(entry->filters);
entry->filters = NULL;
ssl_sock_free_ssl_conf(entry->ssl_conf);
- free(entry->ssl_conf);
- entry->ssl_conf = NULL;
+ ha_free(&entry->ssl_conf);
return cfgerr;
}
/* it's a duplicate, we should remove and free it */
LIST_DEL(&sc0->by_ckch_inst);
SSL_CTX_free(sc0->ctx);
- free(sc0);
- sc0 = NULL;
+ ha_free(&sc0);
break;
}
}
HA_RWLOCK_RDUNLOCK(SSL_SERVER_LOCK, &s->ssl_ctx.lock);
} else {
HA_RWLOCK_RDLOCK(SSL_SERVER_LOCK, &s->ssl_ctx.lock);
- free(s->ssl_ctx.reused_sess[tid].ptr);
- s->ssl_ctx.reused_sess[tid].ptr = NULL;
+ ha_free(&s->ssl_ctx.reused_sess[tid].ptr);
HA_RWLOCK_RDUNLOCK(SSL_SERVER_LOCK, &s->ssl_ctx.lock);
}
{
if (bind_conf->ca_sign_ckch) {
ssl_sock_free_cert_key_and_chain_contents(bind_conf->ca_sign_ckch);
- free(bind_conf->ca_sign_ckch);
- bind_conf->ca_sign_ckch = NULL;
+ ha_free(&bind_conf->ca_sign_ckch);
}
}
SSL_SESSION *sess = d2i_SSL_SESSION(NULL, &ptr, __objt_server(conn->target)->ssl_ctx.reused_sess[tid].size);
if (sess && !SSL_set_session(ctx->ssl, sess)) {
SSL_SESSION_free(sess);
- free(__objt_server(conn->target)->ssl_ctx.reused_sess[tid].ptr);
- __objt_server(conn->target)->ssl_ctx.reused_sess[tid].ptr = NULL;
+ ha_free(&__objt_server(conn->target)->ssl_ctx.reused_sess[tid].ptr);
} else if (sess) {
SSL_SESSION_free(sess);
}
* another thread */
HA_RWLOCK_RDLOCK(SSL_SERVER_LOCK, &s->ssl_ctx.lock);
- if (s->ssl_ctx.reused_sess[tid].ptr) {
- free(s->ssl_ctx.reused_sess[tid].ptr);
- s->ssl_ctx.reused_sess[tid].ptr = NULL;
- }
+ if (s->ssl_ctx.reused_sess[tid].ptr)
+ ha_free(&s->ssl_ctx.reused_sess[tid].ptr);
HA_RWLOCK_RDUNLOCK(SSL_SERVER_LOCK, &s->ssl_ctx.lock);
}
for (i = 0; i < STATS_DOMAIN_COUNT; ++i) {
const int domain = domains[i];
- free(stat_l[domain]);
- stat_l[domain] = NULL;
+ ha_free(&stat_l[domain]);
}
}
__decl_thread(struct resolvers *resolvers = s->resolv_ctx.parent->arg.resolv.resolvers);
HA_SPIN_LOCK(DNS_LOCK, &resolvers->lock);
- free(s->resolv_ctx.hostname_dn); s->resolv_ctx.hostname_dn = NULL;
+ ha_free(&s->resolv_ctx.hostname_dn);
s->resolv_ctx.hostname_dn_len = 0;
resolv_unlink_resolution(s->resolv_ctx.requester);
HA_SPIN_UNLOCK(DNS_LOCK, &resolvers->lock);
goto out;
}
- free(px->check_command);
- free(px->check_path);
- px->check_command = px->check_path = NULL;
+ ha_free(&px->check_command);
+ ha_free(&px->check_path);
if (!px->tcpcheck_rules.list) {
ha_alert("config : proxy '%s' : tcp-check configured but no ruleset defined.\n", px->id);
* comment is assigned to the following rule(s).
*/
list_for_each_entry_safe(chk, back, px->tcpcheck_rules.list, list) {
- if (chk->action != prev_action && prev_action != TCPCHK_ACT_COMMENT) {
- free(comment);
- comment = NULL;
- }
+ if (chk->action != prev_action && prev_action != TCPCHK_ACT_COMMENT)
+ ha_free(&comment);
prev_action = chk->action;
switch (chk->action) {
chk->comment = strdup(comment);
/* fall through */
case TCPCHK_ACT_ACTION_KW:
- free(comment);
- comment = NULL;
+ ha_free(&comment);
break;
case TCPCHK_ACT_SEND:
case TCPCHK_ACT_EXPECT:
break;
}
}
- free(comment);
- comment = NULL;
+ ha_free(&comment);
out:
return ret;
if (errmsg) {
ha_warning("parsing [%s:%d]: '%s %s' : %s\n", file, line, args[0], args[1], errmsg);
err_code |= ERR_WARN;
- free(errmsg);
- errmsg = NULL;
+ ha_free(&errmsg);
}
no_request:
bad_input:
memprintf(err, "an hex digit is expected (found '%c')", p[i-1]);
- if (alloc) {
- free(*binstr);
- *binstr = NULL;
- }
+ if (alloc)
+ ha_free(binstr);
return 0;
}
if (needed < 0) {
/* an error was encountered */
- free(ret);
- ret = NULL;
+ ha_free(&ret);
}
if (out) {
send_log(NULL, LOG_NOTICE, "WURFL: Unloading module v.%s\n", HA_WURFL_MODULE_VERSION);
wurfl_destroy(global_wurfl.handle);
global_wurfl.handle = NULL;
- free(global_wurfl.data_file);
- global_wurfl.data_file = NULL;
- free(global_wurfl.cache_size);
- global_wurfl.cache_size = NULL;
+ ha_free(&global_wurfl.data_file);
+ ha_free(&global_wurfl.cache_size);
list_for_each_entry_safe(wi, wi2, &global_wurfl.information_list, list) {
LIST_DEL(&wi->list);
qel->tx.crypto.bufs[i] = NULL;
}
}
- free(qel->tx.crypto.bufs);
- qel->tx.crypto.bufs = NULL;
+ ha_free(&qel->tx.crypto.bufs);
}
/* Initialize QUIC TLS encryption level with <level<> as level for <qc> QUIC
return 1;
err:
- free(qel->tx.crypto.bufs);
- qel->tx.crypto.bufs = NULL;
+ ha_free(&qel->tx.crypto.bufs);
return 0;
}
p++;
continue;
}
- free((*p)->area);
- (*p)->area = NULL;
- free(*p);
- *p = NULL;
+ ha_free(&(*p)->area);
+ ha_free(p);
p++;
}
free(bufs);