public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Get rid of alloca usage in _dl_start_profile
@ 2023-09-29 13:52 Joe Simmons-Talbott
  2023-10-03 19:33 ` Joe Simmons-Talbott
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Simmons-Talbott @ 2023-09-29 13:52 UTC (permalink / raw)
  To: libc-alpha; +Cc: Joe Simmons-Talbott

Replace alloca usage with a scratch_buffer.
---
 elf/dl-profile.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/elf/dl-profile.c b/elf/dl-profile.c
index 8be0065fbd..8ae50020bb 100644
--- a/elf/dl-profile.c
+++ b/elf/dl-profile.c
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <scratch_buffer.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -201,6 +202,8 @@ _dl_start_profile (void)
   int s_scale;
 #define SCALE_1_TO_1	0x10000L
   const char *errstr = NULL;
+  struct scratch_buffer sbuf;
+  scratch_buffer_init (&sbuf);
 
   /* Compute the size of the sections which contain program code.  */
   for (ph = GL(dl_profile_map)->l_phdr;
@@ -318,8 +321,14 @@ _dl_start_profile (void)
   /* First determine the output name.  We write in the directory
      OUTPUT_DIR and the name is composed from the shared objects
      soname (or the file name) and the ending ".profile".  */
-  filename = (char *) alloca (strlen (GLRO(dl_profile_output)) + 1
-			      + strlen (GLRO(dl_profile)) + sizeof ".profile");
+  size_t filename_len = (strlen (GLRO(dl_profile_output)) + 1
+	+ strlen (GLRO(dl_profile)) + sizeof ".profile");
+  if (!scratch_buffer_set_array_size (&sbuf, 1, filename_len))
+    {
+      _dl_error_printf ("failed to allocate memory");
+      return;
+    }
+  filename = sbuf.data;
   cp = __stpcpy (filename, GLRO(dl_profile_output));
   *cp++ = '/';
   __stpcpy (__stpcpy (cp, GLRO(dl_profile)), ".profile");
@@ -339,6 +348,7 @@ _dl_start_profile (void)
 	__close_nocancel (fd);
       _dl_error_printf (errstr, filename,
 			__strerror_r (errnum, buf, sizeof buf));
+      scratch_buffer_free (&sbuf);
       return;
     }
 
@@ -380,6 +390,7 @@ _dl_start_profile (void)
 
       _dl_error_printf ("%s: file is no correct profile data file for `%s'\n",
 			filename, GLRO(dl_profile));
+      scratch_buffer_free (&sbuf);
       return;
     }
 
@@ -483,6 +494,8 @@ _dl_start_profile (void)
 
   /* Turn on profiling.  */
   running = 1;
+
+  scratch_buffer_free (&sbuf);
 }
 
 
-- 
2.39.2


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

end of thread, other threads:[~2023-10-31 20:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-29 13:52 [PATCH] elf: Get rid of alloca usage in _dl_start_profile Joe Simmons-Talbott
2023-10-03 19:33 ` Joe Simmons-Talbott
2023-10-10 19:05   ` Joe Simmons-Talbott
2023-10-30 12:24     ` Joe Simmons-Talbott
2023-10-30 12:44   ` Andreas Schwab
2023-10-31 20:17     ` Joe Simmons-Talbott

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).