public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Fix memory leak in _dl_find_object_update (bug 29062)
@ 2022-04-13 13:01 Florian Weimer
  2022-04-13 13:11 ` Andreas Schwab
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Weimer @ 2022-04-13 13:01 UTC (permalink / raw)
  To: libc-alpha

The count can be zero if an object has already been loaded as
an indirect dependency (so that l_searchlist.r_list in its link
map is still NULL) is promoted to global scope via RTLD_GLOBAL.

Fixes commit 5d28a8962dc ("elf: Add _dl_find_object function").

---
 elf/dl-find_object.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/elf/dl-find_object.c b/elf/dl-find_object.c
index 2b8df2fd67..4d5831b6f4 100644
--- a/elf/dl-find_object.c
+++ b/elf/dl-find_object.c
@@ -788,6 +788,9 @@ _dl_find_object_update (struct link_map *new_map)
   for (struct link_map *l = new_map; l != NULL; l = l->l_next)
     /* Skip proxy maps and already-processed maps.  */
     count += l == l->l_real && !l->l_find_object_processed;
+  if (count == 0)
+    return true;
+
   struct link_map **map_array = malloc (count * sizeof (*map_array));
   if (map_array == NULL)
     return false;
@@ -797,8 +800,6 @@ _dl_find_object_update (struct link_map *new_map)
       if (l == l->l_real && !l->l_find_object_processed)
         map_array[i++] = l;
   }
-  if (count == 0)
-    return true;
 
   _dl_find_object_link_map_sort (map_array, count);
   bool ok = _dl_find_object_update_1 (map_array, count);


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] elf: Fix memory leak in _dl_find_object_update (bug 29062)
  2022-04-13 13:01 [PATCH] elf: Fix memory leak in _dl_find_object_update (bug 29062) Florian Weimer
@ 2022-04-13 13:11 ` Andreas Schwab
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2022-04-13 13:11 UTC (permalink / raw)
  To: Florian Weimer via Libc-alpha; +Cc: Florian Weimer

On Apr 13 2022, Florian Weimer via Libc-alpha wrote:

> The count can be zero if an object has already been loaded as
> an indirect dependency (so that l_searchlist.r_list in its link
> map is still NULL) is promoted to global scope via RTLD_GLOBAL.
>
> Fixes commit 5d28a8962dc ("elf: Add _dl_find_object function").

Ok.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-13 13:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 13:01 [PATCH] elf: Fix memory leak in _dl_find_object_update (bug 29062) Florian Weimer
2022-04-13 13:11 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).