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