From: Willy Tarreau Date: Wed, 28 Oct 2020 09:58:05 +0000 (+0100) Subject: MINOR: pattern: make pat_ref_add() rely on pat_ref_append() X-Git-Tag: v2.3-dev9~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a1740767c692593402a452b974a5a0d777f1390;p=thirdparty%2Fhaproxy.git MINOR: pattern: make pat_ref_add() rely on pat_ref_append() Let's remove unneeded code duplication, both are exactly the same. --- diff --git a/src/pattern.c b/src/pattern.c index cdacefba0b..0890fb25f4 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -1982,9 +1982,9 @@ int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, return 1; } -/* This function adds entry to . It can failed with memory error. The new +/* This function adds entry to . It can fail on memory error. The new * entry is added at all the pattern_expr registered in this reference. The - * function stop on the first error encountered. It returns 0 and err is + * function stops on the first error encountered. It returns 0 and is * filled. If an error is encountered, the complete add operation is cancelled. * If the insertion is a success the function returns 1. */ @@ -1995,36 +1995,12 @@ int pat_ref_add(struct pat_ref *ref, struct pat_ref_elt *elt; struct pattern_expr *expr; - elt = malloc(sizeof(*elt)); + elt = pat_ref_append(ref, pattern, sample, -1); if (!elt) { memprintf(err, "out of memory error"); return 0; } - elt->line = -1; - - elt->pattern = strdup(pattern); - if (!elt->pattern) { - free(elt); - memprintf(err, "out of memory error"); - return 0; - } - - if (sample) { - elt->sample = strdup(sample); - if (!elt->sample) { - free(elt->pattern); - free(elt); - memprintf(err, "out of memory error"); - return 0; - } - } - else - elt->sample = NULL; - - LIST_INIT(&elt->back_refs); - LIST_ADDQ(&ref->head, &elt->list); - list_for_each_entry(expr, &ref->pat, list) { if (!pat_ref_push(elt, expr, 0, err)) { /* If the insertion fails, try to delete all the added entries. */ @@ -2032,7 +2008,6 @@ int pat_ref_add(struct pat_ref *ref, return 0; } } - return 1; }