[13/19] libctf: link: remember to turn off the LCTF_LINKING flag after ctf_link_write

Message ID 20240730153707.168357-14-nick.alcock@oracle.com
State New
Headers
Series libctf: various bugfixes (including a write into freed memory), and loosen constraints on enums |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Nick Alcock July 30, 2024, 3:37 p.m. UTC
  We set this flag at the top of ctf_link_write (to tell ctf_serialize, way
down under the archive file writing functions, to do the various link- time
serialization things like symbol filtering and the like), but we never
remember to clear it except on error.  This is probably bad if you want to
serialize the dict yourself directly in the future after linking it (which
is...  definitely a *possible* use of the API, if rather strange).

libctf/
	* ctf-link.c (ctf_link_write): Clear LCTF_LINKING before exit.
---
 libctf/ctf-link.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Patch

diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index 7b68d709628..3bfc36ed9e1 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -2040,6 +2040,10 @@  ctf_link_write (ctf_dict_t *fp, size_t *size, size_t threshold)
 	goto err_no;
       }
 
+  /* Turn off the is-linking flag on all the dicts in this link.  */
+  for (i = 0; i < arg.i; i++)
+    arg.files[i]->ctf_flags &= ~LCTF_LINKING;
+
   *size = fsize;
   free (arg.names);
   free (arg.files);