[WGID-279204] Fix a potential memory leak problem
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / zblib_plugin.c
index 8aa1fd6..48de467 100644 (file)
@@ -44,6 +44,8 @@ ZigBeePlugin *zblib_plugin_new(ZigBeeService *service,
 
        /* Allocate memory */
        plugin = g_malloc0(sizeof(ZigBeePlugin));
+       if (NULL == plugin)
+               return NULL;
 
        /* Update fields */
        plugin->plugin_name = g_strdup(plugin_name);
@@ -149,6 +151,29 @@ void zblib_plugin_link_driver(ZigBeePlugin *plugin, ZigBeeDriver *driver)
        Z_LOGD("Driver appended into plugin [%s]", plugin->plugin_name);
 }
 
+void zblib_plugin_unlink_driver(ZigBeePlugin *plugin, ZblibDriverType_e driver_type)
+{
+       ZblibDriverType_e _driver_type;
+       GSList *list = NULL;
+
+       zblib_check_null_ret("plugin", plugin);
+
+       list = plugin->driver_list;
+       while (list) {
+               /* Fetch driver type of driver */
+               _driver_type = zblib_driver_ref_driver_type((ZigBeeDriver *)(list->data));
+               if (_driver_type == driver_type) {
+                       /* Driver found */
+                       Z_LOGD("Driver[%p] removed from plugin", list->data);
+                       list->data = NULL;
+                       break;
+               }
+
+               /* Move to next driver */
+               list = g_slist_next(list);
+       }
+}
+
 gboolean zblib_plugin_dispatch_request(ZigBeePlugin *plugin,
        guint request_id)
 {
@@ -203,4 +228,4 @@ void zblib_plugin_send_notification(ZigBeePlugin *plugin,
        /* Send notification to service */
        zblib_service_send_notification(service,
                noti_id, noti_data, noti_data_len);
-}
\ No newline at end of file
+}