From 00b127c0a4b1a3faf4fd91572de71ae6d744bd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Dom=C3=ADnguez=20L=C3=B3pez?= <116071334+Mario-DL@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:04:12 +0200 Subject: [PATCH] Fix assertion in TopicPayloadPool::release_history (#5008) * Refs #21272: Fix pool configuration when type is plain changed to PREALLOCATED Signed-off-by: Mario Dominguez * Refs #21272. Keep memory mode on `pool_config_`. Signed-off-by: Miguel Company --------- Signed-off-by: Mario Dominguez Signed-off-by: Miguel Company Co-authored-by: Miguel Company --- src/cpp/fastdds/publisher/DataWriterImpl.cpp | 29 ++++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/cpp/fastdds/publisher/DataWriterImpl.cpp b/src/cpp/fastdds/publisher/DataWriterImpl.cpp index 3d40705230d..34def3139e0 100644 --- a/src/cpp/fastdds/publisher/DataWriterImpl.cpp +++ b/src/cpp/fastdds/publisher/DataWriterImpl.cpp @@ -248,6 +248,14 @@ ReturnCode_t DataWriterImpl::enable() topic_att, type_->m_typeSize, qos_.endpoint().history_memory_policy); pool_config_ = PoolConfig::from_history_attributes(history_att); + // When the user requested PREALLOCATED_WITH_REALLOC, but we know the type cannot + // grow, we translate the policy into bare PREALLOCATED + if (PREALLOCATED_WITH_REALLOC_MEMORY_MODE == pool_config_.memory_policy && + (type_->is_bounded() || type_->is_plain(data_representation_))) + { + pool_config_.memory_policy = PREALLOCATED_MEMORY_MODE; + } + WriterAttributes w_att; w_att.endpoint.durabilityKind = qos_.durability().durabilityKind(); w_att.endpoint.endpointKind = WRITER; @@ -2056,28 +2064,19 @@ std::shared_ptr DataWriterImpl::get_payload_pool() { if (!payload_pool_) { - PoolConfig config = pool_config_; - - // When the user requested PREALLOCATED_WITH_REALLOC, but we know the type cannot - // grow, we translate the policy into bare PREALLOCATED - if (PREALLOCATED_WITH_REALLOC_MEMORY_MODE == config.memory_policy && - (type_->is_bounded() || type_->is_plain(data_representation_))) - { - config.memory_policy = PREALLOCATED_MEMORY_MODE; - } - // Avoid calling the serialization size functors on PREALLOCATED mode - fixed_payload_size_ = config.memory_policy == PREALLOCATED_MEMORY_MODE ? config.payload_initial_size : 0u; + fixed_payload_size_ = + pool_config_.memory_policy == PREALLOCATED_MEMORY_MODE ? pool_config_.payload_initial_size : 0u; // Get payload pool reference and allocate space for our history if (is_data_sharing_compatible_) { - payload_pool_ = DataSharingPayloadPool::get_writer_pool(config); + payload_pool_ = DataSharingPayloadPool::get_writer_pool(pool_config_); } else { - payload_pool_ = TopicPayloadPoolRegistry::get(topic_->get_name(), config); - if (!std::static_pointer_cast(payload_pool_)->reserve_history(config, false)) + payload_pool_ = TopicPayloadPoolRegistry::get(topic_->get_name(), pool_config_); + if (!std::static_pointer_cast(payload_pool_)->reserve_history(pool_config_, false)) { payload_pool_.reset(); } @@ -2086,7 +2085,7 @@ std::shared_ptr DataWriterImpl::get_payload_pool() // Prepare loans collection for plain types only if (type_->is_plain(data_representation_)) { - loans_.reset(new LoanCollection(config)); + loans_.reset(new LoanCollection(pool_config_)); } }