Skip to content

Commit

Permalink
Create MaNGOS::Memory::no_deleter
Browse files Browse the repository at this point in the history
Discover new and exciting ways how to leak memory by using this struct.
  • Loading branch information
0blu committed Aug 30, 2024
1 parent 2909b75 commit ac4c98b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ set (shared_SRCS
ArgparserForServer.h
ArgparserForServer.cpp
Memory/ArrayDeleter.h
Memory/NoDeleter.h
)

if(USE_LIBCURL)
Expand Down
19 changes: 19 additions & 0 deletions src/shared/Memory/NoDeleter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef MANGOS_NO_DELETER_H
#define MANGOS_NO_DELETER_H

namespace MaNGOS { namespace Memory
{
/// A non deleter implementation that can be used in std::shared_ptr
/// \warning Using this will result in a memory leak, if not managed otherwise!
/// \example std::shared_ptr<uint8_t> mySharedPtr = std::shared_ptr<uint8_t>(new uint8_t[1024], MaNGOS::Memory::no_deleter<uint8_t>());
template<typename T>
struct no_deleter
{
void operator()(T const*)
{
// Ignore. No call to `delete`
}
};
}} // namespace MaNGOS::Memory

#endif //MANGOS_NO_DELETER_H

0 comments on commit ac4c98b

Please sign in to comment.