]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-table: free newly allocated stkess if it couldn't be inserted
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Oct 2022 13:13:46 +0000 (15:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Oct 2022 12:19:05 +0000 (14:19 +0200)
In __stktable_get_entry() now we're planning for the possibility that the
call to __stktable_store() doesn't add the newly allocated entry and instead
finds a previously inserted one. At the moment this doesn't exist because
the lookup + insert passes are made under the same lock. But it will soon
change.

src/stick_table.c

index 6f5e6c8999850efea2dd718069081ea52e998cf0..95913b12560cae5dbc006cca1c8e5eb87cf96f50 100644 (file)
@@ -523,7 +523,7 @@ struct stksess *__stktable_store(struct stktable *t, struct stksess *ts)
  */
 struct stksess *__stktable_get_entry(struct stktable *table, struct stktable_key *key)
 {
-       struct stksess *ts;
+       struct stksess *ts, *ts2;
 
        if (!key)
                return NULL;
@@ -534,7 +534,14 @@ struct stksess *__stktable_get_entry(struct stktable *table, struct stktable_key
                ts = __stksess_new(table, key);
                if (!ts)
                        return NULL;
-               __stktable_store(table, ts);
+               ts2 = __stktable_store(table, ts);
+               if (unlikely(ts2 != ts)) {
+                       /* another entry was added in the mean time, let's
+                        * switch to it.
+                        */
+                       __stksess_free(table, ts);
+                       ts = ts2;
+               }
        }
        return ts;
 }