CLEANUP: tree-wide: replace free(x);x=NULL with ha_free(&x)
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.
diff --git a/src/cfgparse-ssl.c b/src/cfgparse-ssl.c
index faacc0e..6af1328 100644
--- a/src/cfgparse-ssl.c
+++ b/src/cfgparse-ssl.c
@@ -106,8 +106,7 @@
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)
@@ -1467,8 +1466,7 @@
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;
}
@@ -1497,8 +1495,7 @@
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;