Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1439459ybi; Wed, 3 Jul 2019 16:04:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfVHKFOU8ZjKHvgpA7nrA/BI+dzV2oIPNhHwRuK9DEZKSZwMd4pSLVxtU5Dw5efA44+ecJ X-Received: by 2002:a63:4105:: with SMTP id o5mr40960972pga.308.1562195043874; Wed, 03 Jul 2019 16:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562195043; cv=none; d=google.com; s=arc-20160816; b=v64YtXV/d1INYB/6tyl1tviTPELxP1t6GOKQBG9fNRg9Ofj1LDehcGArbdOUgUiFkO kZ8dnnZlDpBrSHQx8A8ulETQtFVSNxciYjH7GLp8tU0ynkXKHVp3dhb1q/e0SEXrWYlP x73t0rCnSkVqLSIxTxUBjGZxxpsEgSK9bx03GHY9p+BK+htqyIeFdBvSyqm7qUvBGUmu zvPaddb6+ZEZdu9b/WvGBgF6AV+Ialu1vhOro9JF8/QrosaC3Rf5fgQNLYafBEmjWiY0 louaXBL46qEAKUACYb6dPUDqauNWfY7TBgErYC2UBPmKiY9rGMgv9Vu/rejHS7fsFSge aSCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=90zC4JBFrGFu5u5S9fqRiS/RpilsEjbxx+5j9Dz5zOs=; b=V5c7FOMeTrLLfyJqFveFAbxfWcIB1Lm2VeFZAfSnxOlFhvPJBLEJtMhnblpu9CxeGH lMEMrhuxHy9CK3M2IrVbTR/4DrDsTwci5Z+2bofJNhykDTAP4HD5BJ8+7udrIvqnrXC+ B3fJnocTlDuNnXXCbl9oazo8mgvipG5O5YpgIy+9EAww9vAxmYwod3r5R2WGw4ur9Ciu 9US/j7TSWa7eyiy2fAfmMENXOFLT/VWADFHtZpXFpnl2YiZ8Hk6udcAa9UTOQkN8XR8d cfuViWs9LVlMwEyZGyg++cL/fZomJQkcF/HelTRtZ/u1/QJQrsCxDJACXoH1QlwuhAHJ D9gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c139si3640135pfb.140.2019.07.03.16.03.36; Wed, 03 Jul 2019 16:04:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbfGCXCr (ORCPT + 99 others); Wed, 3 Jul 2019 19:02:47 -0400 Received: from mga09.intel.com ([134.134.136.24]:54332 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727451AbfGCXCr (ORCPT ); Wed, 3 Jul 2019 19:02:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jul 2019 16:02:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,448,1557212400"; d="scan'208";a="362784662" Received: from ingas-nuc1.sea.intel.com ([10.254.86.21]) by fmsmga005.fm.intel.com with ESMTP; 03 Jul 2019 16:02:45 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, michal.lowas-rzechonek@silvair.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Fix clean up of node's DBUS assosiated resources Date: Wed, 3 Jul 2019 16:02:44 -0700 Message-Id: <20190703230244.20229-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This consolidates multiple places where node's object paths, interfaces, etc. are de-allocated, into one routine: free_node_dbus_resources(). This also addresses memory leaks assosiated with inconsistent freeing of object path strings. --- mesh/node.c | 66 +++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index adc2aa93e..67e0dd014 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -226,34 +226,46 @@ static void element_free(void *data) l_free(element); } -static void free_node_resources(void *data) +static void free_node_dbus_resources(struct mesh_node *node) { - struct mesh_node *node = data; + if (!node) + return; - /* Unregister io callbacks */ - if (node->net) - mesh_net_detach(node->net); - mesh_net_free(node->net); + if (node->disc_watch) { + l_dbus_remove_watch(dbus_get_bus(), node->disc_watch); + node->disc_watch = 0; + } - l_queue_destroy(node->elements, element_free); - l_free(node->comp); - l_free(node->app_path); + l_queue_foreach(node->elements, free_element_path, NULL); l_free(node->owner); - l_free(node->node_path); - - if (node->disc_watch) - l_dbus_remove_watch(dbus_get_bus(), node->disc_watch); + node->owner = NULL; + l_free(node->app_path); + node->app_path = NULL; if (node->path) { l_dbus_object_remove_interface(dbus_get_bus(), node->path, MESH_NODE_INTERFACE); l_dbus_object_remove_interface(dbus_get_bus(), node->path, - MESH_MANAGEMENT_INTERFACE); + MESH_MANAGEMENT_INTERFACE); + l_free(node->path); + node->path = NULL; } +} - l_free(node->path); +static void free_node_resources(void *data) +{ + struct mesh_node *node = data; + /* Unregister io callbacks */ + if (node->net) + mesh_net_detach(node->net); + mesh_net_free(node->net); + + l_queue_destroy(node->elements, element_free); + l_free(node->comp); + + free_node_dbus_resources(node); l_free(node); } @@ -1033,24 +1045,9 @@ static void app_disc_cb(struct l_dbus *bus, void *user_data) l_info("App %s disconnected (%u)", node->owner, node->disc_watch); node->disc_watch = 0; - - l_queue_foreach(node->elements, free_element_path, NULL); - - l_free(node->owner); - node->owner = NULL; - - if (node->path) { - l_dbus_object_remove_interface(dbus_get_bus(), node->path, - MESH_NODE_INTERFACE); - - l_dbus_object_remove_interface(dbus_get_bus(), node->path, - MESH_MANAGEMENT_INTERFACE); - l_free(node->app_path); - node->app_path = NULL; - } + free_node_dbus_resources(node); } - static bool validate_model_property(struct node_element *ele, struct l_dbus_message_iter *property, uint8_t *num_models, bool vendor) @@ -1611,14 +1608,9 @@ fail: /* Handle failed Attach request */ node_ready_func_t cb = req->cb; - l_queue_foreach(node->elements, free_element_path, NULL); - l_free(node->app_path); - node->app_path = NULL; + free_node_dbus_resources(node); - l_free(node->owner); - node->owner = NULL; cb(req->user_data, MESH_ERROR_FAILED, node); - } else { /* Handle failed Join and Create requests */ if (node) -- 2.21.0