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/wurfl.c b/src/wurfl.c
index 34075d6..02e1dd4 100644
--- a/src/wurfl.c
+++ b/src/wurfl.c
@@ -406,10 +406,8 @@
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);