mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-15 22:00:47 +08:00
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:
31
ld/ldlang.c
31
ld/ldlang.c
@@ -188,6 +188,12 @@ stat_alloc (size_t size)
|
|||||||
return obstack_alloc (&stat_obstack, size);
|
return obstack_alloc (&stat_obstack, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
stat_free (void *str)
|
||||||
|
{
|
||||||
|
obstack_free (&stat_obstack, str);
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
stat_memdup (const void *src, size_t copy_size, size_t alloc_size)
|
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);
|
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,
|
/* Code for handling simple wildcards without going through fnmatch,
|
||||||
which can be expensive because of charset translations etc. */
|
which can be expensive because of charset translations etc. */
|
||||||
|
|
||||||
|
|||||||
@@ -664,10 +664,14 @@ extern void lang_for_each_statement_worker
|
|||||||
(void (*) (lang_statement_union_type *), lang_statement_union_type *);
|
(void (*) (lang_statement_union_type *), lang_statement_union_type *);
|
||||||
extern void *stat_alloc
|
extern void *stat_alloc
|
||||||
(size_t);
|
(size_t);
|
||||||
|
extern void stat_free
|
||||||
|
(void *);
|
||||||
extern void *stat_memdup
|
extern void *stat_memdup
|
||||||
(const void *, size_t, size_t);
|
(const void *, size_t, size_t);
|
||||||
extern char *stat_strdup
|
extern char *stat_strdup
|
||||||
(const char *);
|
(const char *);
|
||||||
|
extern char *stat_concat
|
||||||
|
(const char *, ...);
|
||||||
extern void strip_excluded_output_sections
|
extern void strip_excluded_output_sections
|
||||||
(void);
|
(void);
|
||||||
extern void lang_clear_os_map
|
extern void lang_clear_os_map
|
||||||
|
|||||||
@@ -366,7 +366,8 @@ asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
|
|||||||
|
|
||||||
asym->the_bfd = abfd;
|
asym->the_bfd = abfd;
|
||||||
asym->name = (ldsym->version
|
asym->name = (ldsym->version
|
||||||
? concat (ldsym->name, "@", ldsym->version, (const char *) NULL)
|
? stat_concat (ldsym->name, "@", ldsym->version,
|
||||||
|
(const char *) NULL)
|
||||||
: ldsym->name);
|
: ldsym->name);
|
||||||
asym->value = 0;
|
asym->value = 0;
|
||||||
switch (ldsym->def)
|
switch (ldsym->def)
|
||||||
@@ -378,11 +379,11 @@ asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
|
|||||||
flags |= BSF_GLOBAL;
|
flags |= BSF_GLOBAL;
|
||||||
if (ldsym->comdat_key)
|
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);
|
(const char *) NULL);
|
||||||
section = bfd_get_section_by_name (abfd, name);
|
section = bfd_get_section_by_name (abfd, name);
|
||||||
if (section != NULL)
|
if (section != NULL)
|
||||||
free (name);
|
stat_free (name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
flagword sflags;
|
flagword sflags;
|
||||||
|
|||||||
Reference in New Issue
Block a user