summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
363a2bc)
When realloc fails it doesn't free the old memory. In BFD we usually
will exit with an error on a realloc fail, so want to tidy up memory
on error paths. That's done by bfd_realloc_or_free.
* vms-alpha.c (vms_get_remaining_object_record): Use
bfd_realloc_or_free rather than bfd_realloc.
(add_symbol_entry, vector_grow1, alpha_vms_slurp_relocs): Likewise.
(dst_define_location, parse_module): Likewise, and check realloc
return status before using memory. Return status from function
adjusting all callers.
+2020-03-02 Alan Modra <amodra@gmail.com>
+
+ * vms-alpha.c (vms_get_remaining_object_record): Use
+ bfd_realloc_or_free rather than bfd_realloc.
+ (add_symbol_entry, vector_grow1, alpha_vms_slurp_relocs): Likewise.
+ (dst_define_location, parse_module): Likewise, and check realloc
+ return status before using memory. Return status from function
+ adjusting all callers.
+
2020-02-28 Alan Modra <amodra@gmail.com>
* vms-lib.c (_bfd_vms_lib_archive_p): Free memory on error paths.
2020-02-28 Alan Modra <amodra@gmail.com>
* vms-lib.c (_bfd_vms_lib_archive_p): Free memory on error paths.
if (to_read > PRIV (recrd.buf_size))
{
PRIV (recrd.buf)
if (to_read > PRIV (recrd.buf_size))
{
PRIV (recrd.buf)
- = (unsigned char *) bfd_realloc (PRIV (recrd.buf), to_read);
+ = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read);
if (PRIV (recrd.buf) == NULL)
return 0;
PRIV (recrd.buf_size) = to_read;
if (PRIV (recrd.buf) == NULL)
return 0;
PRIV (recrd.buf_size) = to_read;
else
{
PRIV (max_sym_count) *= 2;
else
{
PRIV (max_sym_count) *= 2;
- PRIV (syms) = bfd_realloc
+ PRIV (syms) = bfd_realloc_or_free
(PRIV (syms),
(PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
}
(PRIV (syms),
(PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
}
/* Save current DST location counter under specified index. */
/* Save current DST location counter under specified index. */
dst_define_location (bfd *abfd, unsigned int loc)
{
vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
dst_define_location (bfd *abfd, unsigned int loc)
{
vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
/* Grow the ptr offset table if necessary. */
if (loc + 1 > PRIV (dst_ptr_offsets_count))
{
/* Grow the ptr offset table if necessary. */
if (loc + 1 > PRIV (dst_ptr_offsets_count))
{
- PRIV (dst_ptr_offsets) = bfd_realloc (PRIV (dst_ptr_offsets),
- (loc + 1) * sizeof (unsigned int));
+ PRIV (dst_ptr_offsets)
+ = bfd_realloc_or_free (PRIV (dst_ptr_offsets),
+ (loc + 1) * sizeof (unsigned int));
+ if (PRIV (dst_ptr_offsets) == NULL)
+ return FALSE;
PRIV (dst_ptr_offsets_count) = loc + 1;
}
PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
PRIV (dst_ptr_offsets_count) = loc + 1;
}
PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
}
/* Restore saved DST location counter from specified index. */
}
/* Restore saved DST location counter from specified index. */
return FALSE;
if (rel1 != RELC_NONE)
goto bad_context;
return FALSE;
if (rel1 != RELC_NONE)
goto bad_context;
- dst_define_location (abfd, op1);
+ if (!dst_define_location (abfd, op1))
+ return FALSE;
break;
/* Set location: pop index, restore location counter from index
break;
/* Set location: pop index, restore location counter from index
bfd_set_error (bfd_error_file_too_big);
return NULL;
}
bfd_set_error (bfd_error_file_too_big);
return NULL;
}
- vec->els = bfd_realloc (vec->els, amt);
+ vec->els = bfd_realloc_or_free (vec->els, amt);
}
}
if (vec->els == NULL)
}
}
if (vec->els == NULL)
/* Parse debug info for a module and internalize it. */
/* Parse debug info for a module and internalize it. */
parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
int length)
{
parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
int length)
{
{
module->file_table_count *= 2;
module->file_table
{
module->file_table_count *= 2;
module->file_table
- = bfd_realloc (module->file_table,
- module->file_table_count
- * sizeof (struct fileinfo));
+ = bfd_realloc_or_free (module->file_table,
+ module->file_table_count
+ * sizeof (struct fileinfo));
+ if (module->file_table == NULL)
+ return FALSE;
}
module->file_table [fileid].name = filename;
}
module->file_table [fileid].name = filename;
because parsing can be either performed at module creation
or deferred until debug info is consumed. */
SET_MODULE_PARSED (module);
because parsing can be either performed at module creation
or deferred until debug info is consumed. */
SET_MODULE_PARSED (module);
}
/* Build the list of modules for the specified BFD. */
}
/* Build the list of modules for the specified BFD. */
return NULL;
module = new_module (abfd);
return NULL;
module = new_module (abfd);
- parse_module (abfd, module, PRIV (dst_section)->contents, -1);
+ if (!parse_module (abfd, module, PRIV (dst_section)->contents, -1))
+ return NULL;
- parse_module (abfd, module, buffer, size);
+ ret = parse_module (abfd, module, buffer, size);
+ if (!ret)
+ return ret;
}
/* Find out the function (if any) that contains the address. */
}
/* Find out the function (if any) that contains the address. */
else
{
vms_sec->reloc_max *= 2;
else
{
vms_sec->reloc_max *= 2;
- sec->relocation = bfd_realloc
+ sec->relocation = bfd_realloc_or_free
(sec->relocation, vms_sec->reloc_max * sizeof (arelent));
(sec->relocation, vms_sec->reloc_max * sizeof (arelent));
+ if (sec->relocation == NULL)
+ return FALSE;
}
}
reloc = &sec->relocation[sec->reloc_count];
}
}
reloc = &sec->relocation[sec->reloc_count];