Skip to content

Commit 88486fe

Browse files
committed
Fix some minor leaks in node deinitialisation
1 parent 18d133e commit 88486fe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

components/esp_rainmaker/src/core/esp_rmaker_node.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "esp_rmaker_internal.h"
2828

2929
static const char *TAG = "esp_rmaker_node";
30+
static bool node_created;
3031

3132
static void esp_rmaker_node_info_free(esp_rmaker_node_info_t *info)
3233
{
@@ -84,6 +85,7 @@ esp_err_t esp_rmaker_node_delete(const esp_rmaker_node_t *node)
8485
_esp_rmaker_device_t *next_device = device->next;
8586
device->parent = NULL;
8687
esp_rmaker_device_delete((esp_rmaker_device_t *)device);
88+
free(device);
8789
device = next_device;
8890
}
8991
/* Node ID is created in the context of esp_rmaker_init and just assigned
@@ -95,14 +97,15 @@ esp_err_t esp_rmaker_node_delete(const esp_rmaker_node_t *node)
9597
if (_node->info) {
9698
esp_rmaker_node_info_free(_node->info);
9799
}
100+
free(_node);
101+
node_created = false;
98102
return ESP_OK;
99103
}
100104
return ESP_ERR_INVALID_ARG;
101105
}
102106

103107
esp_rmaker_node_t *esp_rmaker_node_create(const char *name, const char *type)
104108
{
105-
static bool node_created;
106109
if (node_created) {
107110
ESP_LOGE(TAG, "Node has already been created. Cannot create another");
108111
return NULL;

components/esp_rainmaker/src/core/esp_rmaker_param.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ esp_err_t esp_rmaker_param_delete(const esp_rmaker_param_t *param)
533533
if (_param->ui_type) {
534534
free(_param->ui_type);
535535
}
536+
if (_param->bounds) {
537+
free(_param->bounds);
538+
}
539+
if (_param->val.type == RMAKER_VAL_TYPE_STRING || _param->val.type == RMAKER_VAL_TYPE_OBJECT ||
540+
_param->val.type == RMAKER_VAL_TYPE_ARRAY) {
541+
free(_param->val.val.s);
542+
}
536543
free(_param);
537544
return ESP_OK;
538545
}

0 commit comments

Comments
 (0)