poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/4] ios: Remove usage of xalloc from ios-dev-file.c


From: Tim Rühsen
Subject: Re: [PATCH 1/4] ios: Remove usage of xalloc from ios-dev-file.c
Date: Fri, 15 May 2020 11:23:32 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

Patchset amended regarding the comments and pushed.

On 14.05.20 20:13, Tim Rühsen wrote:
> 2020-05-07  Tim Rühsen  <address@hidden>
> 
>         * libpoke/ios-dev-file.c (ios_dev_file_open): Replace
>         xmalloc and xstrdup by malloc and strdup.
>         Remove include xalloc.h.
> ---
>  ChangeLog              |  6 ++++++
>  libpoke/ios-dev-file.c | 33 ++++++++++++++++++++++++---------
>  2 files changed, 30 insertions(+), 9 deletions(-)
> 
> diff --git a/libpoke/ios-dev-file.c b/libpoke/ios-dev-file.c
> index 14b6ba0a..fb42ed4f 100644
> --- a/libpoke/ios-dev-file.c
> +++ b/libpoke/ios-dev-file.c
> @@ -25,7 +25,6 @@
> 
>  #include <fcntl.h>
>  #include <stdio.h>
> -#include <xalloc.h>
>  #include <string.h>
>  #include <sys/stat.h>
> 
> @@ -66,7 +65,7 @@ ios_dev_file_handler_normalize (const char *handler)
>  static void *
>  ios_dev_file_open (const char *handler, uint64_t flags, int *error)
>  {
> -  struct ios_dev_file *fio;
> +  struct ios_dev_file *fio = NULL;
>    FILE *f;
>    const char *mode;
>    uint8_t flags_mode = flags & IOS_FLAGS_MODE;
> @@ -106,19 +105,35 @@ ios_dev_file_open (const char *handler, uint64_t flags, 
> int *error)
>      }
> 
>    if (!f)
> -    {
> -      if (error != NULL)
> -        *error = IOD_ERROR;
> +    goto err;
> 
> -      return NULL;
> -    }
> +  fio = malloc (sizeof (struct ios_dev_file));
> +  if (!fio)
> +    goto err;
> +
> +  fio->filename = strdup (handler);
> +  if (!fio->filename)
> +    goto err;
> 
> -  fio = xmalloc (sizeof (struct ios_dev_file));
>    fio->file = f;
> -  fio->filename = xstrdup (handler);
>    fio->flags = flags;
> 
>    return fio;
> +
> +err:
> +  if (fio)
> +    {
> +      free (fio->filename);
> +      free (fio);
> +    }
> +
> +  if (f)
> +    fclose (f);
> +
> +  if (error != NULL)
> +    *error = IOD_ERROR;
> +
> +  return NULL;
>  }
> 
>  static int
> --
> 2.26.2
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]