Skip to content

Commit

Permalink
Fix a leak in varr_t<T> that occurs when the inner type is also itera…
Browse files Browse the repository at this point in the history
…ble.
  • Loading branch information
DavidAce committed Dec 26, 2023
1 parent f066a62 commit 196fdb0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions include/h5pp/details/h5ppVarr.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ namespace h5pp::type::vlen {
template<typename T>
varr_t<T> &varr_t<T>::operator=(varr_t<T> &&v) noexcept {
if(vl.p == v.vl.p) return *this;
clear();
vl.len = v.vl.len;
vl.p = v.vl.p;
v.vl.len = 0;
Expand Down Expand Up @@ -250,14 +251,12 @@ namespace h5pp::type::vlen {
}
template<typename T>
void varr_t<T>::clear() noexcept {
if(vl.p == nullptr){
return;
}
if constexpr(std::is_destructible_v<T> and not std::is_trivially_destructible_v<T>)
if(vl.p == nullptr) return;
if constexpr(std::is_destructible_v<T>)
for(auto &v : *this) v.~T();

free(vl.p);
vl.p = nullptr;
vl.p = nullptr;
vl.len = 0;
}

Expand Down Expand Up @@ -343,16 +342,16 @@ namespace h5pp::type::sfinae {
inline constexpr bool is_or_has_varr_v = is_varr_v<T> or has_varr_v<T>;
}


#if defined(H5PP_USE_FMT) && defined(FMT_FORMAT_H_)

// Add a custom fmt::formatter for h5pp::varr_t
template<typename T, typename Char>
struct fmt::formatter<h5pp::varr_t<T>, Char, typename::std::enable_if_t<std::is_arithmetic_v<T>>::value> : fmt::formatter<std::vector<T>, Char> {
//template <typename T, typename=std::enable_if_t<std::is_arithmetic_v<T>>::value>
//struct fmt::formatter<h5pp::varr_t<T>>: formatter<std::vector<T>> {
auto format(const h5pp::varr_t<T> & v, format_context& ctx) const{
struct fmt::formatter<h5pp::varr_t<T>, Char, typename ::std::enable_if_t<std::is_arithmetic_v<T>>::value>
: fmt::formatter<std::vector<T>, Char> {
// template <typename T, typename=std::enable_if_t<std::is_arithmetic_v<T>>::value>
// struct fmt::formatter<h5pp::varr_t<T>>: formatter<std::vector<T>> {
auto format(const h5pp::varr_t<T> &v, format_context &ctx) const {
return fmt::formatter<std::vector<T>>::format(std::vector<T>(v.begin(), v.end()), ctx);
}
}
};
#endif

0 comments on commit 196fdb0

Please sign in to comment.