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-30 16:53:19 +0000
commita59ce5fc7238ed77b662d4d5b268c3bfbdb034ca (patch)
tree7c73f77ab99a651c9f5ed5e8ebaef1db1554272e
parentb1cffed37e446151bbf631502437f1ae5e13e317 (diff)
downloadATCD-a59ce5fc7238ed77b662d4d5b268c3bfbdb034ca.tar.gz
Do not invoke a method on pointer returned from remove() without checking it
(cherry picked from commit ca31d936b698d3e6e318668ac55f77f70f6d81c3)
-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 d98b5c95672..cedde89d686 100644
--- a/ACE/ace/Malloc_T.cpp
+++ b/ACE/ace/Malloc_T.cpp
@@ -64,9 +64,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 *
@@ -77,9 +76,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;
@@ -138,9 +136,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 *
@@ -151,9 +148,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;