]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Dynamically alloc the message list per event of an agent
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Jul 2024 08:57:29 +0000 (10:57 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Jul 2024 13:27:04 +0000 (15:27 +0200)
The inline array used to store, the configured messages per event in the
SPOE agent structure, is replaced by a dynamic array, allocated during the
configuration parsing. The main purpose of this change is to be able to move
all stuff regarding the SPOE filter and applet in the C file.

The related issue is #2502.

include/haproxy/spoe-t.h
src/flt_spoe.c

index 40ba373d651d8bd46a5f5f87be13f4d784ecc5c1..9b10c920fde5c0a42c38dfb12112ca511998052b 100644 (file)
@@ -296,7 +296,7 @@ struct spoe_agent {
        unsigned int          flags;          /* SPOE_FL_* */
        unsigned int          max_frame_size; /* Maximum frame size for this agent, before any negotiation */
 
-       struct list events[SPOE_EV_EVENTS];   /* List of SPOE messages that will be sent
+       struct list *events;                  /* List of SPOE messages that will be sent
                                               * for each supported events */
 
        struct list groups;                   /* List of available SPOE groups */
index df85cabd574defa6aa6f1ac20cb8e309396d01f2..1615305d35685c3986c663bd8397137b189cf60e 100644 (file)
@@ -151,6 +151,7 @@ spoe_release_agent(struct spoe_agent *agent)
                LIST_DELETE(&grp->list);
                spoe_release_group(grp);
        }
+       free(agent->events);
        free(agent->engine_id);
        free(agent);
 }
@@ -2451,6 +2452,12 @@ cfg_parse_spoe_agent(const char *file, int linenum, char **args, int kwm)
                curagent->flags          = SPOE_FL_PIPELINING;
                curagent->max_frame_size = SPOP_MAX_FRAME_SIZE;
 
+               if ((curagent->events = calloc(SPOE_EV_EVENTS, sizeof(*curagent->events))) == NULL) {
+                       ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
+                       err_code |= ERR_ALERT | ERR_ABORT;
+                       goto out;
+               }
+
                for (i = 0; i < SPOE_EV_EVENTS; ++i)
                        LIST_INIT(&curagent->events[i]);
                LIST_INIT(&curagent->groups);