Skip to content

Commit

Permalink
Fix capturing references to stack variables (#774)
Browse files Browse the repository at this point in the history
When strand is busy then passed function will be scheduled and execute after return from dispatch() and it's caller function and then the passed references to local variables will become dangled.

Co-authored-by: Aram Khzarjyan <[email protected]>
Co-authored-by: Sambit Patnaik <[email protected]>
  • Loading branch information
3 people authored Nov 28, 2024
1 parent e2a10a4 commit bc12493
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions implementation/configuration/src/configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ configuration_impl::configuration_impl(const configuration_impl& _other) :
sd_port_ = _other.sd_port_;
sd_protocol_ = _other.sd_protocol_;

is_suppress_events_enabled_ = _other.is_suppress_events_enabled_;

sd_initial_delay_min_ = _other.sd_initial_delay_min_;
sd_initial_delay_max_ = _other.sd_initial_delay_max_;
sd_repetitions_base_delay_= _other.sd_repetitions_base_delay_;
Expand Down
8 changes: 4 additions & 4 deletions implementation/endpoints/src/tcp_client_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void tcp_client_endpoint_impl::receive() {
its_recv_buffer = recv_buffer_;
}
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
strand_.dispatch([self, &its_recv_buffer](){
strand_.dispatch([self, its_recv_buffer](){
self->receive(its_recv_buffer, 0, 0);
});
}
Expand Down Expand Up @@ -770,7 +770,7 @@ void tcp_client_endpoint_impl::receive_cbk(
}
its_lock.unlock();
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
strand_.dispatch([self, &_recv_buffer, _recv_buffer_size, its_missing_capacity](){
strand_.dispatch([self, _recv_buffer, _recv_buffer_size, its_missing_capacity](){
self->receive(_recv_buffer, _recv_buffer_size, its_missing_capacity);
});
} else {
Expand Down Expand Up @@ -798,7 +798,7 @@ void tcp_client_endpoint_impl::receive_cbk(
} else {
its_lock.unlock();
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
strand_.dispatch([self, &_recv_buffer, _recv_buffer_size, its_missing_capacity](){
strand_.dispatch([self, _recv_buffer, _recv_buffer_size, its_missing_capacity](){
self->receive(_recv_buffer, _recv_buffer_size, its_missing_capacity);
});
}
Expand Down Expand Up @@ -948,7 +948,7 @@ void tcp_client_endpoint_impl::send_cbk(boost::system::error_code const &_error,
if (its_entry.first) {
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
strand_.dispatch(
[self, &its_entry]() { self->send_queued(its_entry);}
[self, its_entry]() mutable { self->send_queued(its_entry);}
);
}
}
Expand Down

0 comments on commit bc12493

Please sign in to comment.