Skip to content

Commit

Permalink
Fix some minor leaks in node deinitialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Asc91 committed Nov 8, 2024
1 parent 3d896a8 commit 2348835
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/esp_rainmaker/src/core/esp_rmaker_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "esp_rmaker_internal.h"

static const char *TAG = "esp_rmaker_node";
static bool node_created;

static void esp_rmaker_node_info_free(esp_rmaker_node_info_t *info)
{
Expand Down Expand Up @@ -84,6 +85,7 @@ esp_err_t esp_rmaker_node_delete(const esp_rmaker_node_t *node)
_esp_rmaker_device_t *next_device = device->next;
device->parent = NULL;
esp_rmaker_device_delete((esp_rmaker_device_t *)device);
free(device);
device = next_device;
}
/* Node ID is created in the context of esp_rmaker_init and just assigned
Expand All @@ -95,14 +97,15 @@ esp_err_t esp_rmaker_node_delete(const esp_rmaker_node_t *node)
if (_node->info) {
esp_rmaker_node_info_free(_node->info);
}
free(_node);
node_created = false;
return ESP_OK;
}
return ESP_ERR_INVALID_ARG;
}

esp_rmaker_node_t *esp_rmaker_node_create(const char *name, const char *type)
{
static bool node_created;
if (node_created) {
ESP_LOGE(TAG, "Node has already been created. Cannot create another");
return NULL;
Expand Down
7 changes: 7 additions & 0 deletions components/esp_rainmaker/src/core/esp_rmaker_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ esp_err_t esp_rmaker_param_delete(const esp_rmaker_param_t *param)
if (_param->ui_type) {
free(_param->ui_type);
}
if (_param->bounds) {
free(_param->bounds);
}
if (_param->val.type == RMAKER_VAL_TYPE_STRING || _param->val.type == RMAKER_VAL_TYPE_OBJECT ||
_param->val.type == RMAKER_VAL_TYPE_ARRAY) {
free(_param->val.val.s);
}
free(_param);
return ESP_OK;
}
Expand Down

0 comments on commit 2348835

Please sign in to comment.