From patchwork Sun Jan 15 15:38:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9517581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3ADE460132 for ; Sun, 15 Jan 2017 15:38:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C79428387 for ; Sun, 15 Jan 2017 15:38:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EFF1283AC; Sun, 15 Jan 2017 15:38:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C434728387 for ; Sun, 15 Jan 2017 15:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751218AbdAOPii (ORCPT ); Sun, 15 Jan 2017 10:38:38 -0500 Received: from mout.web.de ([212.227.15.4]:53813 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdAOPih (ORCPT ); Sun, 15 Jan 2017 10:38:37 -0500 Received: from [192.168.1.2] ([78.49.147.199]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MTLwF-1c2l8b249v-00SRmG; Sun, 15 Jan 2017 16:38:14 +0100 Subject: [PATCH 38/46] selinux: One function call less in five functions after null pointer detection To: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris , James Morris , Paul Moore , "Serge E. Hallyn" , Stephen Smalley , William Roberts References: Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: Date: Sun, 15 Jan 2017 16:38:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:nniNs84UlkkixdzNUajX6T7KxJPy0S5cKHOJpFIsij0NjSdcTsD nmxwi89/A19KefgqQUTlvjMH5HKSFDPZYnhK1/7GRObsyCok8Cq3vGgqn04InP4RoioTaHR IvpsYbJRaiqhWWU1VPAo5m13IVPBqD7U9Me9IiWV55pkw4OOKHQJlZJ0lcuEGFhvlb3BB6m GWfq+k29yuH0jwj9a/0BA== X-UI-Out-Filterresults: notjunk:1; V01:K0:rbgthq7W2Mk=:DWuM1rvLY8EJSu5Gn2wWfv NuVAdIKSTb3KKmAmnjA2aXf8HLdx1ntQz0qSQRDLOcDIa8B/NEFWiNYUeEIYTKuDs+uLUivsW TAmVa3lSWIcol4QRxLJOE49p7MFUBDcuVZGEkAqMmfuPOlnlAp5dTeIDXUKKZkUUHf/bkPhZb xs+nCd9uXLYqC2prcYXtea7LTI0ho6giUQ3UK/bB8UTQJkoH4+Hl3bjTgDZtWcX193JSxSxtR yeXY6JcBe4dLGqtLVM1VxCWwWZXki3PsAlJQ0gAMBnyiAwbHIcTUu1eQ90mGzReAmQfMTfEUS HMPbEN+w3R51gKQlY7UUHmMf3QJhpVBYBaD+cBtN1JQyrV4zeVV37EKWgajq76FrTvX70CWeh z3NtFOAmQTStl/nlJo0Bt+BG+Lc49JQAAoE0Y/Gj1/PmMgLqVgZazVUh0B9CBhXWHr0qajH7y JgnBioPk6Qw2N3qsLmIq3coLn9dFE6n1/H+nlZpS/lewsVYVTO9obhJ5v8V+IZ5o431YaNZOd DNOEzpURFUxoLrqpPw/PqRwJ0QIXiYD71h718ZT86Zz//qjM8+1YwGfpvDM+MmEtZ7mrF5xdA HYsA8aFE0gTnS4w5LP5KOmHznGXkdCpG1uHEjHXnwGv5fS4C238kJq5E0QBbMwNBNXkQpaOQD JwVS4ShbiWuf95OMb2QQi9BbMsur45iZBpQKxxcyLqwQZ4sYfPB9SK0okMz0s1ElMCQS6TIHp CkYtVYTMI4MS2+3lxd/Nw+UfHcEvQVzLs3yIsSOkbKwH+xMuhK3LYf7U4x4W+zvNuQY4YI90I 1AkfNaN Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 15 Jan 2017 11:28:02 +0100 Call the function "kfree" at the end only after it was determined that the passed parameter contained a non-null pointer. Signed-off-by: Markus Elfring --- security/selinux/ss/policydb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index faa6ecc2450d..88730b372277 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -620,8 +620,8 @@ static int common_destroy(void *key, void *datum, void *p) comdatum = datum; hashtab_map(comdatum->permissions.table, perm_destroy, NULL); hashtab_destroy(comdatum->permissions.table); + kfree(datum); } - kfree(datum); return 0; } @@ -675,8 +675,8 @@ static int cls_destroy(void *key, void *datum, void *p) kfree(ctemp); } kfree(cladatum->comkey); + kfree(datum); } - kfree(datum); return 0; } @@ -689,8 +689,8 @@ static int role_destroy(void *key, void *datum, void *p) role = datum; ebitmap_destroy(&role->dominates); ebitmap_destroy(&role->types); + kfree(datum); } - kfree(datum); return 0; } @@ -712,8 +712,8 @@ static int user_destroy(void *key, void *datum, void *p) ebitmap_destroy(&usrdatum->range.level[0].cat); ebitmap_destroy(&usrdatum->range.level[1].cat); ebitmap_destroy(&usrdatum->dfltlevel.cat); + kfree(datum); } - kfree(datum); return 0; } @@ -726,8 +726,8 @@ static int sens_destroy(void *key, void *datum, void *p) levdatum = datum; ebitmap_destroy(&levdatum->level->cat); kfree(levdatum->level); + kfree(datum); } - kfree(datum); return 0; }