sect_flag_list: NAME
{
struct flag_info_list *n;
- n = ((struct flag_info_list *) xmalloc (sizeof *n));
+ n = stat_alloc (sizeof *n);
if ($1[0] == '!')
{
n->with = without_flags;
| sect_flag_list '&' NAME
{
struct flag_info_list *n;
- n = ((struct flag_info_list *) xmalloc (sizeof *n));
+ n = stat_alloc (sizeof *n);
if ($3[0] == '!')
{
n->with = without_flags;
INPUT_SECTION_FLAGS '(' sect_flag_list ')'
{
struct flag_info *n;
- n = ((struct flag_info *) xmalloc (sizeof *n));
+ n = stat_alloc (sizeof *n);
n->flag_list = $3;
n->flags_initialized = false;
n->not_with_flags = 0;
exclude_name_list wildcard_name
{
struct name_list *tmp;
- tmp = (struct name_list *) xmalloc (sizeof *tmp);
+ tmp = stat_alloc (sizeof *tmp);
tmp->name = $2;
tmp->next = $1;
$$ = tmp;
wildcard_name
{
struct name_list *tmp;
- tmp = (struct name_list *) xmalloc (sizeof *tmp);
+ tmp = stat_alloc (sizeof *tmp);
tmp->name = $1;
tmp->next = NULL;
$$ = tmp;
section_name_list opt_comma section_name_spec
{
struct wildcard_list *tmp;
- tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
+ tmp = stat_alloc (sizeof *tmp);
tmp->next = $1;
tmp->spec = $3;
$$ = tmp;
section_name_spec
{
struct wildcard_list *tmp;
- tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
+ tmp = stat_alloc (sizeof *tmp);
tmp->next = NULL;
tmp->spec = $1;
$$ = tmp;
{
struct lang_nocrossref *n;
- n = (struct lang_nocrossref *) xmalloc (sizeof *n);
+ n = stat_alloc (sizeof *n);
n->name = $1;
n->next = $2;
$$ = n;
{
struct lang_nocrossref *n;
- n = (struct lang_nocrossref *) xmalloc (sizeof *n);
+ n = stat_alloc (sizeof *n);
n->name = $1;
n->next = $3;
$$ = n;
{
struct lang_output_section_phdr_list *n;
- n = ((struct lang_output_section_phdr_list *)
- xmalloc (sizeof *n));
+ n = stat_alloc (sizeof *n);
n->name = $3;
n->used = false;
n->next = $1;
return obstack_alloc (&stat_obstack, size);
}
+void *
+stat_memdup (const void *src, size_t copy_size, size_t alloc_size)
+{
+ void *ret = obstack_alloc (&stat_obstack, alloc_size);
+ memcpy (ret, src, copy_size);
+ if (alloc_size > copy_size)
+ memset ((char *) ret + copy_size, 0, alloc_size - copy_size);
+ return ret;
+}
+
+char *
+stat_strdup (const char *str)
+{
+ size_t len = strlen (str) + 1;
+ return stat_memdup (str, len, len);
+}
+
/* Code for handling simple wildcards without going through fnmatch,
which can be expensive because of charset translations etc. */
ldirname (const char *name)
{
const char *base = lbasename (name);
- char *dirname;
while (base > name && IS_DIR_SEPARATOR (base[-1]))
--base;
- if (base == name)
- return strdup (".");
- dirname = strdup (name);
- dirname[base - name] = '\0';
- return dirname;
+ size_t len = base - name;
+ if (len == 0)
+ return ".";
+ return stat_memdup (name, len, len + 1);
}
/* If PATTERN is of the form archive:file, return a pointer to the
if (wont_add_section_p (section, os))
return;
- node = (lang_section_bst_type *) xmalloc (sizeof (lang_section_bst_type));
+ node = stat_alloc (sizeof (*node));
node->left = 0;
node->right = 0;
node->section = section;
if (tree->right)
output_section_callback_tree_to_list (ptr, tree->right, output);
-
- free (tree);
}
\f
new_region = stat_alloc (sizeof (lang_memory_region_type));
- new_region->name_list.name = xstrdup (name);
+ new_region->name_list.name = stat_strdup (name);
new_region->name_list.next = NULL;
new_region->next = NULL;
new_region->origin_exp = NULL;
/* Add alias to region name list. */
n = stat_alloc (sizeof (lang_memory_region_name));
- n->name = xstrdup (alias);
+ n->name = stat_strdup (alias);
n->next = region->name_list.next;
region->name_list.next = n;
}
end = strpbrk (p, ",:");
if (end == NULL)
end = p + strlen (p);
- entry = (struct excluded_lib *) xmalloc (sizeof (*entry));
+ entry = stat_alloc (sizeof (*entry));
entry->next = excluded_libs;
- entry->name = (char *) xmalloc (end - p + 1);
- memcpy (entry->name, p, end - p);
- entry->name[end - p] = '\0';
+ entry->name = stat_memdup (p, end - p, end - p + 1);
excluded_libs = entry;
if (*end == '\0')
break;
new_undef->next = ldlang_undef_chain_list_head;
ldlang_undef_chain_list_head = new_undef;
- new_undef->name = xstrdup (name);
+ new_undef->name = stat_strdup (name);
if (link_info.output_bfd != NULL)
insert_undefined (new_undef->name);
ldlang_add_undef (name, true);
ptr = stat_alloc (sizeof (*ptr));
ptr->next = require_defined_symbol_list;
- ptr->name = strdup (name);
+ ptr->name = stat_strdup (name);
require_defined_symbol_list = ptr;
}
{
struct lang_nocrossrefs *n;
- n = (struct lang_nocrossrefs *) xmalloc (sizeof *n);
+ n = stat_alloc (sizeof *n);
n->next = nocrossref_list;
n->list = l;
n->onlyfirst = false;
{
lang_nocrossref_type *nc;
- nc = (lang_nocrossref_type *) xmalloc (sizeof *nc);
+ nc = stat_alloc (sizeof *nc);
nc->name = l->os->name;
nc->next = nocrossref;
nocrossref = nc;
if (changed)
{
*s = '\0';
- return symbol;
- }
- else
- {
- free (symbol);
- return pattern;
+ pattern = stat_strdup (symbol);
}
+ free (symbol);
+ return pattern;
}
/* This is called for each variable name or match expression. NEW_NAME is
{
struct bfd_elf_version_expr *ret;
- ret = (struct bfd_elf_version_expr *) xmalloc (sizeof *ret);
+ ret = stat_alloc (sizeof *ret);
ret->next = orig;
ret->symver = 0;
ret->script = 0;
{
struct bfd_elf_version_tree *ret;
- ret = (struct bfd_elf_version_tree *) xcalloc (1, sizeof *ret);
+ ret = stat_alloc (sizeof (*ret));
+ memset (ret, 0, sizeof (*ret));
ret->globals.list = globals;
ret->locals.list = locals;
ret->match = lang_vers_match;
}
while (e1 && strcmp (e1->pattern, e->pattern) == 0);
- if (last == NULL)
- {
- /* This is a duplicate. */
- /* FIXME: Memory leak. Sometimes pattern is not
- xmalloced alone, but in larger chunk of memory. */
- /* free (e->pattern); */
- free (e);
- }
- else
+ if (last != NULL)
{
e->next = last->next;
last->next = e;
{
einfo (_("%X%P: anonymous version tag cannot be combined"
" with other version tags\n"));
- free (version);
return;
}
struct bfd_elf_version_deps *ret;
struct bfd_elf_version_tree *t;
- ret = (struct bfd_elf_version_deps *) xmalloc (sizeof *ret);
+ ret = stat_alloc (sizeof *ret);
ret->next = list;
for (t = link_info.version_info; t != NULL; t = t->next)
continue;
len = sec->size;
- contents = (char *) xmalloc (len);
+ contents = stat_alloc (len);
if (!bfd_get_section_contents (is->the_bfd, sec, contents, 0, len))
einfo (_("%X%P: unable to read .exports section contents\n"), sec);
p = strchr (p, '\0') + 1;
}
- /* Do not free the contents, as we used them creating the regex. */
-
/* Do not include this section in the link. */
sec->flags |= SEC_EXCLUDE | SEC_KEEP;
}
if (strcmp (ent->name, name) == 0)
return;
- ent = (struct unique_sections *) xmalloc (sizeof *ent);
- ent->name = xstrdup (name);
+ ent = stat_alloc (sizeof *ent);
+ ent->name = stat_strdup (name);
ent->next = unique_section_list;
unique_section_list = ent;
}
{
struct bfd_elf_dynamic_list *d;
- d = (struct bfd_elf_dynamic_list *) xcalloc (1, sizeof *d);
+ d = stat_alloc (sizeof (*d));
+ memset (d, 0, sizeof (*d));
d->head.list = dynamic;
d->match = lang_vers_match;
*list_p = d;
&& (yytext[1] == 'x'
|| yytext[1] == 'X'))
{
- yylval.bigint.str = xstrdup (yytext + 2);
+ yylval.bigint.str
+ = stat_strdup (yytext + 2);
}
return INT;
}
<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
/* Filename without commas, needed to parse mri stuff */
- yylval.name = xstrdup (yytext);
+ yylval.name = stat_strdup (yytext);
return NAME;
}
<SCRIPT,INPUTLIST>{FILENAMECHAR1}{FILENAMECHAR}* {
- yylval.name = xstrdup (yytext);
+ yylval.name = stat_strdup (yytext);
return NAME;
}
<INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}* {
/* Filename to be prefixed by --sysroot or when non-sysrooted, nothing. */
- yylval.name = xstrdup (yytext);
+ yylval.name = stat_strdup (yytext);
return NAME;
}
<INPUTLIST>"-l"{FILENAMECHAR}+ {
- yylval.name = xstrdup (yytext + 2);
+ yylval.name = stat_strdup (yytext + 2);
return LNAME;
}
<EXPRESSION>{SYMBOLNAMECHAR1}{SYMBOLNAMECHAR}* {
- yylval.name = xstrdup (yytext);
+ yylval.name = stat_strdup (yytext);
return NAME;
}
/* The following rule is to prevent a fill expression on the output
section before /DISCARD/ interpreting the '/' as a divide. */
<EXPRESSION>"/DISCARD/" {
- yylval.name = xstrdup (yytext);
+ yylval.name = stat_strdup (yytext);
return NAME;
}
<WILD>{WILDCHAR}* {
}
else
{
- yylval.name = xstrdup (yytext);
+ yylval.name = stat_strdup (yytext);
return NAME;
}
}
<SCRIPT,EXPRESSION,WILD,VERS_NODE,INPUTLIST>"\""[^\"]*"\"" {
/* No matter the state, quotes give what's inside. */
- yylval.name = xmemdup (yytext + 1, yyleng - 2, yyleng - 1);
+ yylval.name = stat_memdup (yytext + 1, yyleng - 2, yyleng - 1);
return NAME;
}
<VERS_NODE>extern { RTOKEN(EXTERN); }
-<VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
+<VERS_NODE>{V_IDENTIFIER} { yylval.name = stat_strdup (yytext);
return VERS_IDENTIFIER; }
-<VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
+<VERS_SCRIPT>{V_TAG} { yylval.name = stat_strdup (yytext);
return VERS_TAG; }
<VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }