From patchwork Tue Nov 24 12:16:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1405507 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=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: 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=dZFJyrYu; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CgNKv28qQz9sTR for ; Tue, 24 Nov 2020 23:16:34 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 42587867CC; Tue, 24 Nov 2020 12:16:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TWejhwW-+tVG; Tue, 24 Nov 2020 12:16:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id D07A085EF9; Tue, 24 Nov 2020 12:16:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B79B3C1833; Tue, 24 Nov 2020 12:16:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4E9BFC0052 for ; Tue, 24 Nov 2020 12:16:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3DF7385E0B for ; Tue, 24 Nov 2020 12:16:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZF6fVPMzu9eG for ; Tue, 24 Nov 2020 12:16:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 8BA72857F8 for ; Tue, 24 Nov 2020 12:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606220188; 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: in-reply-to:in-reply-to:references:references; bh=/gmXkOXPM3cMxXEkOZcxuOVhQUK6U8KjztPm2TiPapo=; b=dZFJyrYuswbQjIs9A+nbZvKQKZ1mrSiLQZv6Wb78ner+LezdQSCWcY+TDfpQkvzgjolEWa MtC4WwwRa/q7zVIwPuyxHL93Vb/Enicqq1t4pEjTn0BZO8jPY96zqOSGPL8cAFk9rn8syz z/NTwpZGcg7DnMLf5+rknuSJrtrZnSA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-FKlv2FaSN5S4kqIbj0tAeQ-1; Tue, 24 Nov 2020 07:16:26 -0500 X-MC-Unique: FKlv2FaSN5S4kqIbj0tAeQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69F7F8030B4; Tue, 24 Nov 2020 12:16:25 +0000 (UTC) Received: from dceara.remote.csb (ovpn-114-190.ams2.redhat.com [10.36.114.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D08719C44; Tue, 24 Nov 2020 12:16:23 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Tue, 24 Nov 2020 13:16:21 +0100 Message-Id: <20201124121615.20453.10922.stgit@dceara.remote.csb> In-Reply-To: <20201124121604.20453.67212.stgit@dceara.remote.csb> References: <20201124121604.20453.67212.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: hzhou@ovn.org, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 1/3] ovsdb-idl: Fix memleak when reinserting tracked orphan rows. 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" It's possible that the IDL client processes multiple jsonrpc updates in a single ovsdb_idl_run(). Considering the following updates processed in a single IDL run: 1. Delete row R1 from table A while R1 is also referenced by row R2 from table B: - because row R2 still refers to row R1, this will create an orphan R1 but also sets row->tracked_old_datum to report to the IDL client that the row has been deleted. 2. Insert row R1 to table A. - because orphan R1 already existed in the IDL, it will be reused. - R1 still has row->tracked_old_datum set (and may also be on the table->track_list). 3. Delete row R2 from table B and row R1 from table A. - row->tracked_old_datum is set again but the previous tracked_old_datum was never freed. IDL clients don't currently use the deleted old_datum values but they might decide to do that in the future so when multiple delete operations are received for a row, always track the first one as that will match the contents of the row the IDL client knew about. Fixes: 72aeb243a52a ("ovsdb-idl: Tracking - preserve data for deleted rows.") Signed-off-by: Dumitru Ceara --- lib/ovsdb-idl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 6334061..bbc22e4 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -3219,7 +3219,7 @@ ovsdb_idl_row_clear_old(struct ovsdb_idl_row *row) { ovs_assert(row->old_datum == row->new_datum); if (!ovsdb_idl_row_is_orphan(row)) { - if (ovsdb_idl_track_is_set(row->table)) { + if (ovsdb_idl_track_is_set(row->table) && !row->tracked_old_datum) { row->tracked_old_datum = row->old_datum; } else { const struct ovsdb_idl_table_class *class = row->table->class_; From patchwork Tue Nov 24 12:16:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1405508 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=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: 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=eWLyLOww; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CgNL52DMCz9sT6 for ; Tue, 24 Nov 2020 23:16:44 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1CBD285F15; Tue, 24 Nov 2020 12:16:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qhWQlWGop7pz; Tue, 24 Nov 2020 12:16:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7795E85E98; Tue, 24 Nov 2020 12:16:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6E5CEC0891; Tue, 24 Nov 2020 12:16:42 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 72D9FC1D9F for ; Tue, 24 Nov 2020 12:16:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 61A26864D4 for ; Tue, 24 Nov 2020 12:16:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9JdWIVaanhGg for ; Tue, 24 Nov 2020 12:16:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by whitealder.osuosl.org (Postfix) with ESMTPS id 736AB8682F for ; Tue, 24 Nov 2020 12:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606220199; 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: in-reply-to:in-reply-to:references:references; bh=6ft6K8ckJmvLz01gcjVS5jKdW7zB3oAbHE8rwsauFlE=; b=eWLyLOww8o3r5fZmwAFLX8qZzVvzKSgX/0V532cNxQmJlDDLCc0pDqancRj0C2L8uNrVXd 0Jmx9mlsBVrP1DUoSHgi5Tf2pDGsD71E1JluwTJEeEjygDl4TWiIuzs17spoT6ztxrCL2P gGvPbRE/BkI99nYuQqlQMBT7OTsKwIQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-244-n_rdWs1FN1mTF67k6QgXWA-1; Tue, 24 Nov 2020 07:16:37 -0500 X-MC-Unique: n_rdWs1FN1mTF67k6QgXWA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9179983DAA1; Tue, 24 Nov 2020 12:16:36 +0000 (UTC) Received: from dceara.remote.csb (ovpn-114-190.ams2.redhat.com [10.36.114.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DBE260873; Tue, 24 Nov 2020 12:16:35 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Tue, 24 Nov 2020 13:16:33 +0100 Message-Id: <20201124121630.20453.20417.stgit@dceara.remote.csb> In-Reply-To: <20201124121604.20453.67212.stgit@dceara.remote.csb> References: <20201124121604.20453.67212.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: hzhou@ovn.org, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 2/3] ovsdb-idl: Fix memleak when deleting orphan rows. 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" Pure IDL orphan rows, i.e., for which no "insert" operation was seen, which are part of tables with change tracking enabled should also be freed when the table track_list is flushed. Reported-by: Ilya Maximets Fixes: 72aeb243a52a ("ovsdb-idl: Tracking - preserve data for deleted rows.") Signed-off-by: Dumitru Ceara --- lib/ovsdb-idl.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index bbc22e4..b282ce4 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1969,16 +1969,18 @@ ovsdb_idl_db_track_clear(struct ovsdb_idl_db *db) ovs_list_remove(&row->track_node); ovs_list_init(&row->track_node); - if (ovsdb_idl_row_is_orphan(row) && row->tracked_old_datum) { + if (ovsdb_idl_row_is_orphan(row)) { ovsdb_idl_row_unparse(row); - const struct ovsdb_idl_table_class *class = - row->table->class_; - for (size_t c = 0; c < class->n_columns; c++) { - ovsdb_datum_destroy(&row->tracked_old_datum[c], - &class->columns[c].type); + if (row->tracked_old_datum) { + const struct ovsdb_idl_table_class *class = + row->table->class_; + for (size_t c = 0; c < class->n_columns; c++) { + ovsdb_datum_destroy(&row->tracked_old_datum[c], + &class->columns[c].type); + } + free(row->tracked_old_datum); + row->tracked_old_datum = NULL; } - free(row->tracked_old_datum); - row->tracked_old_datum = NULL; free(row); } } From patchwork Tue Nov 24 12:16:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1405510 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=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: 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=DseXOJ0c; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CgNLv4HJHz9sSs for ; Tue, 24 Nov 2020 23:17:27 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D7C432107A; Tue, 24 Nov 2020 12:17:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zh6I5NQG6W6c; Tue, 24 Nov 2020 12:17:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 6ACC622640; Tue, 24 Nov 2020 12:17:06 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4FEA0C1833; Tue, 24 Nov 2020 12:17:06 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5E174C0052 for ; Tue, 24 Nov 2020 12:17:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 4BB23220C1 for ; Tue, 24 Nov 2020 12:17:04 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CpKEOA9gvGwf for ; Tue, 24 Nov 2020 12:16:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by silver.osuosl.org (Postfix) with ESMTPS id B4E8E21537 for ; Tue, 24 Nov 2020 12:16:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606220212; 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: in-reply-to:in-reply-to:references:references; bh=ttPR9NEuCPLmhgDIf9ESO8oby793jR+zxRrCxA98KFI=; b=DseXOJ0cPjXncmouIelbnsI9c23yRo7kCuWJrXP7fHv3iGH+q4ocb3asKwVZEy6Nw4gso0 2CK1G6W/H2U7FMA+d/5jiBAwmpAkIi0wSPfw4KcroeFvzWIHCl0vBvhJORRuOAuYdTSgaN j/Bte47q0Ih0L/ptiBv8edZ6giB1dtU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-x8cQFvGANxKM3GWJIu4cAw-1; Tue, 24 Nov 2020 07:16:50 -0500 X-MC-Unique: x8cQFvGANxKM3GWJIu4cAw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB5821E640; Tue, 24 Nov 2020 12:16:49 +0000 (UTC) Received: from dceara.remote.csb (ovpn-114-190.ams2.redhat.com [10.36.114.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E7C55D9CA; Tue, 24 Nov 2020 12:16:48 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Tue, 24 Nov 2020 13:16:45 +0100 Message-Id: <20201124121641.20453.65829.stgit@dceara.remote.csb> In-Reply-To: <20201124121604.20453.67212.stgit@dceara.remote.csb> References: <20201124121604.20453.67212.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: hzhou@ovn.org, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 3/3] ovsdb-idl: Fix use-after-free when deleting orphaned rows. 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" It's possible that the IDL client processes multiple jsonrpc updates in a single ovsdb_idl_run(). Considering the following updates processed in a single IDL run: 1. Update row R1 from table A while R1 is also referenced by row R2 from table B: - this adds R1 to table A's track_list. 2. Delete row R1 from table A while R1 is also referenced by row R2 from table B: - because row R2 still refers to row R1, this will create an orphan R1. - at this point R1 is still in table A's hmap. When the IDL client calls ovsdb_idl_track_clear() after it has finished processing the tracked changes, row R1 gets freed leaving a dangling pointer in table A's hmap. To fix this we don't free rows in ovsdb_idl_track_clear() if they are orphan and still referenced by other rows, i.e., the row's 'dst_arcs' list is not empty. Later, when all arc sources (e.g., R2) are deleted, the orphan R1 will be cleaned up as well. The only exception is when the whole contents of the IDL are flushed, in ovsdb_idl_db_clear(), in which case it's safe to free all rows. Reported-by: Ilya Maximets Fixes: 72aeb243a52a ("ovsdb-idl: Tracking - preserve data for deleted rows.") Signed-off-by: Dumitru Ceara --- lib/ovsdb-idl.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index b282ce4..cdeb63b 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -221,7 +221,7 @@ struct ovsdb_idl_db { struct uuid last_id; }; -static void ovsdb_idl_db_track_clear(struct ovsdb_idl_db *); +static void ovsdb_idl_db_track_clear(struct ovsdb_idl_db *, bool flush_all); static void ovsdb_idl_db_add_column(struct ovsdb_idl_db *, const struct ovsdb_idl_column *); static void ovsdb_idl_db_omit(struct ovsdb_idl_db *, @@ -660,7 +660,7 @@ ovsdb_idl_db_clear(struct ovsdb_idl_db *db) ovsdb_idl_row_destroy_postprocess(db); db->cond_seqno = 0; - ovsdb_idl_db_track_clear(db); + ovsdb_idl_db_track_clear(db, true); if (changed) { db->change_seqno++; @@ -1947,7 +1947,7 @@ ovsdb_idl_track_is_updated(const struct ovsdb_idl_row *row, * loop when it is ready to do ovsdb_idl_run() again. */ static void -ovsdb_idl_db_track_clear(struct ovsdb_idl_db *db) +ovsdb_idl_db_track_clear(struct ovsdb_idl_db *db, bool flush_all) { size_t i; @@ -1981,7 +1981,18 @@ ovsdb_idl_db_track_clear(struct ovsdb_idl_db *db) free(row->tracked_old_datum); row->tracked_old_datum = NULL; } - free(row); + + /* Rows that were reused as orphan after being processed + * for deletion are still in the table hmap and will be + * cleaned up when their src arcs are removed. + * + * The exception is when 'destroy' is explicitly set to + * 'true' which usually happens when the complete IDL + * contents are being flushed. + */ + if (flush_all || ovs_list_is_empty(&row->dst_arcs)) { + free(row); + } } } } @@ -1996,7 +2007,7 @@ ovsdb_idl_db_track_clear(struct ovsdb_idl_db *db) void ovsdb_idl_track_clear(struct ovsdb_idl *idl) { - ovsdb_idl_db_track_clear(&idl->data); + ovsdb_idl_db_track_clear(&idl->data, false); } static void