From patchwork Wed Oct 9 06:34:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damijan Skvarc X-Patchwork-Id: 1173604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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="KWNi9Z0W"; 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 46p4FX0bV1z9s7T for ; Wed, 9 Oct 2019 17:34:39 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 49123B65; Wed, 9 Oct 2019 06:34:35 +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 43E71B5F for ; Wed, 9 Oct 2019 06:34:34 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id AFAF05D3 for ; Wed, 9 Oct 2019 06:34:33 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id 3so1054259wmi.3 for ; Tue, 08 Oct 2019 23:34:33 -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=c5eV8JKr4tYGVxd2k+nlHi65xvZOF7zPEh14vVbSwFs=; b=KWNi9Z0WYLEJBFuqiP4merO9ox8ULQhgb+5CkVZoR5jfPITJXu9l+RqcYwfVM87L4c fTZi8sFujOYZoIJW9hI40sQRcAOFMI6nrQ1babmX9zq0aZhiqqgvDrmVGrTvlJZeKOCK VkEqI0mWWcBg0gQm9ehDwqSl+PEIyAAt+EVkl5elV+2AvETJv+SnNqwvDC4c6uEQqy1i bcpLiwBEzJDC7WNtSJDUUMlzYmwqWJAboW0/apxl0C2eZe4NtZ5vfTJL/3kKV7cbSkUm onUTVhARqA7T/cVLxSRFA6eUra2yQqJrbeHGyBe+9DJeN4LDvwXVLCX29QOYf3SJHWZr oE4Q== 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=c5eV8JKr4tYGVxd2k+nlHi65xvZOF7zPEh14vVbSwFs=; b=mXHXO5w3BbCJd/+eafzRcQGG3xDqpsntGVvnYtO3aI67sQiCWJ6PrNJ8iVlbCBCcoK UJBMPrn0JL6mPG4JQgS73tXVHnYGKAAZOuTTp9+F2n4nCs2YDhR3lMtXZt0TIUhNODER 1B4Xs2isVItkx7d9prgE0R4lktC/UQ9iB53GyX683o2sQfQndW+PThEGRGfx2gJ8q5di oep9LQl55xBGRVeTo5mWrRsm5tfItLXHsANtXq2yWm+r6+7AoUuPhJ2E1n8VOU4BVHZZ nI3ONh8TA18JfoCll0acF90VO/Tl1mkhqP6Arma9Byfa7YBO22USVjzzLB5hVu/r9caU uLLA== X-Gm-Message-State: APjAAAXmArXLwFPE6/jfrF3pSCupzcdGWdOsP+yelufK3JPSjbfReXgj XdNZuLcJgbvf+i14/c/INBmsgMWaqWg= X-Google-Smtp-Source: APXvYqzyKFINJBGG8Oso6maRTKsVXBJPlqtQOgFFI2l4u4f5+ORcKzs96pd0CTU4sTA6BOiOsd5vkg== X-Received: by 2002:a1c:444:: with SMTP id 65mr1317056wme.84.1570602871784; Tue, 08 Oct 2019 23:34:31 -0700 (PDT) Received: from damijan-PC.i-tech.local (mail.i-tech.si. [89.212.78.105]) by smtp.gmail.com with ESMTPSA id o1sm1470129wrs.78.2019.10.08.23.34.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Oct 2019 23:34:30 -0700 (PDT) From: Damijan Skvarc To: dev@openvswitch.org Date: Wed, 9 Oct 2019 08:34:24 +0200 Message-Id: <1570602864-7007-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-client: fix memory leak while executing database backup 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 valgrind detects this leak while running functional test "ovsdb-client backup and restore" ==25401== 1,068 (240 direct, 828 indirect) bytes in 6 blocks are definitely lost in loss record 22 of 22 ==25401== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==25401== by 0x449DA4: xmalloc (util.c:138) ==25401== by 0x43012D: json_create (json.c:1451) ==25401== by 0x43012D: json_array_create_empty (json.c:186) ==25401== by 0x43012D: json_parser_push_array (json.c:1279) ==25401== by 0x4303CF: json_parser_input (json.c:1407) ==25401== by 0x4312F1: json_lex_input (json.c:991) ==25401== by 0x43193B: json_parser_feed (json.c:1149) ==25401== by 0x4329FA: jsonrpc_recv.part.7 (jsonrpc.c:332) ==25401== by 0x432D3B: jsonrpc_recv (jsonrpc.c:297) ==25401== by 0x432D3B: jsonrpc_recv_block (jsonrpc.c:402) ==25401== by 0x4330EB: jsonrpc_transact_block (jsonrpc.c:436) ==25401== by 0x409246: do_backup (ovsdb-client.c:2008) ==25401== by 0x405F76: main (ovsdb-client.c:282) the problem was in db_backup() function, where _uuid json node was detached from its parent "row" json node, but never destroyed afterwards. Signed-off-by: Damijan Skvarc --- ovsdb/ovsdb-client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index 8878462..72756eb 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -2061,6 +2061,7 @@ do_backup(struct jsonrpc *rpc, const char *database, char uuid_s[UUID_LEN + 1]; snprintf(uuid_s, sizeof uuid_s, UUID_FMT, UUID_ARGS(&atom.uuid)); json_object_put(output_rows, uuid_s, json_clone(row)); + json_destroy(uuid_json); } json_object_put(output_txn, table_name, output_rows); }