From patchwork Fri Feb 24 14:27:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 9590457 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 EAF1060578 for ; Fri, 24 Feb 2017 14:28:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB05528756 for ; Fri, 24 Feb 2017 14:28:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFFB02876C; Fri, 24 Feb 2017 14:28:20 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 72F472875C for ; Fri, 24 Feb 2017 14:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751304AbdBXO2U (ORCPT ); Fri, 24 Feb 2017 09:28:20 -0500 Received: from hr2.samba.org ([144.76.82.148]:47303 "EHLO hr2.samba.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751296AbdBXO2T (ORCPT ); Fri, 24 Feb 2017 09:28:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42627210; h=Message-Id:Date:Cc:To:From; bh=fHMhgLH3bXqiYaSu1MHMnH/JSvK8KwEk/Wh+VQ7iD5I=; b=Nh+2Syx0Wzm3/MVkq/Ow51iPOt iRsyoPZbyZRldFqNbeANhw/U1G71+n+G216B/EzPelbKHr764CpJhp8kvRF80xOz+uevMpiw7mD1i 6rAdIVuAm9s7Dws5m4vZcb4K6R3cBew6fIl1+P425rQKfwhAZOSOkkhzhU8i0HP7Tee0=; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim) id 1chGr3-0000FM-7U; Fri, 24 Feb 2017 14:28:17 +0000 From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: cwseys@physics.wisc.edu, ssorce@redhat.com, samba-technical@lists.samba.org Subject: [cifs-utils PATCH 5/8] treewide: Eliminate SAFE_FREE Date: Fri, 24 Feb 2017 09:27:47 -0500 Message-Id: <20170224142750.4151-6-jlayton@samba.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170224142750.4151-1-jlayton@samba.org> References: <20170224142750.4151-1-jlayton@samba.org> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It just frees and then zeroes out the pointer. That's of dubious value in the places where it's currently being used. Just use free() instead. Signed-off-by: Jeff Layton --- cifs.upcall.c | 22 ++++++++++------------ mount.cifs.c | 16 +++++----------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/cifs.upcall.c b/cifs.upcall.c index cfc926cd9d09..15e1e0f91c22 100644 --- a/cifs.upcall.c +++ b/cifs.upcall.c @@ -82,8 +82,6 @@ typedef enum _sectype { #define KRB5_KEY_DATA_CAST krb5_octet #endif -#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x = NULL; } } while (0) - #ifdef HAVE_LIBCAP_NG static int trim_capabilities(bool need_environ) @@ -162,7 +160,7 @@ static char *cifs_krb5_principal_get_realm(krb5_principal principal) #if !defined(HAVE_KRB5_FREE_UNPARSED_NAME) static void krb5_free_unparsed_name(krb5_context context, char *val) { - SAFE_FREE(val); + free(val); } #endif @@ -650,7 +648,7 @@ decode_key_description(const char *desc, struct decoded_args *arg) len = pos - tkn; len -= 5; - SAFE_FREE(arg->hostname); + free(arg->hostname); arg->hostname = strndup(tkn + 5, len); if (arg->hostname == NULL) { syslog(LOG_ERR, "Unable to allocate memory"); @@ -665,7 +663,7 @@ decode_key_description(const char *desc, struct decoded_args *arg) len = pos - tkn; len -= 4; - SAFE_FREE(arg->ip); + free(arg->ip); arg->ip = strndup(tkn + 4, len); if (arg->ip == NULL) { syslog(LOG_ERR, "Unable to allocate memory"); @@ -680,7 +678,7 @@ decode_key_description(const char *desc, struct decoded_args *arg) len = pos - tkn; len -= 5; - SAFE_FREE(arg->username); + free(arg->username); arg->username = strndup(tkn + 5, len); if (arg->username == NULL) { syslog(LOG_ERR, "Unable to allocate memory"); @@ -968,7 +966,7 @@ int main(const int argc, char *const argv[]) } have = decode_key_description(buf, &arg); - SAFE_FREE(buf); + free(buf); if ((have & DKD_MUSTHAVE_SET) != DKD_MUSTHAVE_SET) { syslog(LOG_ERR, "unable to get necessary params from key " "description (0x%x)", have); @@ -1207,11 +1205,11 @@ out: krb5_cc_close(context, ccache); if (context) krb5_free_context(context); - SAFE_FREE(arg.hostname); - SAFE_FREE(arg.ip); - SAFE_FREE(arg.username); - SAFE_FREE(keydata); - SAFE_FREE(env_cachename); + free(arg.hostname); + free(arg.ip); + free(arg.username); + free(keydata); + free(env_cachename); syslog(LOG_DEBUG, "Exit status %ld", rc); return rc; } diff --git a/mount.cifs.c b/mount.cifs.c index b2bcb7f16b9f..13b71ef50303 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -61,6 +61,7 @@ #include "mount.h" #include "util.h" #include "resolve_host.h" +#include "data_blob.h" #ifndef MS_MOVE #define MS_MOVE 8192 @@ -101,13 +102,6 @@ /* Max password size. */ #define MOUNT_PASSWD_SIZE 512 - - -#ifndef SAFE_FREE -#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x = NULL; } } while (0) -#endif - - /* * mount.cifs has been the subject of many "security" bugs that have arisen * because of users and distributions installing it as a setuid root program @@ -621,7 +615,7 @@ return_i: /* make sure passwords are scrubbed from memory */ if (line_buf != NULL) memset(line_buf, 0, line_buf_size); - SAFE_FREE(line_buf); + free(line_buf); return i; } @@ -1516,7 +1510,7 @@ add_mtab(char *devname, char *mountpoint, unsigned long flags, const char *fstyp rc = EX_FILEIO; } unlock_mtab(); - SAFE_FREE(mountent.mnt_opts); + free(mountent.mnt_opts); add_mtab_exit: toggle_dac_capability(1, 0); sigprocmask(SIG_SETMASK, &oldmask, NULL); @@ -2152,7 +2146,7 @@ mount_exit: memset(parsed_info->password, 0, sizeof(parsed_info->password)); munmap(parsed_info, sizeof(*parsed_info)); } - SAFE_FREE(options); - SAFE_FREE(orgoptions); + free(options); + free(orgoptions); return rc; }