diff --git a/src/Type.cc b/src/Type.cc index d6da601227..fec2544e2d 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -484,7 +484,7 @@ TableType::TableType(TypeListPtr ind, TypePtr yield) : IndexType(TYPE_TABLE, std RegenerateHash(); } -TableType::~TableType() { delete table_hash; } +TableType::~TableType() {} bool TableType::CheckExpireFuncCompatibility(const detail::AttrPtr& attr) { if ( reported_error ) @@ -499,10 +499,7 @@ bool TableType::CheckExpireFuncCompatibility(const detail::AttrPtr& attr) { TypePtr TableType::ShallowClone() { return make_intrusive(indices, yield_type); } -void TableType::RegenerateHash() { - delete table_hash; - table_hash = new detail::CompositeHash(GetIndices()); -} +void TableType::RegenerateHash() { table_hash = std::make_unique(GetIndices()); } bool TableType::IsUnspecifiedTable() const { // Unspecified types have an empty list of indices. diff --git a/src/Type.h b/src/Type.h index a113538e17..dcdbc09e0d 100644 --- a/src/Type.h +++ b/src/Type.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -402,7 +403,7 @@ public: // what one gets using an empty "set()" or "table()" constructor. bool IsUnspecifiedTable() const; - const detail::CompositeHash* GetTableHash() const { return table_hash; } + const detail::CompositeHash* GetTableHash() const { return table_hash.get(); } // Called to rebuild the associated hash function when a record type // (that this table type depends on) gets redefined during parsing. @@ -411,7 +412,7 @@ public: private: bool DoExpireCheck(const detail::AttrPtr& attr); - detail::CompositeHash* table_hash = nullptr; + std::unique_ptr table_hash; // Used to prevent repeated error messages. bool reported_error = false;