From 71a1aa0afdd89883ab7449e37a6b44111532fea9 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 10 Jan 2024 18:48:51 -0800 Subject: [PATCH] fix for needing to always flush optimization information for identifiers --- src/script_opt/ScriptOpt.cc | 9 +++--- .../language.spurious-table-expires/out | 2 ++ .../language/spurious-table-expires.zeek | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 testing/btest/Baseline/language.spurious-table-expires/out create mode 100644 testing/btest/language/spurious-table-expires.zeek diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 34ffbf4c72..d9051f8113 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -507,9 +507,6 @@ static void analyze_scripts_for_ZAM() { void clear_script_analysis() { IDOptInfo::ClearGlobalInitExprs(); - // Keep the functions around if we're debugging, so we can - // generate profiles. -#ifndef DEBUG // We need to explicitly clear out the optimization information // associated with identifiers. They have reference loops with // the parent identifier that will prevent reclamation of the @@ -519,8 +516,10 @@ void clear_script_analysis() { for ( auto& id : f.Scope()->OrderedVars() ) id->ClearOptInfo(); - funcs.clear(); -#endif + // Keep the functions around if we're profiling, so we can loop + // over them to generate the profiles. + if ( ! analysis_options.profile_ZAM ) + funcs.clear(); non_recursive_funcs.clear(); lambdas.clear(); diff --git a/testing/btest/Baseline/language.spurious-table-expires/out b/testing/btest/Baseline/language.spurious-table-expires/out new file mode 100644 index 0000000000..ba5bc037ba --- /dev/null +++ b/testing/btest/Baseline/language.spurious-table-expires/out @@ -0,0 +1,2 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +expire, new, 42 diff --git a/testing/btest/language/spurious-table-expires.zeek b/testing/btest/language/spurious-table-expires.zeek new file mode 100644 index 0000000000..fa0e0120ab --- /dev/null +++ b/testing/btest/language/spurious-table-expires.zeek @@ -0,0 +1,28 @@ +# @TEST-EXEC: zeek -b -r $TRACES/wikipedia.trace %INPUT >out +# @TEST-EXEC: btest-diff out + +# Default timer expiration interval is very conservative (10sec) and never runs for short pcaps. +redef table_expire_interval = 0.01sec; + +function f(t: table[string] of count, k: string): interval + { + print "expire", k, t[k]; + return 0.0sec; + } + +global t: table[string] of count &create_expire=0.1sec &expire_func=f; + +# Populate the initial table with two entries. +event zeek_init() &priority=5 + { + t["a"] = 10; + t["b"] = 20; + } + +# Replace global t, deleting all entries. In a DEBUG build, table continued +# to exist and its entries spuriously expired over time. +event zeek_init() + { + t = table() &create_expire=0.1sec &expire_func=f; + t["new"] = 42; + }