ywkaras commented on a change in pull request #6241:
URL: https://github.com/apache/trafficserver/pull/6241#discussion_r567014393
##########
File path: include/tscore/Allocator.h
##########
@@ -108,29 +109,39 @@ class Allocator
ink_freelist_madvise_init(&this->fl, name, element_size, chunk_size,
alignment, advice);
}
+ // Dummies
+ void
+ destroy_if_enabled(void *)
+ {
+ }
+ Allocator &
+ raw()
+ {
+ return *this;
+ }
+
protected:
InkFreeList *fl;
};
/**
- Allocator for Class objects. It uses a prototype object to do
- fast initialization. Prototype of the template class is created
- when the fast allocator is created. This is instantiated with
- default (no argument) constructor. Constructor is not called for
- the allocated objects. Instead, the prototype is just memory
- copied onto the new objects. This is done for performance reasons.
+ Allocator for Class objects.
*/
-template <class C> class ClassAllocator : public Allocator
+template <class C, bool Destruct_on_free_ = false> class ClassAllocator :
private Allocator
{
public:
- /** Allocates objects of the templated type. */
+ using Value_type = C;
+ static bool const Destruct_on_free = Destruct_on_free_;
+
+ /** Allocates objects of the templated type. Arguments are forwarded to the
constructor for the object. */
+ template <typename... Args>
C *
- alloc()
+ alloc(Args &&... args)
{
void *ptr = ink_freelist_new(this->fl);
- memcpy(ptr, (void *)&this->proto.typeObject, sizeof(C));
+ ::new (ptr) C(std::forward<Args>(args)...);
Review comment:
"proto" is a data member of the class allocator, and I think they are
always statically allocated. So the raw memory for proto will be zeroed out at
load time before the proto object is constructed by placement new. We could
zero the memory here before calling placement new. If we don't, there is a
risk of seeing further crashes with this change, like the the Susan found.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]