diff mbox series

[committed] btf: check hash maps are non-null before emptying

Message ID 20241107180757.51698-1-david.faust@oracle.com
State New
Headers show
Series [committed] btf: check hash maps are non-null before emptying | expand

Commit Message

David Faust Nov. 7, 2024, 6:07 p.m. UTC
These maps will always be non-null in btf_finalize under normal
circumstances, but be safe and verify that before trying to empty them.

Tested on x86_64-linux-gnu and x86_64-linux-gnu host for bpf-unknown-none
target. Pushed as obvious.

gcc/
	* btfout.cc (btf_finalize): Check that hash maps are non-null before
	emptying them.
---
 gcc/btfout.cc | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/gcc/btfout.cc b/gcc/btfout.cc
index 083ca48d627..4a6b5453e08 100644
--- a/gcc/btfout.cc
+++ b/gcc/btfout.cc
@@ -1661,13 +1661,19 @@  btf_finalize (void)
   datasecs.release ();
 
   funcs = NULL;
-  func_map->empty ();
-  func_map = NULL;
+  if (func_map)
+    {
+      func_map->empty ();
+      func_map = NULL;
+    }
 
   if (debug_prune_btf)
     {
-      btf_used_types->empty ();
-      btf_used_types = NULL;
+      if (btf_used_types)
+	{
+	  btf_used_types->empty ();
+	  btf_used_types = NULL;
+	}
 
       fixups.release ();
       forwards = NULL;