From patchwork Fri Aug 26 23:15:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 663262 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3sLcNm0QYfz9sBR for ; Sat, 27 Aug 2016 09:16:08 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id EC5AB10A4C; Fri, 26 Aug 2016 16:16:03 -0700 (PDT) X-Original-To: dev@openvswitch.com Delivered-To: dev@openvswitch.com Received: from mail-pa0-f65.google.com (mail-pa0-f65.google.com [209.85.220.65]) by archives.nicira.com (Postfix) with ESMTPS id BB45210A3E for ; Fri, 26 Aug 2016 16:16:00 -0700 (PDT) Received: by mail-pa0-f65.google.com with SMTP id hh10so5364179pac.1 for ; Fri, 26 Aug 2016 16:16:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VJZfNM5GgtZ77Da/6QAqPwCoFhXXQY1In4czP2ybFik=; b=fiAHc5b/tzDaOKNPlP8l6ODRR+ID80HNzVC7EtRO/WIP3RcnAYox6L0SdlkSeg2x4R 7gSfKu0ty+aNwj5mZhIkq3CJ5kGSVjq+UnWhWzzwwI1TLc4eokDG4D67i+3DcqLgLL// lsnNJxLcv+p/QG1Cm6QnzZ4Y51dOsqer0mQGZ9RX9a27pmas4SmdGTsqAsT/4TsOWHfI 2tqv6Cl1qllL472GQoP+yqQjDxgIOorgp4XMorITKKcmkkQcsahkHJ7B7Y/jNmC6zqII SLNF0dzKgHKmvugiFnooCr/fWccD6KJr8GEirLlrvO9BHfyVmwZ17S3FDksYmlMT98Kz O78A== X-Gm-Message-State: AE9vXwMRSNaxj6Q5jYzavsNzLERiN6b58KSsFgFHoQrUUi6RNbkoDwtfoTRLal71OS9EMg== X-Received: by 10.66.4.41 with SMTP id h9mr1414379pah.69.1472253360265; Fri, 26 Aug 2016 16:16:00 -0700 (PDT) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id yu7sm10195832pab.45.2016.08.26.16.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Aug 2016 16:15:59 -0700 (PDT) From: Andy Zhou To: dev@openvswitch.com Date: Fri, 26 Aug 2016 16:15:48 -0700 Message-Id: <1472253354-69501-2-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1472253354-69501-1-git-send-email-azhou@ovn.org> References: <1472253354-69501-1-git-send-email-azhou@ovn.org> Subject: [ovs-dev] [replication SMv2 1/7] ovsdb: Properly handle error returned from from reset_database() X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Fix a memory leak in case of error. The error object was not properly disposed. Since the error to reset DB is not expected, log it and exit. Signed-off-by: Andy Zhou --- ovsdb/replication.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ovsdb/replication.c b/ovsdb/replication.c index de6eec1..6681a20 100644 --- a/ovsdb/replication.c +++ b/ovsdb/replication.c @@ -21,6 +21,7 @@ #include "condition.h" #include "openvswitch/json.h" +#include "openvswitch/vlog.h" #include "jsonrpc.h" #include "ovsdb.h" #include "ovsdb-error.h" @@ -32,6 +33,8 @@ #include "table.h" #include "transaction.h" +VLOG_DEFINE_THIS_MODULE(replication) + static char *active_ovsdb_server; static struct jsonrpc *rpc; static struct sset monitored_tables = SSET_INITIALIZER(&monitored_tables); @@ -88,12 +91,14 @@ replication_run(struct shash *all_dbs) /* Reset local databases. */ if (reset_dbs) { struct ovsdb_error *error = reset_databases(all_dbs); - if (!error) { + if (error) { + /* In case reset DB fails, log the error before exiting. */ + char *msg = ovsdb_error_to_string(error); + ovsdb_error_destroy(error); + VLOG_FATAL("Failed to reset DB, (%s)", msg); + } else { reset_dbs = false; } - /* In case of success reseting the databases, - * return in order to notify monitors. */ - return; } /* Open JSON-RPC. */