ld plugin.c concat leaks

* ldlang.c: Whitespace.
	(stat_free, stat_concat): New functions.
	* ldlang.h (stat_free, stat_concat): Declare.
	* plugin.c (asymbol_from_plugin_symbol): Use stat_concat.
This commit is contained in:
Alan Modra
2025-01-23 10:22:58 +10:30
parent 40c7f80788
commit 90bea4932e
3 changed files with 74 additions and 38 deletions

View File

@@ -188,6 +188,12 @@ stat_alloc (size_t size)
return obstack_alloc (&stat_obstack, size);
}
void
stat_free (void *str)
{
obstack_free (&stat_obstack, str);
}
void *
stat_memdup (const void *src, size_t copy_size, size_t alloc_size)
{
@@ -205,6 +211,31 @@ stat_strdup (const char *str)
return stat_memdup (str, len, len);
}
char *
stat_concat (const char *first, ...)
{
va_list args;
va_start (args, first);
size_t length = 0;
for (const char *arg = first; arg; arg = va_arg (args, const char *))
length += strlen (arg);
va_end (args);
char *new_str = stat_alloc (length + 1);
va_start (args, first);
char *end = new_str;
for (const char *arg = first; arg; arg = va_arg (args, const char *))
{
length = strlen (arg);
memcpy (end, arg, length);
end += length;
}
*end = 0;
va_end (args);
return new_str;
}
/* Code for handling simple wildcards without going through fnmatch,
which can be expensive because of charset translations etc. */

View File

@@ -664,10 +664,14 @@ extern void lang_for_each_statement_worker
(void (*) (lang_statement_union_type *), lang_statement_union_type *);
extern void *stat_alloc
(size_t);
extern void stat_free
(void *);
extern void *stat_memdup
(const void *, size_t, size_t);
extern char *stat_strdup
(const char *);
extern char *stat_concat
(const char *, ...);
extern void strip_excluded_output_sections
(void);
extern void lang_clear_os_map

View File

@@ -366,7 +366,8 @@ asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
asym->the_bfd = abfd;
asym->name = (ldsym->version
? concat (ldsym->name, "@", ldsym->version, (const char *) NULL)
? stat_concat (ldsym->name, "@", ldsym->version,
(const char *) NULL)
: ldsym->name);
asym->value = 0;
switch (ldsym->def)
@@ -378,11 +379,11 @@ asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
flags |= BSF_GLOBAL;
if (ldsym->comdat_key)
{
char *name = concat (".gnu.linkonce.t.", ldsym->comdat_key,
char *name = stat_concat (".gnu.linkonce.t.", ldsym->comdat_key,
(const char *) NULL);
section = bfd_get_section_by_name (abfd, name);
if (section != NULL)
free (name);
stat_free (name);
else
{
flagword sflags;