From 143ea3ba38a750efd23fe106abb4e33d73c8f18d Mon Sep 17 00:00:00 2001 From: Martin Leitner-Ankerl Date: Tue, 19 Jul 2022 20:00:48 +0200 Subject: [PATCH] fix #42: Using delete operator for the memory allocated with placement new Also bump version to 1.0.1 for that fix --- CMakeLists.txt | 2 +- include/ankerl/svector.h | 15 ++++++++++----- meson.build | 2 +- scripts/build.py | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9777f59..467de14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.12) project("svector" - VERSION 1.0.0 + VERSION 1.0.1 DESCRIPTION " Compact SVO optimized vector for C++17 or higher" HOMEPAGE_URL "https://github.com/martinus/svector") diff --git a/include/ankerl/svector.h b/include/ankerl/svector.h index b6ef1ad..60edcfe 100644 --- a/include/ankerl/svector.h +++ b/include/ankerl/svector.h @@ -1,5 +1,5 @@ // ┌─┐┬ ┬┌─┐┌─┐┌┬┐┌─┐┬─┐ Compact SVO optimized vector C++17 or higher -// └─┐└┐┌┘├┤ │ │ │ │├┬┘ Version 1.0.0 +// └─┐└┐┌┘├┤ │ │ │ │├┬┘ Version 1.0.1 // └─┘ └┘ └─┘└─┘ ┴ └─┘┴└─ https://github.com/martinus/svector // // Licensed under the MIT License . @@ -30,7 +30,7 @@ // see https://semver.org/spec/v2.0.0.html #define ANKERL_SVECTOR_VERSION_MAJOR 1 // incompatible API changes #define ANKERL_SVECTOR_VERSION_MINOR 0 // add functionality in a backwards compatible manner -#define ANKERL_SVECTOR_VERSION_PATCH 0 // backwards compatible bug fixes +#define ANKERL_SVECTOR_VERSION_PATCH 1 // backwards compatible bug fixes // API versioning with inline namespace, see https://www.foonathan.net/2018/11/inline-namespaces/ #define ANKERL_SVECTOR_VERSION_CONCAT1(major, minor, patch) v##major##_##minor##_##patch @@ -272,7 +272,8 @@ class svector { auto* storage = indirect(); uninitialized_move_and_destroy(storage->data(), direct_data(), storage->size()); set_direct_and_size(storage->size()); - delete storage; + std::destroy_at(storage); + ::operator delete(storage); } else { // put everything into indirect storage auto* storage = detail::storage::alloc(new_capacity); @@ -284,7 +285,9 @@ class svector { // indirect -> indirect uninitialized_move_and_destroy(data(), storage->data(), size()); storage->size(size()); - delete indirect(); + auto* storage = indirect(); + std::destroy_at(storage); + ::operator delete(storage); } set_indirect(storage); } @@ -522,7 +525,9 @@ class svector { std::destroy_n(ptr, s); } if (!is_dir) { - delete indirect(); + auto* storage = indirect(); + std::destroy_at(storage); + ::operator delete(storage); } } diff --git a/meson.build b/meson.build index 08d5ee7..1f45df6 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,7 @@ # project('svector', 'cpp', - version: '1.0.0', + version: '1.0.1', license: 'MIT', default_options : ['cpp_std=c++17', 'warning_level=3', 'werror=true']) diff --git a/scripts/build.py b/scripts/build.py index 0374aa4..8338ea3 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -35,8 +35,8 @@ ['env', 'CXX=ccache g++', 'meson', 'setup', '-Db_sanitize=thread', 'builddir/gcc_sanitize_thread'], ['env', 'CXX=ccache clang++', 'meson', 'setup', '-Db_sanitize=thread', 'builddir/clang_sanitize_thread'], - ['env', 'CXX=ccache g++', 'meson', 'setup', '-Db_sanitize=memory', 'builddir/gcc_sanitize_memory'], # doesn't work due to STL, and ignore doesn't work either :-( - #['env', 'CXX=ccache clang++', 'meson', 'setup', '-Db_sanitize=memory', 'builddir/clang_sanitize_memory'], # doesn't work due to STL, and ignore doesn't work either :-( + # ['env', 'CXX=ccache g++', 'meson', 'setup', '-Db_sanitize=memory', 'builddir/gcc_sanitize_memory'], # doesn't work due to STL, and ignore doesn't work either :-( + # ['env', 'CXX=ccache clang++', 'meson', 'setup', '-Db_sanitize=memory', 'builddir/clang_sanitize_memory'], # doesn't work due to STL, and ignore doesn't work either :-( ['env', 'CXX=ccache g++', 'meson', 'setup', '-Db_sanitize=undefined', 'builddir/gcc_sanitize_undefined'], ['env', 'CXX=ccache clang++', 'meson', 'setup', '-Db_sanitize=undefined', 'builddir/clang_sanitize_undefined'],