diff --git a/src/CompHash.cc b/src/CompHash.cc index 37ee7e25c9..29f09e53b6 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -13,10 +13,9 @@ #include #include -CompositeHash::CompositeHash(TypeList* composite_type) +CompositeHash::CompositeHash(IntrusivePtr composite_type) + :type(std::move(composite_type)) { - type = composite_type; - Ref(type); singleton_tag = TYPE_INTERNAL_ERROR; // If the only element is a record, don't treat it as a @@ -66,7 +65,6 @@ CompositeHash::CompositeHash(TypeList* composite_type) CompositeHash::~CompositeHash() { - Unref(type); delete [] key; } diff --git a/src/CompHash.h b/src/CompHash.h index ef0f0d14c3..9aa3555200 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -3,13 +3,14 @@ #pragma once #include "Type.h" +#include "IntrusivePtr.h" class ListVal; class HashKey; class CompositeHash { public: - explicit CompositeHash(TypeList* composite_type); + explicit CompositeHash(IntrusivePtr composite_type); ~CompositeHash(); // Compute the hash corresponding to the given index val, @@ -78,7 +79,7 @@ protected: int type_check, int sz, bool optional, bool calc_static_size) const; - TypeList* type; + IntrusivePtr type; char* key; // space for composite key int size; int is_singleton; // if just one type in index diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 460fea1945..96f67f55a8 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -791,10 +791,9 @@ bool BloomFilterVal::Typify(BroType* arg_type) type = arg_type; type->Ref(); - TypeList* tl = new TypeList(type); + auto tl = make_intrusive(type); tl->Append(type->Ref()); - hash = new CompositeHash(tl); - Unref(tl); + hash = new CompositeHash(std::move(tl)); return true; } @@ -963,10 +962,9 @@ bool CardinalityVal::Typify(BroType* arg_type) type = arg_type; type->Ref(); - TypeList* tl = new TypeList(type); + auto tl = make_intrusive(type); tl->Append(type->Ref()); - hash = new CompositeHash(tl); - Unref(tl); + hash = new CompositeHash(std::move(tl)); return true; } diff --git a/src/Stmt.cc b/src/Stmt.cc index 15400632d7..76b31c07e4 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -602,10 +602,9 @@ static void int_del_func(void* v) void SwitchStmt::Init() { - TypeList* t = new TypeList(); + auto t = make_intrusive(); t->Append(e->Type()->Ref()); - comp_hash = new CompositeHash(t); - Unref(t); + comp_hash = new CompositeHash(std::move(t)); case_label_value_map.SetDeleteFunc(int_del_func); } diff --git a/src/Val.cc b/src/Val.cc index 1c11070d0c..7ae4b16f2f 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1352,7 +1352,8 @@ void TableVal::Init(TableType* t) else subnets = 0; - table_hash = new CompositeHash(table_type->Indices()); + table_hash = new CompositeHash(IntrusivePtr(NewRef{}, + table_type->Indices())); val.table_val = new PDict; val.table_val->SetDeleteFunc(table_entry_val_delete_func); } diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index d3cbe300f1..53c677eff3 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -20,11 +20,10 @@ static void analyzer_del_func(void* v) AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file) { - TypeList* t = new TypeList(); + auto t = make_intrusive(); t->Append(file_mgr->GetTagEnumType()->Ref()); t->Append(BifType::Record::Files::AnalyzerArgs->Ref()); - analyzer_hash = new CompositeHash(t); - Unref(t); + analyzer_hash = new CompositeHash(std::move(t)); analyzer_map.SetDeleteFunc(analyzer_del_func); } diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 5da17c7e4c..c177ba4545 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -27,10 +27,9 @@ void TopkVal::Typify(BroType* t) { assert(!hash && !type); type = t->Ref(); - TypeList* tl = new TypeList(t); + auto tl = make_intrusive(t); tl->Append(t->Ref()); - hash = new CompositeHash(tl); - Unref(tl); + hash = new CompositeHash(std::move(tl)); } HashKey* TopkVal::GetHash(Val* v) const