[PATCH libICE 1/2] free() can handle NULL so remove the check
Eric Engestrom
eric.engestrom at imgtec.com
Tue Sep 12 08:58:57 UTC 2017
On Friday, 2017-09-08 19:59:17 +0200, walter harms wrote:
> free() can handle NULL so remove the check
Did you use a cocci script [1] to generate this?
If so, can you add it to the commit message?
Regardless, I double-checked it and it looks good to me:
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>
[1] perhaps something like this?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/free/ifnullfree.cocci
>
> Signed-off-by: Walter Harms <wharms at bfs.de>
> ---
> src/authutil.c | 24 ++++++++++++------------
> src/misc.c | 3 +--
> src/process.c | 41 +++++++++++++++--------------------------
> src/shutdown.c | 44 +++++++++++---------------------------------
> 4 files changed, 39 insertions(+), 73 deletions(-)
>
> diff --git a/src/authutil.c b/src/authutil.c
> index ca0504a..d7bcef9 100644
> --- a/src/authutil.c
> +++ b/src/authutil.c
> @@ -111,8 +111,8 @@ IceAuthFileName (void)
>
> if (size > bsize)
> {
> - if (buf)
> - free (buf);
> +
> + free (buf);
> buf = malloc (size);
> if (!buf) {
> bsize = 0;
> @@ -266,11 +266,11 @@ IceReadAuthFileEntry (
>
> bad:
>
> - if (local.protocol_name) free (local.protocol_name);
> - if (local.protocol_data) free (local.protocol_data);
> - if (local.network_id) free (local.network_id);
> - if (local.auth_name) free (local.auth_name);
> - if (local.auth_data) free (local.auth_data);
> + free (local.protocol_name);
> + free (local.protocol_data);
> + free (local.network_id);
> + free (local.auth_name);
> + free (local.auth_data);
>
> return (NULL);
> }
> @@ -284,11 +284,11 @@ IceFreeAuthFileEntry (
> {
> if (auth)
> {
> - if (auth->protocol_name) free (auth->protocol_name);
> - if (auth->protocol_data) free (auth->protocol_data);
> - if (auth->network_id) free (auth->network_id);
> - if (auth->auth_name) free (auth->auth_name);
> - if (auth->auth_data) free (auth->auth_data);
> + free (auth->protocol_name);
> + free (auth->protocol_data);
> + free (auth->network_id);
> + free (auth->auth_name);
> + free (auth->auth_data);
> free (auth);
> }
> }
> diff --git a/src/misc.c b/src/misc.c
> index d2e9150..87d6335 100644
> --- a/src/misc.c
> +++ b/src/misc.c
> @@ -54,8 +54,7 @@ IceAllocScratch (
> {
> if (!iceConn->scratch || size > iceConn->scratch_size)
> {
> - if (iceConn->scratch)
> - free (iceConn->scratch);
> + free (iceConn->scratch);
>
> iceConn->scratch = malloc (size);
> iceConn->scratch_size = size;
> diff --git a/src/process.c b/src/process.c
> index 4100a83..a9a8d08 100644
> --- a/src/process.c
> +++ b/src/process.c
> @@ -1026,8 +1026,7 @@ ProcessConnectionSetup (
> iceConn->connection_status = IceConnectRejected;
> }
>
> - if (hostname)
> - free (hostname);
> + free (hostname);
> }
>
> if (iceConn->connection_status == IceConnectRejected)
> @@ -1080,8 +1079,7 @@ ProcessConnectionSetup (
> if (authData && authDataLen > 0)
> free (authData);
>
> - if (errorString)
> - free (errorString);
> + free (errorString);
> }
>
> if (accept_setup_now)
> @@ -1369,8 +1367,7 @@ ProcessAuthReply (
> status = IcePaAuthAccepted;
> }
>
> - if (hostname)
> - free (hostname);
> + free (hostname);
> }
>
> if (status != IcePaAuthAccepted)
> @@ -1444,8 +1441,7 @@ ProcessAuthReply (
> status = IcePaAuthAccepted;
> }
>
> - if (hostname)
> - free (hostname);
> + free (hostname);
> }
>
> if (status == IcePaAuthRejected)
> @@ -1559,18 +1555,15 @@ ProcessAuthReply (
> _IceErrorSetupFailed (iceConn, ICE_ProtocolSetup,
> failureReason);
>
> - if (failureReason)
> - free (failureReason);
> + free (failureReason);
> }
> }
>
>
> if (free_setup_info)
> {
> - if (iceConn->protosetup_to_me->his_vendor)
> - free (iceConn->protosetup_to_me->his_vendor);
> - if (iceConn->protosetup_to_me->his_release)
> - free (iceConn->protosetup_to_me->his_release);
> + free (iceConn->protosetup_to_me->his_vendor);
> + free (iceConn->protosetup_to_me->his_release);
> free (iceConn->protosetup_to_me);
> iceConn->protosetup_to_me = NULL;
> }
> @@ -1587,8 +1580,8 @@ ProcessAuthReply (
> if (authData && authDataLen > 0)
> free (authData);
>
> - if (errorString)
> - free (errorString);
> +
> + free (errorString);
>
> IceDisposeCompleteMessage (iceConn, replyData);
> return (0);
> @@ -2071,8 +2064,7 @@ ProcessProtocolSetup (
> ICE_ProtocolSetup, "None of the authentication protocols specified are supported and host-based authentication failed");
> }
>
> - if (hostname)
> - free (hostname);
> + free (hostname);
> }
> }
> else
> @@ -2118,8 +2110,8 @@ ProcessProtocolSetup (
> if (authData && authDataLen > 0)
> free (authData);
>
> - if (errorString)
> - free (errorString);
> +
> + free (errorString);
> }
>
> if (accept_setup_now)
> @@ -2202,16 +2194,13 @@ ProcessProtocolSetup (
>
> _IceErrorSetupFailed (iceConn, ICE_ProtocolSetup, failureReason);
>
> - if (failureReason)
> - free (failureReason);
> + free (failureReason);
> }
> }
>
> - if (vendor)
> - free (vendor);
>
> - if (release)
> - free (release);
> + free (vendor);
> + free (release);
>
> if (hisAuthCount > 0)
> {
> diff --git a/src/shutdown.c b/src/shutdown.c
> index 5def0b4..90e9ded 100644
> --- a/src/shutdown.c
> +++ b/src/shutdown.c
> @@ -282,39 +282,17 @@ _IceFreeConnection (
> if (iceConn->trans_conn)
> _IceTransClose (iceConn->trans_conn);
>
> - if (iceConn->connection_string)
> - free (iceConn->connection_string);
> -
> - if (iceConn->vendor)
> - free (iceConn->vendor);
> -
> - if (iceConn->release)
> - free (iceConn->release);
> -
> - if (iceConn->inbuf)
> - free (iceConn->inbuf);
> -
> - if (iceConn->outbuf)
> - free (iceConn->outbuf);
> -
> - if (iceConn->scratch)
> - free (iceConn->scratch);
> -
> - if (iceConn->process_msg_info)
> - free (iceConn->process_msg_info);
> -
> - if (iceConn->connect_to_you)
> - free (iceConn->connect_to_you);
> -
> - if (iceConn->protosetup_to_you)
> - free (iceConn->protosetup_to_you);
> -
> - if (iceConn->connect_to_me)
> - free (iceConn->connect_to_me);
> -
> - if (iceConn->protosetup_to_me)
> - free (iceConn->protosetup_to_me);
> -
> + free (iceConn->connection_string);
> + free (iceConn->vendor);
> + free (iceConn->release);
> + free (iceConn->inbuf);
> + free (iceConn->outbuf);
> + free (iceConn->scratch);
> + free (iceConn->process_msg_info);
> + free (iceConn->connect_to_you);
> + free (iceConn->protosetup_to_you);
> + free (iceConn->connect_to_me);
> + free (iceConn->protosetup_to_me);
> free (iceConn);
> }
>
> --
> 2.1.4
>
More information about the xorg-devel
mailing list