summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2020-05-29 22:05:47 +0000
committerSteve Huston <shuston@riverace.com>2020-05-29 22:05:47 +0000
commitca31d936b698d3e6e318668ac55f77f70f6d81c3 (patch)
treef1d29f749954f9b4a1983ce2429e9a6cc79d0df2
parentadced9754c8ffca51fdba3189775e7dc757fd02b (diff)
downloadATCD-riverace-case-2186.tar.gz
Do not invoke a method on pointer returned from remove() without checking itriverace-case-2186
-rw-r--r--ACE/ace/Malloc_T.cpp20
1 files 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<T, ACE_LOCK>::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<T> *allocated = this->free_list_.remove ();
+ return allocated == 0 ? 0 : allocated->addr();
}
template <class T, class ACE_LOCK> void *
@@ -86,9 +85,8 @@ ACE_Cached_Allocator<T, ACE_LOCK>::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<T> *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<ACE_LOCK>::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<char> *allocated = this->free_list_.remove ();
+ return allocated == 0 ? 0 : allocated->addr();
}
template <class ACE_LOCK> void *
@@ -160,9 +157,8 @@ ACE_Dynamic_Cached_Allocator<ACE_LOCK>::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<char> *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;