From 0ad219a8f4366ea3bbcd442f999ee5df31201817 Mon Sep 17 00:00:00 2001 From: bellardo Date: Tue, 2 Apr 2002 05:42:38 +0000 Subject: [PATCH] Updated delete operators to accept a null pointer to delete as required by c++. --- src/common/memory/allocators.cpp | 11 +++++++---- src/common/memory/allocators.h | 8 ++++++-- src/common/memory/memory_pool.cpp | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/common/memory/allocators.cpp b/src/common/memory/allocators.cpp index b6aa4d33c9..7db5a75368 100644 --- a/src/common/memory/allocators.cpp +++ b/src/common/memory/allocators.cpp @@ -94,11 +94,14 @@ void* API_ROUTINE gds__alloc(SLONG size_request) ULONG API_ROUTINE gds__free(void* blk) { - try + if (blk) { - poolLoader.loadPool(); - return FB_MemoryPool->deallocate(blk); - } catch(...) {} + try + { + poolLoader.loadPool(); + return FB_MemoryPool->deallocate(blk); + } catch(...) {} + } return 0; } diff --git a/src/common/memory/allocators.h b/src/common/memory/allocators.h index 11f49c176c..901cbf799c 100644 --- a/src/common/memory/allocators.h +++ b/src/common/memory/allocators.h @@ -100,6 +100,10 @@ namespace Firebird allocator(MemoryPool& p, SSHORT t = 0) : pool(&p), type(t) {} allocator(MemoryPool *p = getDefaultMemoryPool(), SSHORT t = 0) : pool(p), type(t) {} + template + allocator(const allocator &alloc) + : pool(alloc.getPool()), type(alloc.getType()) { } + pointer allocate(size_type s, const void * = 0) { return (pointer) (pool ? pool->allocate(sizeof(T) * s) : gds__alloc(sizeof(T)*s)); } void deallocate(pointer p, size_type s) @@ -122,7 +126,8 @@ namespace Firebird return pool == rhs.pool && type == rhs.type; } - + MemoryPool *getPool() const { return pool; } + SSHORT getType() const { return type; } private: MemoryPool *pool; @@ -131,5 +136,4 @@ namespace Firebird }; - #endif // COMMON_ALLOCATORS_H diff --git a/src/common/memory/memory_pool.cpp b/src/common/memory/memory_pool.cpp index 30d03dcd07..15b37e9f6e 100644 --- a/src/common/memory/memory_pool.cpp +++ b/src/common/memory/memory_pool.cpp @@ -66,7 +66,7 @@ static const bool ENABLE_FREQUENT_VERIFICATION = false; // These next variables control the Red Zone debugging offered by the memory pool -static const bool ENABLE_RED_ZONES = false; // set to false to disable the red zones +static const bool ENABLE_RED_ZONES = true; // set to false to disable the red zones static const int RED_ZONE_FILL = 0xFD; static const int BEFORE_RED_ZONE_SIZE = 3; // The size of the red zone BEFORE the memory, // in ALLOCATION UNITS! Does NOT need to be set to