This is an automated email from the ASF dual-hosted git repository.

pengzheng pushed a commit to branch hotfix/dm-add-interfece-leak
in repository https://gitbox.apache.org/repos/asf/celix.git

commit acdd4b492a78dd3814a187eadc0b2241dc8f347a
Author: PengZheng <[email protected]>
AuthorDate: Fri Sep 19 14:25:52 2025 +0800

    Fix the memory leak when removing the component interface and adding the 
corresponding test
    
    - Ensure `removedInterface->properties` is destroyed in 
`dm_component_impl.c`.
    - Add `DmInterfaceAddRemove` test case to verify proper interface addition 
and removal behavior.
---
 .../gtest/src/DependencyManagerTestSuite.cc        | 27 ++++++++++++++++++++++
 libs/framework/src/dm_component_impl.c             |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/libs/framework/gtest/src/DependencyManagerTestSuite.cc 
b/libs/framework/gtest/src/DependencyManagerTestSuite.cc
index 726464c78..53d9e432c 100644
--- a/libs/framework/gtest/src/DependencyManagerTestSuite.cc
+++ b/libs/framework/gtest/src/DependencyManagerTestSuite.cc
@@ -211,6 +211,33 @@ TEST_F(DependencyManagerTestSuite, DmGetInfo) {
     celix_arrayList_destroy(infos);
 }
 
+TEST_F(DependencyManagerTestSuite, DmInterfaceAddRemove) {
+    auto *mng = celix_bundleContext_getDependencyManager(ctx);
+    auto *cmp = celix_dmComponent_create(ctx, "test1");
+
+    void *dummyInterfacePointer = (void *) 0x42;
+
+    auto *p = celix_properties_create();
+    celix_properties_set(p, "key", "value");
+    celix_dmComponent_addInterface(cmp, "test-interface", nullptr, 
dummyInterfacePointer, p);
+
+    auto *dep = celix_dmServiceDependency_create();
+    celix_dmServiceDependency_setService(dep, "test-interface", nullptr, 
nullptr);
+    celix_dmComponent_addServiceDependency(cmp, dep);
+
+    celix_dependencyManager_add(mng, cmp);
+
+    celix_dmComponent_removeInterface(cmp, dummyInterfacePointer);
+
+    auto *infos = celix_dependencyManager_createInfos(mng);
+    ASSERT_EQ(1, celix_arrayList_size(infos));
+    auto *dmInfo = (celix_dependency_manager_info_t *) 
celix_arrayList_get(infos, 0);
+    ASSERT_EQ(1, celix_arrayList_size(dmInfo->components));
+    auto *info = (celix_dm_component_info_t *) 
celix_arrayList_get(dmInfo->components, 0);
+    EXPECT_EQ(0, celix_arrayList_size(info->interfaces));
+    celix_arrayList_destroy(infos);
+}
+
 TEST_F(DependencyManagerTestSuite, TestCheckActive) {
     auto *mng = celix_bundleContext_getDependencyManager(ctx);
     auto *cmp = celix_dmComponent_create(ctx, "test1");
diff --git a/libs/framework/src/dm_component_impl.c 
b/libs/framework/src/dm_component_impl.c
index f41c0f7f0..778552f78 100644
--- a/libs/framework/src/dm_component_impl.c
+++ b/libs/framework/src/dm_component_impl.c
@@ -521,6 +521,9 @@ celix_status_t 
celix_dmComponent_removeInterface(celix_dm_component_t *component
 
     if (removedInterface != NULL) {
         celix_bundleContext_unregisterService(component->context, 
removedInterface->svcId);
+        if (removedInterface->properties != NULL) {
+            celix_properties_destroy(removedInterface->properties);
+        }
         free(removedInterface->serviceName);
         free(removedInterface);
     }

Reply via email to