From patchwork Thu Oct 24 07:20:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damijan Skvarc X-Patchwork-Id: 1182653 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.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="a20vc9rY"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zJZ73bXlz9sP4 for ; Thu, 24 Oct 2019 18:21:02 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 20A3FAC7; Thu, 24 Oct 2019 07:21:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B34EA92F for ; Thu, 24 Oct 2019 07:20:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2FEA387B for ; Thu, 24 Oct 2019 07:20:58 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id p4so24776321wrm.8 for ; Thu, 24 Oct 2019 00:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=l11cbinzMR5d5SRF0i1SsxiS/QXX0/BHa/tYfJZeN64=; b=a20vc9rYZkio4vAJSddl5QCa6ui2ffZYgevA1Id9q3pOiR16yf7oCwz1crtjwr0MUQ jBq14ZgFw/KHmQlHScV+qAtCGBxkKyV5oIMlDa42asz26qA3u66C/+r0kvv/uCNPgpEk Fy/54haVO9rAjBiyoVnzHjsLOA0Cig+89AmAhlwDgQxgmVWzhvBreZWAw76zg7IpOcqG O9VbuhOESgoHwsrrQB9qNg23/+WrG0HKBNMN/9qJsNkFo0+OqwRbDFOudJ1rbs0MyltI kukqnBT8cDEGsaDKlgKVm96gl96l4iWuSh08H+MvFKxGcebCntfArnp2FDuiWAMpp+b9 CsGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=l11cbinzMR5d5SRF0i1SsxiS/QXX0/BHa/tYfJZeN64=; b=oXfo81y5oqd1uqrbpE/+3t7KLP8LjewreriblfyHMosnLy+tIn0ukk6YU+1j0iWk4R gaOVUyqjQVQkxNSl8ghLWSf1qXClq+uuTHzAmrNIaKwAjW5sT/K5E3GddoKXko1+a8EB iH3ZXAQbQcMQaMce3W5PBZ7OfpFJKSHpJeVrPA7T1ati7jOUVC9m8k4aZufsGABiB1s1 N2ttkRI87nUtFET8rbnj9IKzzz4cSyiklfPJVcNP3LfSTbhoOSK0SLLOEFWc9ZtQDMAN EDF/rLfxi7GnFPvk0YRi8F/hUqQvgLjM2KN06BAQRJuqLP84FBvTBXniwKfDXw8YbmV4 HMTA== X-Gm-Message-State: APjAAAX+hN6SXcy7jywiwz4rTPUA34+Ih3v44mtuWzWoAkvCG9uLqavb bdPvcSu67YM51/eD6YZcTb1GnuMT X-Google-Smtp-Source: APXvYqxZQM3w13GC+37MntPdVeEqahMug7NrraFfkg7j97qHdvJ0qCRPMdCDd9nf7aH527AQ+tWMRg== X-Received: by 2002:adf:e849:: with SMTP id d9mr2315984wrn.145.1571901656287; Thu, 24 Oct 2019 00:20:56 -0700 (PDT) Received: from damijan-PC.i-tech.local (mail.i-tech.si. [89.212.78.105]) by smtp.gmail.com with ESMTPSA id g11sm1445481wmh.45.2019.10.24.00.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Oct 2019 00:20:55 -0700 (PDT) From: Damijan Skvarc To: dev@openvswitch.org Date: Thu, 24 Oct 2019 09:20:49 +0200 Message-Id: <1571901649-5501-1-git-send-email-damjan.skvarc@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/1] ovsdb-server: fix memory leak in ovsdb_convert_table() function. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Memory leak happens while converting existing database into new database according to the specified schema (ovsdb-client convert new-schema). Memory leak was detected by valgrind while executing functional test "schema conversion online - clustered" ==16202== 96 bytes in 6 blocks are definitely lost in loss record 326 of 399 ==16202== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16202== by 0x44A5D4: xmalloc (util.c:138) ==16202== by 0x4377A6: alloc_default_atoms (ovsdb-data.c:315) ==16202== by 0x437F18: ovsdb_datum_init_default (ovsdb-data.c:918) ==16202== by 0x413D82: ovsdb_row_create (row.c:59) ==16202== by 0x40AA53: ovsdb_convert_table (file.c:220) ==16202== by 0x40AA53: ovsdb_convert (file.c:275) ==16202== by 0x416BE1: ovsdb_trigger_try (trigger.c:255) ==16202== by 0x40D29E: ovsdb_jsonrpc_trigger_create (jsonrpc-server.c:1119) ==16202== by 0x40D29E: ovsdb_jsonrpc_session_got_request (jsonrpc-server.c:986) ==16202== by 0x40D29E: ovsdb_jsonrpc_session_run (jsonrpc-server.c:556) ==16202== by 0x40D29E: ovsdb_jsonrpc_session_run_all (jsonrpc-server.c:586) ==16202== by 0x40D29E: ovsdb_jsonrpc_server_run (jsonrpc-server.c:401) ==16202== by 0x40682E: main_loop (ovsdb-server.c:209) ==16202== by 0x40682E: main (ovsdb-server.c:460) The problem was in ovsdb_datum_convert() function, which overrides pointers to datum memory allocated in ovsdb_row_create() function. Fix was done by freeing this memory before ovsdb_datum_convert() is called. Signed-off-by: Damijan Skvarc --- ovsdb/file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ovsdb/file.c b/ovsdb/file.c index 8d16b09..7ac7df0 100644 --- a/ovsdb/file.c +++ b/ovsdb/file.c @@ -235,6 +235,8 @@ ovsdb_convert_table(struct ovsdb_txn *txn, continue; } + ovsdb_datum_destroy(&dst_row->fields[dst_column->index], &dst_column->type); + struct ovsdb_error *error = ovsdb_datum_convert( &dst_row->fields[dst_column->index], &dst_column->type, &src_row->fields[src_column->index], &src_column->type);