]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: tree-wide: drop a few useless null-checks before free()
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Feb 2026 09:40:48 +0000 (10:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Feb 2026 07:24:03 +0000 (08:24 +0100)
We only support platforms where free(NULL) is a NOP so that
null checks are useless before free(). Let's drop them to keep
the code clean. There were a few in cfgparse-global, flt_trace,
ssl_sock and stats.

src/cfgparse-global.c
src/flt_trace.c
src/ssl_sock.c
src/stats.c

index aafca44ea6e4f77f18512af7297cedc95b5e61ef..81616c218d021da36ae2523803610a4aa79070f5 100644 (file)
@@ -456,9 +456,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                for (i = 1; *args[i]; i++)
                        len += strlen(args[i]) + 1;
 
-               if (global.desc)
-                       free(global.desc);
-
+               free(global.desc);
                global.desc = d = calloc(1, len);
 
                d += snprintf(d, global.desc + len - d, "%s", args[1]);
@@ -487,9 +485,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               if (global.node)
-                       free(global.node);
-
+               free(global.node);
                global.node = strdup(args[1]);
        }
        else if (strcmp(args[0], "unix-bind") == 0) {
index ba50d6d4eb2be2065a25aa917a76b1d2d6b25bd7..77577ecf5806513e681a790fb62ddb70d9dada8d 100644 (file)
@@ -688,8 +688,7 @@ parse_trace_flt(char **args, int *cur_arg, struct proxy *px,
        return 0;
 
  error:
-       if (conf->name)
-               free(conf->name);
+       free(conf->name);
        free(conf);
        return -1;
 }
index 420894a08425b96f97eb9f18480976824dbf89d8..eb56179851386c4eb9ec7a880f64c5125f703e50 100644 (file)
@@ -1582,9 +1582,7 @@ out:
        if (ocsp)
                ssl_sock_free_ocsp(ocsp);
 
-       if (warn)
-               free(warn);
-
+       free(warn);
        free(err);
 
        return ret;
index f710a4aab96f9e8f30a65900ebfc17375206a1ad..ad2a11d83452aca1d7d84ccca0503fbc4c85f7ba 100644 (file)
@@ -1315,8 +1315,7 @@ static void deinit_stats(void)
        for (i = 0; i < STATS_DOMAIN_COUNT; ++i) {
                const int domain = domains[i];
 
-               if (stat_cols[domain])
-                       free(stat_cols[domain]);
+               free(stat_cols[domain]);
        }
 }
 
@@ -1324,8 +1323,7 @@ REGISTER_POST_DEINIT(deinit_stats);
 
 static void free_trash_counters(void)
 {
-       if (trash_counters)
-               free(trash_counters);
+       free(trash_counters);
 }
 
 REGISTER_PER_THREAD_FREE(free_trash_counters);