diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2019-09-17 06:54:23 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2019-10-03 17:04:56 +0100 |
commit | de07e349bea156484fae1dbec974fdbbf207d57d (patch) | |
tree | 6c05706f80ed06a2c71ef69aab121d1102aa73ed /libctf/ctf-dump.c | |
parent | 9c1a2295e84170d2de06ef3c828f0c9f5933867e (diff) | |
download | fsf-binutils-gdb-de07e349bea156484fae1dbec974fdbbf207d57d.zip fsf-binutils-gdb-de07e349bea156484fae1dbec974fdbbf207d57d.tar.gz fsf-binutils-gdb-de07e349bea156484fae1dbec974fdbbf207d57d.tar.bz2 |
libctf: remove ctf_malloc, ctf_free and ctf_strdup
These just get in the way of auditing for erroneous usage of strdup and
add a huge irregular surface of "ctf_malloc or malloc? ctf_free or free?
ctf_strdup or strdup?"
ctf_malloc and ctf_free usage has not reliably matched up for many
years, if ever, making the whole game pointless.
Go back to malloc, free, and strdup like everyone else: while we're at
it, fix a bunch of places where we weren't properly checking for OOM.
This changes the interface of ctf_cuname_set and ctf_parent_name_set,
which could strdup but could not return errors (like ENOMEM).
New in v4.
include/
* ctf-api.h (ctf_cuname_set): Can now fail, returning int.
(ctf_parent_name_set): Likewise.
libctf/
* ctf-impl.h (ctf_alloc): Remove.
(ctf_free): Likewise.
(ctf_strdup): Likewise.
* ctf-subr.c (ctf_alloc): Remove.
(ctf_free): Likewise.
* ctf-util.c (ctf_strdup): Remove.
* ctf-create.c (ctf_serialize): Use malloc, not ctf_alloc; free, not
ctf_free; strdup, not ctf_strdup.
(ctf_dtd_delete): Likewise.
(ctf_dvd_delete): Likewise.
(ctf_add_generic): Likewise.
(ctf_add_function): Likewise.
(ctf_add_enumerator): Likewise.
(ctf_add_member_offset): Likewise.
(ctf_add_variable): Likewise.
(membadd): Likewise.
(ctf_compress_write): Likewise.
(ctf_write_mem): Likewise.
* ctf-decl.c (ctf_decl_push): Likewise.
(ctf_decl_fini): Likewise.
(ctf_decl_sprintf): Likewise. Check for OOM.
* ctf-dump.c (ctf_dump_append): Use malloc, not ctf_alloc; free, not
ctf_free; strdup, not ctf_strdup.
(ctf_dump_free): Likewise.
(ctf_dump): Likewise.
* ctf-open.c (upgrade_types_v1): Likewise.
(init_types): Likewise.
(ctf_file_close): Likewise.
(ctf_bufopen_internal): Likewise. Check for OOM.
(ctf_parent_name_set): Likewise: report the OOM to the caller.
(ctf_cuname_set): Likewise.
(ctf_import): Likewise.
* ctf-string.c (ctf_str_purge_atom_refs): Use malloc, not ctf_alloc;
free, not ctf_free; strdup, not ctf_strdup.
(ctf_str_free_atom): Likewise.
(ctf_str_create_atoms): Likewise.
(ctf_str_add_ref_internal): Likewise.
(ctf_str_remove_ref): Likewise.
(ctf_str_write_strtab): Likewise.
Diffstat (limited to 'libctf/ctf-dump.c')
-rw-r--r-- | libctf/ctf-dump.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c index df08f0b..c2d331b 100644 --- a/libctf/ctf-dump.c +++ b/libctf/ctf-dump.c @@ -52,7 +52,7 @@ ctf_dump_append (ctf_dump_state_t *state, char *str) { ctf_dump_item_t *cdi; - if ((cdi = ctf_alloc (sizeof (struct ctf_dump_item))) == NULL) + if ((cdi = malloc (sizeof (struct ctf_dump_item))) == NULL) return (ctf_set_errno (state->cds_fp, ENOMEM)); cdi->cdi_item = str; @@ -73,7 +73,7 @@ ctf_dump_free (ctf_dump_state_t *state) { free (cdi->cdi_item); next_cdi = ctf_list_next (cdi); - ctf_free (cdi); + free (cdi); } } @@ -668,7 +668,7 @@ ctf_dump (ctf_file_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect, by bit. The first call will take (much) longer than otherwise, but the amortized time needed is the same. */ - if ((*statep = ctf_alloc (sizeof (struct ctf_dump_state))) == NULL) + if ((*statep = malloc (sizeof (struct ctf_dump_state))) == NULL) { ctf_set_errno (fp, ENOMEM); goto end; @@ -779,7 +779,7 @@ ctf_dump (ctf_file_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect, end: ctf_dump_free (state); - ctf_free (state); + free (state); ctf_set_errno (fp, 0); *statep = NULL; return NULL; |