cloud_server: fix heap-use-after-free error
When a resource is created in the /switches collection,
publishing to cloud is done in a scheduled task. However,
if the resource was deleted before the task executed then
the task tries to use an invalid memory.
Before deleting the resource all scheduled tasks using it
must be removed.
@@ -530,6 +530,7 @@ free_switch_instance(oc_resource_t *resource)
oc_switch_t *cswitch = (oc_switch_t *)oc_list_head(switches);
while (cswitch) {
if (cswitch->resource == resource) {
+ oc_remove_delayed_callback(cswitch->resource, register_to_cloud);
oc_cloud_delete_resource(resource);
oc_delete_resource(resource);
oc_list_remove(switches, cswitch);
