From patchwork Sat Feb 5 08:46:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1588713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JrQyD2fb6z9s0B for ; Sat, 5 Feb 2022 19:47:16 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0DCFE61029; Sat, 5 Feb 2022 08:47:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nXOxEG3PiZSs; Sat, 5 Feb 2022 08:47:07 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id D3CCB60A88; Sat, 5 Feb 2022 08:47:06 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D9984C0070; Sat, 5 Feb 2022 08:47:05 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3DBFEC0070 for ; Sat, 5 Feb 2022 08:47:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 1F5C3410A0 for ; Sat, 5 Feb 2022 08:47:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZpCGn2QlKE95 for ; Sat, 5 Feb 2022 08:47:04 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp4.osuosl.org (Postfix) with ESMTPS id 21BEF40993 for ; Sat, 5 Feb 2022 08:47:03 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 466FDE0006; Sat, 5 Feb 2022 08:46:58 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sat, 5 Feb 2022 00:46:26 -0800 Message-Id: <20220205084635.3725713-2-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220205084635.3725713-1-hzhou@ovn.org> References: <20220205084635.3725713-1-hzhou@ovn.org> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH RFC ovn 01/10] expr.c: Use expr_destroy and expr_clone instead of free and xmemdup. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Use the functions for safer memory operation. Signed-off-by: Han Zhou --- lib/expr.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/expr.c b/lib/expr.c index e3f6bb892..5fc6c1ce9 100644 --- a/lib/expr.c +++ b/lib/expr.c @@ -186,7 +186,7 @@ expr_combine(enum expr_type type, struct expr *a, struct expr *b) } else if (a->type == type) { if (b->type == type) { ovs_list_splice(&a->andor, b->andor.next, &b->andor); - free(b); + expr_destroy(b); } else { ovs_list_push_back(&a->andor, &b->node); } @@ -210,7 +210,7 @@ expr_insert_andor(struct expr *andor, struct expr *before, struct expr *new) /* Conjunction junction, what's your function? */ } ovs_list_splice(&before->node, new->andor.next, &new->andor); - free(new); + expr_destroy(new); } else { ovs_list_insert(&before->node, &new->node); } @@ -276,11 +276,11 @@ expr_fix_andor(struct expr *expr, bool short_circuit) if (ovs_list_is_short(&expr->andor)) { if (ovs_list_is_empty(&expr->andor)) { - free(expr); + expr_destroy(expr); return expr_create_boolean(!short_circuit); } else { - sub = expr_from_node(ovs_list_front(&expr->andor)); - free(expr); + sub = expr_from_node(ovs_list_pop_front(&expr->andor)); + expr_destroy(expr); return sub; } } else { @@ -2096,7 +2096,7 @@ expr_simplify_relational(struct expr *expr) * and similarly for "tcp.dst <= 1234". */ struct expr *new = NULL; if (eq) { - new = xmemdup(expr, sizeof *expr); + new = expr_clone(expr); new->cmp.relop = EXPR_R_EQ; } @@ -2105,7 +2105,7 @@ expr_simplify_relational(struct expr *expr) z = bitwise_scan(value, sizeof *value, lt, z + 1, end)) { struct expr *e; - e = xmemdup(expr, sizeof *expr); + e = expr_clone(expr); e->cmp.relop = EXPR_R_EQ; bitwise_toggle_bit(&e->cmp.value, sizeof e->cmp.value, z); bitwise_zero(&e->cmp.value, sizeof e->cmp.value, start, z - start); @@ -2324,7 +2324,7 @@ crush_and_string(struct expr *expr, const struct expr_symbol *symbol) expr_destroy(expr); return new; } - free(new); + expr_destroy(new); break; case EXPR_T_CONDITION: OVS_NOT_REACHED(); @@ -2463,14 +2463,14 @@ crush_and_numeric(struct expr *expr, const struct expr_symbol *symbol) expr_destroy(sub); } } - free(disjuncts); - free(expr); + expr_destroy(disjuncts); + expr_destroy(expr); if (ovs_list_is_empty(&or->andor)) { - free(or); + expr_destroy(or); return expr_create_boolean(false); } else if (ovs_list_is_short(&or->andor)) { struct expr *cmp = expr_from_node(ovs_list_pop_front(&or->andor)); - free(or); + expr_destroy(or); return cmp; } else { return crush_cmps(or, symbol); @@ -2517,15 +2517,15 @@ crush_and_numeric(struct expr *expr, const struct expr_symbol *symbol) } expr_destroy(as); expr_destroy(bs); - free(new); + expr_destroy(new); if (ovs_list_is_empty(&or->andor)) { expr_destroy(expr); - free(or); + expr_destroy(or); return expr_create_boolean(false); } else if (ovs_list_is_short(&or->andor)) { struct expr *cmp = expr_from_node(ovs_list_pop_front(&or->andor)); - free(or); + expr_destroy(or); if (ovs_list_is_empty(&expr->andor)) { expr_destroy(expr); return crush_cmps(cmp, symbol); @@ -2675,7 +2675,7 @@ expr_sort(struct expr *expr) qsort(subs, n, sizeof *subs, compare_expr_sort); ovs_list_init(&expr->andor); - free(expr); + expr_destroy(expr); expr = NULL; for (i = 0; i < n; ) { @@ -2708,7 +2708,7 @@ expr_sort(struct expr *expr) expr = crushed; break; } else { - free(crushed); + expr_destroy(crushed); } } else { expr = expr_combine(EXPR_T_AND, expr, crushed); @@ -2754,8 +2754,8 @@ expr_normalize_and(struct expr *expr) } } if (ovs_list_is_short(&expr->andor)) { - struct expr *sub = expr_from_node(ovs_list_front(&expr->andor)); - free(expr); + struct expr *sub = expr_from_node(ovs_list_pop_front(&expr->andor)); + expr_destroy(expr); return sub; } @@ -2813,7 +2813,7 @@ expr_normalize_or(struct expr *expr) expr_destroy(expr); return new; } - free(new); + expr_destroy(new); } else { expr_insert_andor(expr, next, new); } @@ -2823,12 +2823,12 @@ expr_normalize_or(struct expr *expr) } } if (ovs_list_is_empty(&expr->andor)) { - free(expr); + expr_destroy(expr); return expr_create_boolean(false); } if (ovs_list_is_short(&expr->andor)) { struct expr *e = expr_from_node(ovs_list_pop_front(&expr->andor)); - free(expr); + expr_destroy(expr); return e; }