]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: pattern: use malloc() to initialize new pat_ref struct
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 7 Nov 2024 09:05:30 +0000 (10:05 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 7 Nov 2024 10:36:08 +0000 (11:36 +0100)
As mentioned in the previous commit, in _pat_ref_new(), it was not
strictly needed to explicitly assign all struct members to 0 since
the struct was allocated with calloc() which does the zeroing for us.

However, it was verified that we already initialize all fields explictly,
thus there is no reason to keep using calloc() instead of malloc(). In
fact using malloc() is less expensive, so let's use that instead now.

src/pattern.c

index bc3d8537eca0a801667e266b89efa68122609a8f..7996bb8dacc7535c328599cb0501c2239815ebcf 100644 (file)
@@ -1801,13 +1801,11 @@ static struct pat_ref *_pat_ref_new(const char *display, unsigned int flags)
 {
        struct pat_ref *ref;
 
-       ref = calloc(1, sizeof(*ref));
+       ref = malloc(sizeof(*ref));
        if (!ref)
                return NULL;
 
-       /* For now is assumed <ref> was allocated with calloc() thus we don't
-        * have to explicitly set all members to 0.
-        */
+       /* don't forget to explicitly initialize all pat_ref struct members */
 
        if (display) {
                ref->display = strdup(display);