Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H7#define BITCOIN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H9#include <support/cleanse.h>11#include <memory>12#include <vector>14template <typename T>15struct zero_after_free_allocator {16using value_type = T;18zero_after_free_allocator() noexcept = default;19template <typename U>20zero_after_free_allocator(const zero_after_free_allocator<U>&) noexcept21{22}24T* allocate(std::size_t n)25{26return std::allocator<T>{}.allocate(n);27}29void deallocate(T* p, std::size_t n)30{31if (p != nullptr)32memory_cleanse(p, sizeof(T) * n);33std::allocator<T>{}.deallocate(p, n);34}36template <typename U>37friend bool operator==(const zero_after_free_allocator&, const zero_after_free_allocator<U>&) noexcept38{39return true;40}41};43/** Byte-vector that clears its contents before deletion. */44using SerializeData = std::vector<std::byte, zero_after_free_allocator<std::byte>>;46#endif // BITCOIN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H