poke-devel
[Top][All Lists]
Advanced

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

[PATCH] Fix memory leaks and check for failure when calling .file


From: John Darrington
Subject: [PATCH] Fix memory leaks and check for failure when calling .file
Date: Sat, 21 Dec 2019 18:11:54 +0100

---
 ChangeLog     |  5 +++++
 src/pk-file.c | 11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 7fd81a1..346593b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-21 John Darrington <address@hidden>
+
+       * src/pk-file.c (pk_cmd_file): Fix memory leaks and
+       check for failures on opening file.
+
 2019-12-16  Dan Čermák  <address@hidden>
 
        * src/pk-repl.c (pk_repl): fix memory leak of poke_history
diff --git a/src/pk-file.c b/src/pk-file.c
index caf6842..195bb00 100644
--- a/src/pk-file.c
+++ b/src/pk-file.c
@@ -111,6 +111,7 @@ pk_cmd_file (int argc, struct pk_cmd_arg argv[], uint64_t 
uflags)
         {
           char *why = strerror (errno);
           pk_printf (_("%s: file cannot be read: %s\n"), arg_str, why);
+         free (filename);
           return 0;
         }
 
@@ -121,10 +122,18 @@ pk_cmd_file (int argc, struct pk_cmd_arg argv[], uint64_t 
uflags)
         {
           printf (_("File %s already opened.  Use `file #N' to switch.\n"),
                   filename);
+         free (filename);
           return 0;
         }
 
-      ios_open (filename);
+      errno = 0;
+      if (IOS_ERROR == ios_open (filename))
+       {
+         pk_printf (_("Error opening %s: %s\n"), filename,
+                    strerror (errno));
+         free (filename);
+         return 0;
+       }
       free (filename);
     }
 
-- 
2.11.0




reply via email to

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