From patchwork Fri Sep 22 13:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Simonart X-Patchwork-Id: 1838253 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=BL5oyO0K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 4RsXs74SMXz1yh6 for ; Fri, 22 Sep 2023 23:18:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8FCDB83C88; Fri, 22 Sep 2023 13:18:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 8FCDB83C88 Authentication-Results: smtp1.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=BL5oyO0K X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uJRIbWMi0z1e; Fri, 22 Sep 2023 13:18:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id CA74D82F4A; Fri, 22 Sep 2023 13:18:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org CA74D82F4A Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A417AC0071; Fri, 22 Sep 2023 13:18:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 153E2C0032 for ; Fri, 22 Sep 2023 13:18:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E45B160B0B for ; Fri, 22 Sep 2023 13:18:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org E45B160B0B Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BL5oyO0K 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 BMDDAGaA1bTl for ; Fri, 22 Sep 2023 13:18:29 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 3826360804 for ; Fri, 22 Sep 2023 13:18:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3826360804 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695388708; 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=C7QN4it4p8UcLR6ZBhK0aNZpHazWyPCFMPawIo/lI+U=; b=BL5oyO0KyqO+nHVmm3Lo+EKT+XOYfy8tjBxQp4cWrPcHf+Mp6UT6t+r0/PWa9pGRBlg+yg f2RlbjQzpdTBVX5OYNE56hzTGsKa1WuvluQ4Dpitaz3u+FohY7X/JpiC4CvYAMRP4KuqDQ CzzvOWM1IYHbTL4x+AHg6ykXuwV6Oew= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-361-2Qz_mnxWMrymaO4YwKfG3Q-1; Fri, 22 Sep 2023 09:18:24 -0400 X-MC-Unique: 2Qz_mnxWMrymaO4YwKfG3Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65BE41C25A68; Fri, 22 Sep 2023 13:18:24 +0000 (UTC) Received: from wsfd-netdev90.ntdv.lab.eng.bos.redhat.com (wsfd-netdev90.ntdv.lab.eng.bos.redhat.com [10.19.188.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44C37492C37; Fri, 22 Sep 2023 13:18:24 +0000 (UTC) From: Xavier Simonart To: xsimonar@redhat.com, dev@openvswitch.org Date: Fri, 22 Sep 2023 15:18:23 +0200 Message-Id: <20230922131823.2361211-1-xsimonar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH v2] ovsdb: Fix potential leak when making diff of conditions. 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" OVN unit tests highlight this: ERROR: LeakSanitizer: detected memory leaks Direct leak of 1344 byte(s) in 1 object(s) allocated from: 0 0x4db0b7 in calloc (ovsdb/ovsdb-server+0x4db0b7) 1 0x5c2162 in xcalloc__ lib/util.c:124:31 2 0x5c221c in xcalloc lib/util.c:161:12 3 0x54afbc in ovsdb_condition_diff ovsdb/condition.c:527:21 4 0x529da6 in ovsdb_monitor_table_condition_update ovsdb/monitor.c:824:5 5 0x524fa4 in ovsdb_jsonrpc_parse_monitor_cond_change_request ovsdb/jsonrpc-server.c:1557:13 6 0x5235c3 in ovsdb_jsonrpc_monitor_cond_change ovsdb/jsonrpc-server.c:1624:25 7 0x5217f2 in ovsdb_jsonrpc_session_got_request ovsdb/jsonrpc-server.c:1034:17 8 0x520ee6 in ovsdb_jsonrpc_session_run ovsdb/jsonrpc-server.c:572:17 9 0x51ffbe in ovsdb_jsonrpc_session_run_all ovsdb/jsonrpc-server.c:602:21 10 0x51fbcf in ovsdb_jsonrpc_server_run ovsdb/jsonrpc-server.c:417:9 11 0x517550 in main_loop ovsdb/ovsdb-server.c:224:9 12 0x512e80 in main ovsdb/ovsdb-server.c:507:5 13 0x7f9ecf675b74 in __libc_start_main (/lib64/libc.so.6+0x27b74) Fixes: ef1da757f016 ("ovsdb: condition: Process condition changes incrementally.") Signed-off-by: Xavier Simonart --- v2: addressed comments from Ilya. --- ovsdb/condition.c | 11 ++++++++--- ovsdb/monitor.c | 1 + tests/ovsdb-monitor.at | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ovsdb/condition.c b/ovsdb/condition.c index 5a3eb4e8a..4911fbf59 100644 --- a/ovsdb/condition.c +++ b/ovsdb/condition.c @@ -550,9 +550,14 @@ ovsdb_condition_diff(struct ovsdb_condition *diff, &b->clauses[j]); } - diff->optimized = a->optimized && b->optimized; - if (diff->optimized) { - ovsdb_condition_optimize(diff); + if (diff->n_clauses) { + diff->optimized = a->optimized && b->optimized; + if (diff->optimized) { + ovsdb_condition_optimize(diff); + } + } else { + free(diff->clauses); + diff->clauses = NULL; } } diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c index 9829cd39c..9855f45d3 100644 --- a/ovsdb/monitor.c +++ b/ovsdb/monitor.c @@ -821,6 +821,7 @@ ovsdb_monitor_table_condition_update( ovsdb_condition_destroy(&mtc->new_condition); ovsdb_condition_clone(&mtc->new_condition, &cond); ovsdb_condition_destroy(&cond); + ovsdb_condition_destroy(&mtc->diff_condition); ovsdb_condition_diff(&mtc->diff_condition, &mtc->old_condition, &mtc->new_condition); ovsdb_monitor_condition_add_columns(dbmon, diff --git a/tests/ovsdb-monitor.at b/tests/ovsdb-monitor.at index 12cd2bc31..3e1df18a1 100644 --- a/tests/ovsdb-monitor.at +++ b/tests/ovsdb-monitor.at @@ -586,6 +586,7 @@ row,action,name,number,_version [[]], [], [[[[["name","==","one"],["name","==","two"]]]], + [[[["name","==","two"],["name","==","one"]]]], [[[["name","==","one"]]]], [[[false]]], [[[true]]]])