Skip to content

Commit 1516956

Browse files
mspangpull[bot]
authored andcommitted
Make ReadClient::Callback non-movable (#29191)
The purpose of this interface is be called polymorphically through a pointer. Moving it will invalidate the original instance and is very likely to be a bug. Make this type non-movable; this will fail compilation if a derived class is stored in an inappropriate container that moves its elements. As an example, ClusterStateCache is also currently movable, but moving it retains a pointer to the moved-from instance via mBufferedReader, so any further usage is likely to result in a invalid memory access.
1 parent bd59f53 commit 1516956

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/app/ClusterStateCache.h

+13
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class ClusterStateCache : protected ReadClient::Callback
7171
class Callback : public ReadClient::Callback
7272
{
7373
public:
74+
Callback() = default;
75+
76+
// Callbacks are not expected to be copyable or movable.
77+
Callback(const Callback &) = delete;
78+
Callback(Callback &&) = delete;
79+
Callback & operator=(const Callback &) = delete;
80+
Callback & operator=(Callback &&) = delete;
81+
7482
/*
7583
* Called anytime an attribute value has changed in the cache
7684
*/
@@ -103,6 +111,11 @@ class ClusterStateCache : protected ReadClient::Callback
103111
mHighestReceivedEventNumber = highestReceivedEventNumber;
104112
}
105113

114+
ClusterStateCache(const ClusterStateCache &) = delete;
115+
ClusterStateCache(ClusterStateCache &&) = delete;
116+
ClusterStateCache & operator=(const ClusterStateCache &) = delete;
117+
ClusterStateCache & operator=(ClusterStateCache &&) = delete;
118+
106119
void SetHighestReceivedEventNumber(EventNumber highestReceivedEventNumber)
107120
{
108121
mHighestReceivedEventNumber.SetValue(highestReceivedEventNumber);

src/app/ReadClient.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ ReadClient::ReadClient(InteractionModelEngine * apImEngine, Messaging::ExchangeM
4545
mOnConnectionFailureCallback(HandleDeviceConnectionFailure, this)
4646
{
4747
mpExchangeMgr = apExchangeMgr;
48-
mpCallback = apCallback;
4948
mInteractionType = aInteractionType;
5049

5150
mpImEngine = apImEngine;

src/app/ReadClient.h

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ class ReadClient : public Messaging::ExchangeDelegate
7272
class Callback
7373
{
7474
public:
75+
Callback() = default;
76+
77+
// Callbacks are not expected to be copyable or movable.
78+
Callback(const Callback &) = delete;
79+
Callback(Callback &&) = delete;
80+
Callback & operator=(const Callback &) = delete;
81+
Callback & operator=(Callback &&) = delete;
82+
7583
virtual ~Callback() = default;
7684

7785
/**

0 commit comments

Comments
 (0)