poke-devel
[Top][All Lists]
Advanced

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

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


From: Tim Rühsen
Subject: [PATCH 1/4] ios: Remove usage of xalloc from ios-dev-file.c
Date: Thu, 14 May 2020 20:13:28 +0200

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




reply via email to

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