Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753802AbdIHNxT (ORCPT ); Fri, 8 Sep 2017 09:53:19 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34410 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932529AbdIHNUe (ORCPT ); Fri, 8 Sep 2017 09:20:34 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Brauner Subject: [PATCH 4.13 20/47] binder: free memory on error Date: Fri, 8 Sep 2017 15:18:52 +0200 Message-Id: <20170908131824.469270678@linuxfoundation.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170908131823.546721606@linuxfoundation.org> References: <20170908131823.546721606@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1548 Lines: 51 4.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner commit 22eb9476b5d80a393ac0ba235c42bccc90b82c76 upstream. On binder_init() the devices string is duplicated and smashed into individual device names which are passed along. However, the original duplicated string wasn't freed in case binder_init() failed. Let's free it on error. Signed-off-by: Christian Brauner Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -4215,7 +4215,7 @@ static int __init init_binder_device(con static int __init binder_init(void) { int ret; - char *device_name, *device_names; + char *device_name, *device_names, *device_tmp; struct binder_device *device; struct hlist_node *tmp; @@ -4263,7 +4263,8 @@ static int __init binder_init(void) } strcpy(device_names, binder_devices_param); - while ((device_name = strsep(&device_names, ","))) { + device_tmp = device_names; + while ((device_name = strsep(&device_tmp, ","))) { ret = init_binder_device(device_name); if (ret) goto err_init_binder_device_failed; @@ -4277,6 +4278,9 @@ err_init_binder_device_failed: hlist_del(&device->hlist); kfree(device); } + + kfree(device_names); + err_alloc_device_names_failed: debugfs_remove_recursive(binder_debugfs_dir_entry_root);