Fix memory leak when destroying ModeBase delegates (#28267)
* Fixes #28265
* Fixed typo.
diff --git a/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp
index c96ec29..65de4f9 100644
--- a/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp
+++ b/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp
@@ -85,7 +85,8 @@
}
if (gDishwasherModeDelegate != nullptr)
{
- gDishwasherModeDelegate->~DishwasherModeDelegate();
+ delete gDishwasherModeDelegate;
+ gDishwasherModeDelegate = nullptr;
}
}
diff --git a/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp
index 9d05b4b..bf53372 100644
--- a/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp
+++ b/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp
@@ -84,7 +84,8 @@
}
if (gLaundryWasherModeDelegate != nullptr)
{
- gLaundryWasherModeDelegate->~LaundryWasherModeDelegate();
+ delete gLaundryWasherModeDelegate;
+ gLaundryWasherModeDelegate = nullptr;
}
}
diff --git a/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp b/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp
index 9a95054..81fa549 100644
--- a/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp
+++ b/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp
@@ -97,7 +97,8 @@
}
if (gRvcRunModeDelegate != nullptr)
{
- gRvcRunModeDelegate->~RvcRunModeDelegate();
+ delete gRvcRunModeDelegate;
+ gRvcRunModeDelegate = nullptr;
}
}
@@ -180,7 +181,8 @@
}
if (gRvcCleanModeDelegate != nullptr)
{
- gRvcCleanModeDelegate->~RvcCleanModeDelegate();
+ delete gRvcCleanModeDelegate;
+ gRvcCleanModeDelegate = nullptr;
}
}
diff --git a/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp
index 30b8c03..8f3c865 100644
--- a/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp
+++ b/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp
@@ -84,7 +84,8 @@
}
if (gTccModeDelegate != nullptr)
{
- gTccModeDelegate->~TccModeDelegate();
+ delete gTccModeDelegate;
+ gTccModeDelegate = nullptr;
}
}
diff --git a/src/app/clusters/mode-base-server/mode-base-server.h b/src/app/clusters/mode-base-server/mode-base-server.h
index 3e1b77b..b75eeb8 100644
--- a/src/app/clusters/mode-base-server/mode-base-server.h
+++ b/src/app/clusters/mode-base-server/mode-base-server.h
@@ -241,7 +241,7 @@
// todo change once there is a clear public interface for the OnOff cluster data dependencies (#27508)
static IntrusiveList<Instance> gModeBaseAliasesInstances;
-// This does not return a refernce to const IntrusiveList, because the caller might need
+// This does not return a reference to const IntrusiveList, because the caller might need
// to change the state of the instances in the list and const IntrusiveList only allows
// access to const Instance.
IntrusiveList<Instance> & GetModeBaseInstanceList();