From patchwork Mon Sep 2 09:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Simonart X-Patchwork-Id: 1979579 X-Patchwork-Delegate: echaudro@redhat.com 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=HlcTSX/0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 4Wy3Mw6vG7z1ygC for ; Mon, 2 Sep 2024 19:28:28 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 32308405D3; Mon, 2 Sep 2024 09:28:27 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id l87QwTvO6aLo; Mon, 2 Sep 2024 09:28:25 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org AD83240128 Authentication-Results: smtp2.osuosl.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=HlcTSX/0 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id AD83240128; Mon, 2 Sep 2024 09:28:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 72A7AC0012; Mon, 2 Sep 2024 09:28:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id B993DC0011 for ; Mon, 2 Sep 2024 09:28:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id A0FAE605E4 for ; Mon, 2 Sep 2024 09:28:24 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6CFeEK2l4Azx for ; Mon, 2 Sep 2024 09:28:23 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=xsimonar@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 5E919605BB Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5E919605BB 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=HlcTSX/0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5E919605BB for ; Mon, 2 Sep 2024 09:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725269302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9w0QOEWWnjhfh9zXiEt5yr0UVkBG15B4DlXGyaTpX8M=; b=HlcTSX/0keSTvPx5MVaeml4ZXVi3+2nxbDTDKpWc84zfohlbQUQTN932ffb7zRSS5AJA95 jYEqqdP3OV9UD/7vYhCLqsoNHjbbDeeWUTGHEfGKOav9hXOsbFUrx8FllJpJNXFsL0ahnO tKBBy6u2yMNr/yj/LrQahRXzOPNURGM= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-POKvT0vSMiG8_s4Omd3pSQ-1; Mon, 02 Sep 2024 05:28:20 -0400 X-MC-Unique: POKvT0vSMiG8_s4Omd3pSQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 060141955F42 for ; Mon, 2 Sep 2024 09:28:20 +0000 (UTC) Received: from wsfd-netdev90.ntdv.lab.eng.bos.redhat.com (wsfd-netdev90.anl.eng.rdu2.dc.redhat.com [10.6.38.135]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5A22B300019A; Mon, 2 Sep 2024 09:28:19 +0000 (UTC) From: Xavier Simonart To: xsimonar@redhat.com, dev@openvswitch.org Date: Mon, 2 Sep 2024 11:28:18 +0200 Message-Id: <20240902092818.1846942-1-xsimonar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH] ovsdb-idl: Fix IDL memory leak. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" In the following case, we could see multiple leaks detected for memory allocated by ovsdb_idl_txn_add_map_op: insert a row in a table, set a key and delete the row (all within the same transaction). For instance: Direct leak of 24 byte(s) in 1 object(s) allocated from: 0 0x4e60a7 in calloc (./tests/test-ovsdb+0x4e60a7) 1 0x5f9b32 in xcalloc__ ./lib/util.c:125:31 2 0x5f9b60 in xzalloc__ ./lib/util.c:135:12 3 0x5f9c25 in xzalloc ./ovs/lib/util.c:169:12 4 0x5d4899 in ovsdb_idl_txn_add_map_op ./lib/ovsdb-idl.c:4175:29 5 0x5d4758 in ovsdb_idl_txn_write_partial_map ./lib/ovsdb-idl.c:4332:5 6 0x53cbe8 in idltest_simple2_update_smap_setkey ./tests/idltest.c:4701:5 7 0x526fe2 in do_idl_partial_update_map_column ./tests/test-ovsdb.c:3027:5 8 0x59d99c in ovs_cmdl_run_command__ ./lib/command-line.c:247:17 9 0x59d79a in ovs_cmdl_run_command ./lib/command-line.c:278:5 10 0x51d458 in main ./tests/test-ovsdb.c:80:5 11 0x7f0a20a79b74 in __libc_start_main (/lib64/libc.so.6+0x27b74) Signed-off-by: Xavier Simonart Acked-by: Mike Pattrick Acked-by: Eelco Chaudron --- lib/ovsdb-idl.c | 2 ++ tests/ovsdb-idl.at | 9 +++++++-- tests/test-ovsdb.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index ba720474b..d92df28d1 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -3783,6 +3783,8 @@ ovsdb_idl_txn_delete(const struct ovsdb_idl_row *row_) ovsdb_idl_remove_from_indexes(row_); if (!row->old_datum) { ovsdb_idl_row_unparse(row); + ovsdb_idl_destroy_all_map_op_lists(row); + ovsdb_idl_destroy_all_set_op_lists(row); ovsdb_idl_row_clear_new(row); ovs_assert(!row->prereqs); hmap_remove(&row->table->rows, &row->hmap_node); diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index 9070ea051..74ccaccdd 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -1881,7 +1881,10 @@ OVSDB_CHECK_IDL_PARTIAL_UPDATE_MAP_COLUMN([map, simple2 idl-partial-update-map-c 007: name=String2 smap=[[key2 : value2]] imap=[[3 : myids2]] 008: After trying to delete a deleted element 009: name=String2 smap=[[key2 : value2]] imap=[[3 : myids2]] -010: End test +010: After Create element, update smap and Delete element +011: name=String2 smap=[[key2 : value2]] imap=[[3 : myids2]] +012: After update smap and Delete element +014: End test ]]) OVSDB_CHECK_IDL_PY([partial-map idl], @@ -1944,7 +1947,9 @@ OVSDB_CHECK_IDL_PARTIAL_UPDATE_SET_COLUMN([set, simple3 idl-partial-update-set-c 009: table simple3: name=String2 uset=[<0>,<1>,<4>] uref=[] uuid=<2> 010: After add to other table + set of strong ref 011: table simple3: name=String2 uset=[<0>,<1>,<4>] uref=[<5>] uuid=<2> -012: End test +012: After Create element, update set and Delete element +013: table simple3: name=String2 uset=[<0>,<1>,<4>] uref=[<5>] uuid=<2> +014: End test ]]) OVSDB_CHECK_IDL_PY([partial-set idl], diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index 41c1525f4..710341b65 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -3020,6 +3020,29 @@ do_idl_partial_update_map_column(struct ovs_cmdl_context *ctx) printf("%03d: After trying to delete a deleted element\n", step++); dump_simple2(idl, myRow, step++); + myTxn = ovsdb_idl_txn_create(idl); + myRow = idltest_simple2_insert(myTxn); + idltest_simple2_update_smap_setkey(myRow, "key3", "myList3"); + idltest_simple2_set_name(myRow, "String2"); + idltest_simple2_delete(myRow); + ovsdb_idl_txn_commit_block(myTxn); + ovsdb_idl_txn_destroy(myTxn); + ovsdb_idl_get_initial_snapshot(idl); + printf("%03d: After Create element, update smap and Delete element\n", + step++); + dump_simple2(idl, myRow, step++); + + myTxn = ovsdb_idl_txn_create(idl); + myRow = idltest_simple2_first(idl); + idltest_simple2_update_smap_setkey(myRow, "key4", "myList4"); + idltest_simple2_set_name(myRow, "String3"); + idltest_simple2_delete(myRow); + ovsdb_idl_txn_commit_block(myTxn); + ovsdb_idl_txn_destroy(myTxn); + ovsdb_idl_get_initial_snapshot(idl); + printf("%03d: After update smap and Delete element\n", step++); + dump_simple2(idl, myRow, step++); + ovsdb_idl_destroy(idl); printf("%03d: End test\n", step); } @@ -3118,6 +3141,21 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context *ctx) ovsdb_idl_get_initial_snapshot(idl); printf("%03d: After add to other table + set of strong ref\n", step++); dump_simple3(idl, myRow, step++); + + /* create row, insert key, delete row */ + myTxn = ovsdb_idl_txn_create(idl); + myRow = idltest_simple3_insert(myTxn); + uuid_from_string(&uuid_to_add, "12345678-dd3f-4616-ab6a-83a490bb0991"); + idltest_simple3_update_uset_addvalue(myRow, uuid_to_add); + idltest_simple3_set_name(myRow, "String2"); + idltest_simple3_delete(myRow); + ovsdb_idl_txn_commit_block(myTxn); + ovsdb_idl_txn_destroy(myTxn); + ovsdb_idl_get_initial_snapshot(idl); + printf("%03d: After Create element, update set and Delete element\n", + step++); + dump_simple3(idl, myRow, step++); + ovsdb_idl_destroy(idl); printf("%03d: End test\n", step); }