From ca31d936b698d3e6e318668ac55f77f70f6d81c3 Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Fri, 29 May 2020 22:05:47 +0000 Subject: Do not invoke a method on pointer returned from remove() without checking it --- ACE/ace/Malloc_T.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ACE/ace/Malloc_T.cpp b/ACE/ace/Malloc_T.cpp index 69a6e4398f3..0f966f99c8f 100644 --- a/ACE/ace/Malloc_T.cpp +++ b/ACE/ace/Malloc_T.cpp @@ -73,9 +73,8 @@ ACE_Cached_Allocator::malloc (size_t nbytes) if (nbytes > sizeof (T)) return 0; - // addr() call is really not absolutely necessary because of the way - // ACE_Cached_Mem_Pool_Node's internal structure arranged. - return this->free_list_.remove ()->addr (); + ACE_Cached_Mem_Pool_Node *allocated = this->free_list_.remove (); + return allocated == 0 ? 0 : allocated->addr(); } template void * @@ -86,9 +85,8 @@ ACE_Cached_Allocator::calloc (size_t nbytes, if (nbytes > sizeof (T)) return 0; - // addr() call is really not absolutely necessary because of the way - // ACE_Cached_Mem_Pool_Node's internal structure arranged. - void *ptr = this->free_list_.remove ()->addr (); + ACE_Cached_Mem_Pool_Node *allocated = this->free_list_.remove (); + void *ptr = allocated == 0 ? 0 : allocated->addr(); if (ptr != 0) ACE_OS::memset (ptr, initial_value, sizeof (T)); return ptr; @@ -147,9 +145,8 @@ ACE_Dynamic_Cached_Allocator::malloc (size_t nbytes) if (nbytes > chunk_size_) return 0; - // addr() call is really not absolutely necessary because of the way - // ACE_Cached_Mem_Pool_Node's internal structure arranged. - return this->free_list_.remove ()->addr (); + ACE_Cached_Mem_Pool_Node *allocated = this->free_list_.remove (); + return allocated == 0 ? 0 : allocated->addr(); } template void * @@ -160,9 +157,8 @@ ACE_Dynamic_Cached_Allocator::calloc (size_t nbytes, if (nbytes > chunk_size_) return 0; - // addr() call is really not absolutely necessary because of the way - // ACE_Cached_Mem_Pool_Node's internal structure arranged. - void *ptr = this->free_list_.remove ()->addr (); + ACE_Cached_Mem_Pool_Node *allocated = this->free_list_.remove (); + void *ptr = allocated == 0 ? 0 : allocated->addr(); if (ptr != 0) ACE_OS::memset (ptr, initial_value, chunk_size_); return ptr; -- cgit v1.2.1