e354a5
commit 5e598c2bbf938eac0f4045f5143f9dd723646672
e354a5
Author: Florian Weimer <fweimer@redhat.com>
e354a5
Date:   Fri Oct 30 18:40:28 2020 +0100
e354a5
e354a5
    elf: In ldconfig, extract the new_sub_entry function from search_dir
e354a5
    
e354a5
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
e354a5
e354a5
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
e354a5
index 7c8fd29387463a8a..be730ceb075f6c1f 100644
e354a5
--- a/elf/ldconfig.c
e354a5
+++ b/elf/ldconfig.c
e354a5
@@ -328,6 +328,23 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
e354a5
 	   "Andreas Jaeger");
e354a5
 }
e354a5
 
e354a5
+/* Allocate a new subdirectory with full path PATH under ENTRY, using
e354a5
+   inode data from *ST.  */
e354a5
+static struct dir_entry *
e354a5
+new_sub_entry (const struct dir_entry *entry, const char *path,
e354a5
+	       const struct stat64 *st)
e354a5
+{
e354a5
+  struct dir_entry *new_entry = xmalloc (sizeof (struct dir_entry));
e354a5
+  new_entry->from_file = entry->from_file;
e354a5
+  new_entry->from_line = entry->from_line;
e354a5
+  new_entry->path = xstrdup (path);
e354a5
+  new_entry->flag = entry->flag;
e354a5
+  new_entry->next = NULL;
e354a5
+  new_entry->ino = st->st_ino;
e354a5
+  new_entry->dev = st->st_dev;
e354a5
+  return new_entry;
e354a5
+}
e354a5
+
e354a5
 /* Add a single directory entry.  */
e354a5
 static void
e354a5
 add_single_dir (struct dir_entry *entry, int verbose)
e354a5
@@ -823,26 +840,17 @@ search_dir (const struct dir_entry *entry)
e354a5
 
e354a5
       if (is_dir && is_hwcap_platform (direntry->d_name))
e354a5
 	{
e354a5
-	  /* Handle subdirectory later.  */
e354a5
-	  struct dir_entry *new_entry;
e354a5
-
e354a5
-	  new_entry = xmalloc (sizeof (struct dir_entry));
e354a5
-	  new_entry->from_file = entry->from_file;
e354a5
-	  new_entry->from_line = entry->from_line;
e354a5
-	  new_entry->path = xstrdup (file_name);
e354a5
-	  new_entry->flag = entry->flag;
e354a5
-	  new_entry->next = NULL;
e354a5
 	  if (!is_link
e354a5
 	      && direntry->d_type != DT_UNKNOWN
e354a5
 	      && __builtin_expect (lstat64 (real_file_name, &lstat_buf), 0))
e354a5
 	    {
e354a5
 	      error (0, errno, _("Cannot lstat %s"), file_name);
e354a5
-	      free (new_entry->path);
e354a5
-	      free (new_entry);
e354a5
 	      continue;
e354a5
 	    }
e354a5
-	  new_entry->ino = lstat_buf.st_ino;
e354a5
-	  new_entry->dev = lstat_buf.st_dev;
e354a5
+
e354a5
+	  /* Handle subdirectory later.  */
e354a5
+	  struct dir_entry *new_entry = new_sub_entry (entry, file_name,
e354a5
+						       &lstat_buf);
e354a5
 	  add_single_dir (new_entry, 0);
e354a5
 	  continue;
e354a5
 	}