From cfbc55d15ae84e43e5c5b71b5ecde2555f1b1ac8 Mon Sep 17 00:00:00 2001
From: "Alfred M. Szmidt" <ams@gnu.org>
Date: Mon, 10 Jul 2017 20:14:58 +0000
Subject: [PATCH 26/60] src/hostname.c (parse_file): Free name and allocate one
 extra byte for it.

---
 ChangeLog      | 5 +++++
 src/hostname.c | 6 ++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 289a6e9f..64e8dad8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-10  Omer Anson <oaanson@gmail.com>  (tiny change)
+
+	* src/hostname.c (parse_file): Free name and allocate one extra
+	byte for it.
+
 2017-07-10  Omer Anson <oaanson@gmail.com>  (tiny change)
 
 	* src/hostname.c (set_name): Handle case when hostname_new is
diff --git a/src/hostname.c b/src/hostname.c
index d1f584f8..e340f8fd 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -410,9 +410,11 @@ parse_file (const char *const file_name)
 
       if (buffer[0] != '#')
         {
-	  name = (char *) xmalloc (sizeof (char) * nread);
-	  if (sscanf (buffer, "%s", name)  == 1)
+	  name = (char *) xmalloc (sizeof (char) * (nread + 1));
+	  if (sscanf (buffer, "%s", name) == 1)
 	    break;
+	  free (name);
+	  name = NULL;
         }
     }
   while (feof (file) == 0);
-- 
2.26.0.292.g33ef6b2f38

