From patchwork Tue Mar 24 19:33:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: aginwala aginwala X-Patchwork-Id: 1260937 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=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.a=rsa-sha256 header.s=20161025 header.b=LqWz15RT; 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 48n1fX5FZCz9sPR for ; Wed, 25 Mar 2020 06:34:44 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id ED4B58328C; Tue, 24 Mar 2020 19:34:42 +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 VLogqIw2gSPo; Tue, 24 Mar 2020 19:34:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 32D4A87ED6; Tue, 24 Mar 2020 19:34:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1BB94C089F; Tue, 24 Mar 2020 19:34:40 +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 DAF95C0177 for ; Tue, 24 Mar 2020 19:34:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C9E4687E89 for ; Tue, 24 Mar 2020 19:34:38 +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 m5cp8TOqhX8Z for ; Tue, 24 Mar 2020 19:34:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by whitealder.osuosl.org (Postfix) with ESMTPS id 8AE6B8328C for ; Tue, 24 Mar 2020 19:34:37 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id q16so1508979pje.1 for ; Tue, 24 Mar 2020 12:34:37 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=+bw54idadU8O9UAfI8WPBZXbKiojDbiXG3LzGxWzXX0=; b=LqWz15RTQiIp3wbuStimobXGtcv10VvWmPwnkXMD8fbmF/lQ69CUT0l28hB6+rY/c1 iiiyF4jszXaKeIPjNSWuIwusjPacQ97y4TjSlqMbg1KCMA8itronvhfRRL5YrX6KQ+Q3 zWKtP2XdFX/4xJHmZfsOqy/GmrmrmljKjAzNeyQ7yQ1/S7x07F1KUyAI9qQq+rizpghg IUULGrpeszJ9Wra5wWp/8ziw4cQ67DRkD8Zd9x489ZoWGr84uBr8KZQnJHVJs8wboyD/ eUl54X0O7Q7awnlX7GCJhFMNwPnXTNWUxao/Qw53Cvep6db07wXvoy4Pvp7ImZ+trgC2 +pCQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=+bw54idadU8O9UAfI8WPBZXbKiojDbiXG3LzGxWzXX0=; b=AHaTsXMWg4LwzsXKNJPr/Wzh6aq2hsK5FZAxmyHDRRiwpb7558LVAyOlftwmBq01NO u+9njZD3fpNv1VLUj5nEH5BVmvR21ojAcZQ8BFcWf/8bg9nukqdcxff9dSBW11uOmgpg NildrrJZbBuL4qpDde5nMN5i5ezzLSBcym8nlEjYG06ZLAoWj059PU3nMt9ECOVVt8M3 Xgh96wfx917RoJ8saDH1Nbvl/SUkqQMnn40wuaR5Ls6rDSodZX5YbIGs3RcjuTHV5lGu zTMvJexA4IGHMZ4rc4uZZwzfAdofrS5v8ulkiG5TDUmWqqAfHxFZ6AU4T0eIHnMM8Yf5 vUsQ== X-Gm-Message-State: ANhLgQ2HqQV6UikodlLtNmRheME3CxtBPRX165TDEruJUB5vBQVQhsFO wdxZjpbw4cXIBP4CwDT6xu6rNXOY X-Google-Smtp-Source: ADFU+vsIk4eHE+Dx4X2tihyVOBOLiyB5PfBNpQlgnggJf+T2SmIg5QaVzI1AYAFWXKhP7Vrsw1NOXQ== X-Received: by 2002:a17:90a:808c:: with SMTP id c12mr7357535pjn.6.1585078476825; Tue, 24 Mar 2020 12:34:36 -0700 (PDT) Received: from LM-SJC-11020505.corp.ebay.com ([216.113.160.71]) by smtp.gmail.com with ESMTPSA id nl7sm3155148pjb.36.2020.03.24.12.34.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2020 12:34:36 -0700 (PDT) From: amginwal@gmail.com To: dev@openvswitch.org Date: Tue, 24 Mar 2020 12:33:54 -0700 Message-Id: <20200324193354.56514-2-amginwal@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200324193354.56514-1-amginwal@gmail.com> References: <20200324193354.56514-1-amginwal@gmail.com> MIME-Version: 1.0 Cc: Aliasgar Ginwala Subject: [ovs-dev] [PATCH branch-2.11 2/2] ovsdb-tool: fix memory leak while converting cluster into standalone database 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" From: Damijan Skvarc memory leak is reported by valgrind while executing functional test "ovsdb-tool convert-to-standalone" ==13842== 2,850 (280 direct, 2,570 indirect) bytes in 7 blocks are definitely lost in loss record 20 of 20 ==13842== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==13842== by 0x45EE2E: xmalloc (util.c:138) ==13842== by 0x43E386: json_create (json.c:1451) ==13842== by 0x43BDD2: json_object_create (json.c:254) ==13842== by 0x43DEE3: json_parser_push_object (json.c:1273) ==13842== by 0x43E167: json_parser_input (json.c:1371) ==13842== by 0x43D6EA: json_lex_input (json.c:991) ==13842== by 0x43DAC1: json_parser_feed (json.c:1149) ==13842== by 0x40D108: parse_body (log.c:411) ==13842== by 0x40D386: ovsdb_log_read (log.c:476) ==13842== by 0x406A0B: do_convert_to_standalone (ovsdb-tool.c:1571) ==13842== by 0x406A0B: do_cluster_standalone (ovsdb-tool.c:1606) ==13842== by 0x438670: ovs_cmdl_run_command__ (command-line.c:223) ==13842== by 0x438720: ovs_cmdl_run_command (command-line.c:254) ==13842== by 0x405A4C: main (ovsdb-tool.c:79) The problem was in do_convert_to_standalone() function which while reading log file allocate json object which was not deallocated at the end. Signed-off-by: Damijan Skvarc Signed-off-by: Ben Pfaff Signed-off-by: Aliasgar Ginwala --- ovsdb/ovsdb-tool.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index ba78760ef..91662cab8 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -953,26 +953,30 @@ raft_header_to_standalone_log(const struct raft_header *h, { if (h->snap_index) { if (!h->snap.data || json_array(h->snap.data)->n != 2) { - ovs_fatal(0, "Incorrect raft header data array length"); + ovs_fatal(0, "Incorrect raft header data array length"); } - struct json *schema_json = json_array(h->snap.data)->elems[0]; + struct json_array *pa = json_array(h->snap.data); + struct json *schema_json = pa->elems[0]; + struct ovsdb_error *error = NULL; + if (schema_json->type != JSON_NULL) { struct ovsdb_schema *schema; check_ovsdb_error(ovsdb_schema_from_json(schema_json, &schema)); ovsdb_schema_destroy(schema); - check_ovsdb_error(ovsdb_log_write_and_free(db_log_data, - schema_json)); + error = ovsdb_log_write(db_log_data, schema_json); } - struct json *data_json = json_array(h->snap.data)->elems[1]; - if (!data_json || data_json->type != JSON_OBJECT) { - ovs_fatal(0, "Invalid raft header data"); - } - if (data_json->type != JSON_NULL) { - check_ovsdb_error(ovsdb_log_write_and_free(db_log_data, - data_json)); + if (!error) { + struct json *data_json = pa->elems[1]; + if (!data_json || data_json->type != JSON_OBJECT) { + ovs_fatal(0, "Invalid raft header data"); + } + if (data_json->type != JSON_NULL) { + error = ovsdb_log_write(db_log_data, data_json); + } } + check_ovsdb_error(error); } } @@ -984,14 +988,14 @@ raft_record_to_standalone_log(const struct raft_record *r, if (!r->entry.data) { return; } - if (json_array(r->entry.data)->n != 2) { + struct json_array *pa = json_array(r->entry.data); + + if (pa->n != 2) { ovs_fatal(0, "Incorrect raft record array length"); } - - struct json *data_json = json_array(r->entry.data)->elems[1]; + struct json *data_json = pa->elems[1]; if (data_json->type != JSON_NULL) { - check_ovsdb_error(ovsdb_log_write_and_free(db_log_data, - data_json)); + check_ovsdb_error(ovsdb_log_write(db_log_data, data_json)); } } } @@ -1586,6 +1590,7 @@ do_convert_to_standalone(struct ovsdb_log *log, struct ovsdb_log *db_log_data) raft_record_to_standalone_log(&r, db_log_data); raft_record_uninit(&r); } + json_destroy(json); } }