aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-string.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-09-17 06:54:23 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-10-03 17:04:56 +0100
commitde07e349bea156484fae1dbec974fdbbf207d57d (patch)
tree6c05706f80ed06a2c71ef69aab121d1102aa73ed /libctf/ctf-string.c
parent9c1a2295e84170d2de06ef3c828f0c9f5933867e (diff)
downloadgdb-de07e349bea156484fae1dbec974fdbbf207d57d.zip
gdb-de07e349bea156484fae1dbec974fdbbf207d57d.tar.gz
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-string.c')
-rw-r--r--libctf/ctf-string.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/libctf/ctf-string.c b/libctf/ctf-string.c
index 243e1ac..a4227f9 100644
--- a/libctf/ctf-string.c
+++ b/libctf/ctf-string.c
@@ -82,7 +82,7 @@ ctf_str_purge_atom_refs (ctf_str_atom_t *atom)
{
next = ctf_list_next (ref);
ctf_list_delete (&atom->csa_refs, ref);
- ctf_free (ref);
+ free (ref);
}
}
@@ -93,7 +93,7 @@ ctf_str_free_atom (void *a)
ctf_str_atom_t *atom = a;
ctf_str_purge_atom_refs (atom);
- ctf_free (atom);
+ free (atom);
}
/* Create the atoms table. There is always at least one atom in it, the null
@@ -102,7 +102,7 @@ int
ctf_str_create_atoms (ctf_file_t *fp)
{
fp->ctf_str_atoms = ctf_dynhash_create (ctf_hash_string, ctf_hash_eq_string,
- ctf_free, ctf_str_free_atom);
+ free, ctf_str_free_atom);
if (fp->ctf_str_atoms == NULL)
return -ENOMEM;
@@ -154,7 +154,7 @@ ctf_str_add_ref_internal (ctf_file_t *fp, const char *str,
if (add_ref)
{
- if ((aref = ctf_alloc (sizeof (struct ctf_str_atom_ref))) == NULL)
+ if ((aref = malloc (sizeof (struct ctf_str_atom_ref))) == NULL)
return NULL;
aref->caf_ref = ref;
}
@@ -169,11 +169,11 @@ ctf_str_add_ref_internal (ctf_file_t *fp, const char *str,
return atom;
}
- if ((atom = ctf_alloc (sizeof (struct ctf_str_atom))) == NULL)
+ if ((atom = malloc (sizeof (struct ctf_str_atom))) == NULL)
goto oom;
memset (atom, 0, sizeof (struct ctf_str_atom));
- if ((newstr = ctf_strdup (str)) == NULL)
+ if ((newstr = strdup (str)) == NULL)
goto oom;
if (ctf_dynhash_insert (fp->ctf_str_atoms, newstr, atom) < 0)
@@ -203,9 +203,9 @@ ctf_str_add_ref_internal (ctf_file_t *fp, const char *str,
oom:
if (newstr)
ctf_dynhash_remove (fp->ctf_str_atoms, newstr);
- ctf_free (atom);
- ctf_free (aref);
- ctf_free (newstr);
+ free (atom);
+ free (aref);
+ free (newstr);
return NULL;
}
@@ -279,7 +279,7 @@ ctf_str_remove_ref (ctf_file_t *fp, const char *str, uint32_t *ref)
if (aref->caf_ref == ref)
{
ctf_list_delete (&atom->csa_refs, aref);
- ctf_free (aref);
+ free (aref);
}
}
}
@@ -452,7 +452,7 @@ ctf_str_write_strtab (ctf_file_t *fp)
qsort (&sorttab[1], s.strtab_count - 1, sizeof (ctf_str_atom_t *),
ctf_str_sort_strtab);
- if ((strtab.cts_strs = ctf_alloc (strtab.cts_len)) == NULL)
+ if ((strtab.cts_strs = malloc (strtab.cts_len)) == NULL)
goto oom_sorttab;
if (!fp->ctf_syn_ext_strtab)