diff --git a/src/Type.cc b/src/Type.cc index 8c229bdabb..0d9bd3e296 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1004,20 +1004,16 @@ void SubNetType::Describe(ODesc* d) const d->Add(int(Tag())); } -FileType::FileType(BroType* yield_type) -: BroType(TYPE_FILE) +FileType::FileType(IntrusivePtr yield_type) +: BroType(TYPE_FILE), yield(std::move(yield_type)) { - yield = yield_type; } -FileType::~FileType() - { - Unref(yield); - } +FileType::~FileType() = default; BroType* FileType::YieldType() { - return yield; + return yield.get(); } void FileType::Describe(ODesc* d) const @@ -1949,7 +1945,7 @@ BroType* merge_types(const BroType* t1, const BroType* t2) return 0; } - return new FileType(merge_types(t1->YieldType(), t2->YieldType())); + return new FileType({AdoptRef{}, merge_types(t1->YieldType(), t2->YieldType())}); case TYPE_UNION: reporter->InternalError("union type in merge_types()"); diff --git a/src/Type.h b/src/Type.h index 178a0f5aac..7df8ae3057 100644 --- a/src/Type.h +++ b/src/Type.h @@ -567,8 +567,8 @@ public: class FileType : public BroType { public: - explicit FileType(BroType* yield_type); - FileType* ShallowClone() override { return new FileType(yield->Ref()); } + explicit FileType(IntrusivePtr yield_type); + FileType* ShallowClone() override { return new FileType(yield); } ~FileType() override; BroType* YieldType() override; @@ -576,9 +576,7 @@ public: void Describe(ODesc* d) const override; protected: - FileType() { yield = 0; } - - BroType* yield; + IntrusivePtr yield; }; class OpaqueType : public BroType { diff --git a/src/Val.cc b/src/Val.cc index 46be8f1803..4c3ae7fd0c 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -49,7 +49,7 @@ static FileType* GetStringFileType() noexcept { static FileType* string_file_type = 0; if ( ! string_file_type ) - string_file_type = new FileType(base_type(TYPE_STRING)); + string_file_type = new FileType({AdoptRef{}, base_type(TYPE_STRING)}); return string_file_type; } diff --git a/src/parse.y b/src/parse.y index c5dc8a4b1b..f19fcd65a0 100644 --- a/src/parse.y +++ b/src/parse.y @@ -991,13 +991,13 @@ type: | TOK_FILE TOK_OF type { set_location(@1, @3); - $$ = new FileType($3); + $$ = new FileType({AdoptRef{}, $3}); } | TOK_FILE { set_location(@1); - $$ = new FileType(base_type(TYPE_STRING)); + $$ = new FileType({AdoptRef{}, base_type(TYPE_STRING)}); } | TOK_OPAQUE TOK_OF TOK_ID