From patchwork Wed Jan 3 12:32:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ales Musil X-Patchwork-Id: 1881936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U4s+NQM0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4pyZ22LNz1yQ5 for ; Wed, 3 Jan 2024 23:32:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B9290417D1; Wed, 3 Jan 2024 12:32:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B9290417D1 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U4s+NQM0 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 TKrnCmuofBLk; Wed, 3 Jan 2024 12:32:34 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id ACED541751; Wed, 3 Jan 2024 12:32:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org ACED541751 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7278AC0077; Wed, 3 Jan 2024 12:32:33 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 36384C0037 for ; Wed, 3 Jan 2024 12:32:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 0849440A5B for ; Wed, 3 Jan 2024 12:32:32 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0849440A5B Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U4s+NQM0 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8fnJHk27tUAL for ; Wed, 3 Jan 2024 12:32:30 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 9EAFE40154 for ; Wed, 3 Jan 2024 12:32:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 9EAFE40154 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704285147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L5C+f9CKIf8NaST9r40Jik+6Mw3j/1pv7oMHwPQNO7E=; b=U4s+NQM0oQpA9ujeuh0hhNx0bRKEV/Y2Hhtc2F8o+8xbeIjQ3/5AC20Kfrsr9e45ZzKZ1q w1CTEasHoPFJWRoxhXAY2w6ujBvbT4+LydvLRIPPTtzBAbYXhKJWKS1TpYynHWtxDy6Kxe xZ+7peunOrSugrHcNUtGsSU0sI8wlc4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-474-I6JhWcLtNZelM5Stgl8wEQ-1; Wed, 03 Jan 2024 07:32:25 -0500 X-MC-Unique: I6JhWcLtNZelM5Stgl8wEQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 727E2835382 for ; Wed, 3 Jan 2024 12:32:25 +0000 (UTC) Received: from amusil.redhat.com (unknown [10.45.224.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87B4C492BE6; Wed, 3 Jan 2024 12:32:24 +0000 (UTC) From: Ales Musil To: dev@openvswitch.org Date: Wed, 3 Jan 2024 13:32:23 +0100 Message-ID: <20240103123223.435262-1-amusil@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com Subject: [ovs-dev] [PATCH ovn] treewide: Fix small memory leaks reported by static analysis 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" Fix a couple of small memory leaks that were reported by coverity static analysis on ovn rpm package. Signed-off-by: Ales Musil --- controller-vtep/ovn-controller-vtep.c | 2 ++ controller/lflow.c | 1 + controller/ovn-controller.c | 1 + controller/pinctrl.c | 20 +++++++++++++------- utilities/ovn-nbctl.c | 1 + utilities/ovn-trace.c | 1 + 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/controller-vtep/ovn-controller-vtep.c b/controller-vtep/ovn-controller-vtep.c index 23b368179..4472e5285 100644 --- a/controller-vtep/ovn-controller-vtep.c +++ b/controller-vtep/ovn-controller-vtep.c @@ -306,10 +306,12 @@ parse_options(int argc, char *argv[]) switch (c) { case 'd': + free(ovnsb_remote); ovnsb_remote = xstrdup(optarg); break; case 'D': + free(vtep_remote); vtep_remote = xstrdup(optarg); break; diff --git a/controller/lflow.c b/controller/lflow.c index 85a4943dc..b0cf4253c 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -1017,6 +1017,7 @@ convert_match_to_expr(const struct sbrec_logical_flow *lflow, static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); VLOG_WARN_RL(&rl, "error parsing match \"%s\": %s", lflow->match, error); + expr_destroy(e); free(error); return NULL; } diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 760b7788b..7cd146f48 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -6186,6 +6186,7 @@ parse_options(int argc, char *argv[]) break; case 'n': + free(cli_system_id); cli_system_id = xstrdup(optarg); break; diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 5a35d56f6..169c02c32 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -6407,23 +6407,26 @@ pinctrl_handle_empty_lb_backends_opts(struct ofpbuf *userdata) while (userdata->size) { userdata_opt = ofpbuf_try_pull(userdata, sizeof opt_hdr); if (!userdata_opt) { - return false; + goto err; } memcpy(&opt_hdr, userdata_opt, sizeof opt_hdr); size_t size = ntohs(opt_hdr.size); char *userdata_opt_data = ofpbuf_try_pull(userdata, size); if (!userdata_opt_data) { - return false; + goto err; } switch (ntohs(opt_hdr.opt_code)) { case EMPTY_LB_VIP: + free(vip); vip = xmemdup0(userdata_opt_data, size); break; case EMPTY_LB_PROTOCOL: + free(protocol); protocol = xmemdup0(userdata_opt_data, size); break; case EMPTY_LB_LOAD_BALANCER: + free(load_balancer); load_balancer = xmemdup0(userdata_opt_data, size); break; default: @@ -6434,10 +6437,7 @@ pinctrl_handle_empty_lb_backends_opts(struct ofpbuf *userdata) if (!vip || !protocol || !load_balancer) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); VLOG_WARN_RL(&rl, "missing lb parameters in userdata"); - free(vip); - free(protocol); - free(load_balancer); - return false; + goto err; } struct empty_lb_backends_event *event; @@ -6447,7 +6447,7 @@ pinctrl_handle_empty_lb_backends_opts(struct ofpbuf *userdata) if (!event) { if (hmap_count(&event_table[OVN_EVENT_EMPTY_LB_BACKENDS]) >= 1000) { COVERAGE_INC(pinctrl_drop_controller_event); - return false; + goto err; } event = xzalloc(sizeof *event); @@ -6464,6 +6464,12 @@ pinctrl_handle_empty_lb_backends_opts(struct ofpbuf *userdata) free(load_balancer); } return true; + +err: + free(vip); + free(protocol); + free(load_balancer); + return false; } static void diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c index 9522078c1..526369b68 100644 --- a/utilities/ovn-nbctl.c +++ b/utilities/ovn-nbctl.c @@ -4694,6 +4694,7 @@ static void nexthop = normalize_prefix_str(ctx->argv[3]); if (!nexthop) { ctl_error(ctx, "bad nexthop argument: %s", ctx->argv[3]); + free(prefix); return; } } diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c index 0b86eae7b..13ae464ad 100644 --- a/utilities/ovn-trace.c +++ b/utilities/ovn-trace.c @@ -983,6 +983,7 @@ parse_lflow_for_datapath(const struct sbrec_logical_flow *sblf, if (error) { VLOG_WARN("%s: parsing expression failed (%s)", sblf->match, error); + expr_destroy(match); free(error); return; }