]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: pattern: release the reference on failure to load from file
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Apr 2026 14:27:36 +0000 (16:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Apr 2026 15:39:26 +0000 (17:39 +0200)
In pattern_read_from_file(), in case of failure to load from the file,
the newly allocated reference remains attached to the list and is never
freed. Let's just do it.

This can be backported to all versions since it arrived in 1.5 with
commit 1e00d3853b ("MAJOR: pattern/map: Extends the map edition system
in the patterns").

src/pattern.c

index 41f834582a9c9755bc9183aeac476364ab9687bb..17322e3a3ce24e2f0e7db1eb68000d510b36082c 100644 (file)
@@ -2590,12 +2590,18 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
                if (ref->flags & PAT_REF_FILE) {
                        if (load_smp) {
                                ref->flags |= PAT_REF_SMP;
-                               if (!pat_ref_read_from_file_smp(ref, err))
+                               if (!pat_ref_read_from_file_smp(ref, err)) {
+                                       LIST_DELETE(&ref->list);
+                                       pat_ref_free(ref);
                                        return 0;
+                               }
                        }
                        else {
-                               if (!pat_ref_read_from_file(ref, err))
+                               if (!pat_ref_read_from_file(ref, err)) {
+                                       LIST_DELETE(&ref->list);
+                                       pat_ref_free(ref);
                                        return 0;
+                               }
                        }
                }
                else if ((ref->flags & PAT_REF_ID) && load_smp)