From patchwork Mon Oct 7 08:10:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damijan Skvarc X-Patchwork-Id: 1172648 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="u0VuJ/Nb"; 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 46mtTR1RZFz9sN1 for ; Mon, 7 Oct 2019 19:10:49 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B8423AB9; Mon, 7 Oct 2019 08:10:46 +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 77580A7F for ; Mon, 7 Oct 2019 08:10:45 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9F0965F4 for ; Mon, 7 Oct 2019 08:10:42 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id b9so14077181wrs.0 for ; Mon, 07 Oct 2019 01:10:42 -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=UsE7iX1BBIZTokW0xKxqwPEaCYEfm5E/94dIe4aT1DU=; b=u0VuJ/NbJTyB/R7xvqk6Xd03LMmLzZRqG01Uj6Ho69MBZVGrR+Ev4s8A8kdSllftWq 3zQTZuOeW34/StgVTtXTLc8vw4JKl19uEsD1uqzVp4B6jV+2zyAyY/5FtXMpt+Gh6Tmb CMiS7cYKojGXX+QJyetzjvPl5EEEqJRL7ZEUmFIaK69Q7glhBdMXs0b2Mpj6pLVgKRl2 6zK75nYfP5iZ5sfNoyd25/BFE2ifF024Avj7QOBXlgEZvClgascWxa+qTRN4GxIfI1gM sf5XlnZF4wy4F5b2ybNxNv/r9vKnff7O6WUsPmik1UMoFtRyXYO/9Fc8ihk2YK/x435L j5vA== 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=UsE7iX1BBIZTokW0xKxqwPEaCYEfm5E/94dIe4aT1DU=; b=IWB+LuzDEIL50xLtSdF73q30jABApbReBEk+llaaW9JF4KZ8cZlC/ObBUXyOlULwkw k2uUQnyirZwu83qcl/Z14um1l87c4uaM4PJwmKtQ38NkZzw3DF9QxW+ms0V4+OnIxezy Nd5vrvdpHiQBKUknbaYesxMm7YnpHJ+AKO9HnrqFcvtZ+8WgfSiOZh4uLTdiJxXgMro0 191umUYH6fnyNBKVJtY9SSnOBM9Udyf33ykRwAEl7EeLqSc9W78gIGFYmzMn8inFgq+t sg5ra6TGD48J7thGA2KfN16XI6tVkPIPgBKNbn5dg+xjS/sWXQeTxTKOzLMPqBibdVQa 8/CQ== X-Gm-Message-State: APjAAAU9Tpf6DJJnL8L2iipKFv5BhqfLRY8pTUYl+4iftm4tvjPeYM57 8DmpHbYq0Nx8craUWU923Qzp/IiJERA= X-Google-Smtp-Source: APXvYqznJVn/MMkl5b5G/FeNqanNhH/jHmMgRXTNgvIICMm6dt1bg7pSP6xSwfSN6XqdxlRXI1dsNg== X-Received: by 2002:adf:f348:: with SMTP id e8mr13765550wrp.237.1570435840740; Mon, 07 Oct 2019 01:10:40 -0700 (PDT) Received: from damijan-PC.i-tech.local (mail.i-tech.si. [89.212.78.105]) by smtp.gmail.com with ESMTPSA id c4sm18423085wru.31.2019.10.07.01.10.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Oct 2019 01:10:39 -0700 (PDT) From: Damijan Skvarc To: dev@openvswitch.org Date: Mon, 7 Oct 2019 10:10:34 +0200 Message-Id: <1570435834-17079-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-tool: fix memory leak while converting cluster into standalone database 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 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 --- 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 3bbf4c8..a8f3135 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -951,26 +951,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); } } @@ -982,14 +986,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)); } } } @@ -1584,6 +1588,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); } }