Skip to content

Commit bc12493

Browse files
kheaactuaakhzarjsambit-patnaik
authored
Fix capturing references to stack variables (#774)
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]>
1 parent e2a10a4 commit bc12493

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

implementation/configuration/src/configuration_impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ configuration_impl::configuration_impl(const configuration_impl& _other) :
145145
sd_port_ = _other.sd_port_;
146146
sd_protocol_ = _other.sd_protocol_;
147147

148+
is_suppress_events_enabled_ = _other.is_suppress_events_enabled_;
149+
148150
sd_initial_delay_min_ = _other.sd_initial_delay_min_;
149151
sd_initial_delay_max_ = _other.sd_initial_delay_max_;
150152
sd_repetitions_base_delay_= _other.sd_repetitions_base_delay_;

implementation/endpoints/src/tcp_client_endpoint_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void tcp_client_endpoint_impl::receive() {
269269
its_recv_buffer = recv_buffer_;
270270
}
271271
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
272-
strand_.dispatch([self, &its_recv_buffer](){
272+
strand_.dispatch([self, its_recv_buffer](){
273273
self->receive(its_recv_buffer, 0, 0);
274274
});
275275
}
@@ -770,7 +770,7 @@ void tcp_client_endpoint_impl::receive_cbk(
770770
}
771771
its_lock.unlock();
772772
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
773-
strand_.dispatch([self, &_recv_buffer, _recv_buffer_size, its_missing_capacity](){
773+
strand_.dispatch([self, _recv_buffer, _recv_buffer_size, its_missing_capacity](){
774774
self->receive(_recv_buffer, _recv_buffer_size, its_missing_capacity);
775775
});
776776
} else {
@@ -798,7 +798,7 @@ void tcp_client_endpoint_impl::receive_cbk(
798798
} else {
799799
its_lock.unlock();
800800
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
801-
strand_.dispatch([self, &_recv_buffer, _recv_buffer_size, its_missing_capacity](){
801+
strand_.dispatch([self, _recv_buffer, _recv_buffer_size, its_missing_capacity](){
802802
self->receive(_recv_buffer, _recv_buffer_size, its_missing_capacity);
803803
});
804804
}
@@ -948,7 +948,7 @@ void tcp_client_endpoint_impl::send_cbk(boost::system::error_code const &_error,
948948
if (its_entry.first) {
949949
auto self = std::dynamic_pointer_cast< tcp_client_endpoint_impl >(shared_from_this());
950950
strand_.dispatch(
951-
[self, &its_entry]() { self->send_queued(its_entry);}
951+
[self, its_entry]() mutable { self->send_queued(its_entry);}
952952
);
953953
}
954954
}

0 commit comments

Comments
 (0)