Skip to content

Commit

Permalink
application: Matter Bridge: fixed possible memory leaks
Browse files Browse the repository at this point in the history
- Added missing virtual constructor in abstract
  BridedDeviceDataProvider class.
- stop the timer in data provider when object is being destructed
- added more logs

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
  • Loading branch information
markaj-nordic authored and rlubos committed Aug 4, 2023
1 parent 4bd26e9 commit 969bad4
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void HumiditySensorDataProvider::NotifyUpdateState(chip::ClusterId clusterId, ch
CHIP_ERROR HumiditySensorDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
LOG_INF("Updating state of the HumiditySensorDataProvider, cluster ID: %u, attribute ID: %u. Dropping, currently not supported.",
clusterId, attributeId);
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HumiditySensorDataProvider : public BridgedDeviceDataProvider {
static constexpr uint16_t kMaxRandomTemperature = 50;

HumiditySensorDataProvider(UpdateAttributeCallback callback) : BridgedDeviceDataProvider(callback) {}
~HumiditySensorDataProvider() { k_timer_stop(&mTimer); }

void Init() override;
void NotifyUpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ CHIP_ERROR OnOffLightDataProvider::UpdateState(chip::ClusterId clusterId, chip::
return CHIP_ERROR_INVALID_ARGUMENT;
}

LOG_INF("Updating state of the OnOffLightDataProvider, cluster ID: %u, attribute ID: %u.", clusterId,
attributeId);

switch (attributeId) {
case Clusters::OnOff::Attributes::OnOff::Id: {
mOnOff = *buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class OnOffLightDataProvider : public BridgedDeviceDataProvider {
static constexpr uint16_t kOnOffIntervalMs = 30000;

OnOffLightDataProvider(UpdateAttributeCallback callback) : BridgedDeviceDataProvider(callback) {}
~OnOffLightDataProvider() { k_timer_stop(&mTimer); }

void Init() override;
void NotifyUpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void TemperatureSensorDataProvider::NotifyUpdateState(chip::ClusterId clusterId,
CHIP_ERROR TemperatureSensorDataProvider::UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId,
uint8_t *buffer)
{
LOG_INF("Updating state of the TemperatureSensorDataProvider, cluster ID: %u, attribute ID: %u. Dropping, currently not supported.",
clusterId, attributeId);
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TemperatureSensorDataProvider : public BridgedDeviceDataProvider {
static constexpr int16_t kMaxRandomTemperature = 10;

TemperatureSensorDataProvider(UpdateAttributeCallback callback) : BridgedDeviceDataProvider(callback) {}
~TemperatureSensorDataProvider() { k_timer_stop(&mTimer); }

void Init() override;
void NotifyUpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BridgedDeviceDataProvider {
chip::AttributeId attributeId, void *data, size_t dataSize);

explicit BridgedDeviceDataProvider(UpdateAttributeCallback callback) { mUpdateAttributeCallback = callback; }
virtual ~BridgedDeviceDataProvider() = default;

virtual void Init() = 0;
virtual void NotifyUpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
Expand Down

0 comments on commit 969bad4

Please sign in to comment.