Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ezpi 376 fix memory leak #123

Merged
merged 13 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ cpp_space_after_semicolon=false
cpp_space_remove_around_unary_operator=true
cpp_space_around_binary_operator=insert
cpp_space_around_assignment_operator=insert
cpp_space_pointer_reference_alignment=left
cpp_space_pointer_reference_alignment=ignore
cpp_space_around_ternary_operator=insert
cpp_wrap_preserve_blocks=one_liners
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<<<<<<< HEAD
*.bin.old
=======
*.old
>>>>>>> development
*.bin
firmware/**
firmware/v*/**
Expand Down
10 changes: 5 additions & 5 deletions ezlopi-cloud/ezlopi-cloud-coordinates/ezlopi_cloud_coordinates.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ static double sg_longitude;

void hub_coordinates_set(cJSON* cj_request, cJSON* cj_response)
{
cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cj_request)
{
cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
cJSON* cj_params = cJSON_GetObjectItem(__FUNCTION__, cj_request, ezlopi_params_str);
if (cj_params)
{
CJSON_GET_VALUE_DOUBLE(cj_params, ezlopi_latitude_str, sg_latitude);
CJSON_GET_VALUE_DOUBLE(cj_params, ezlopi_longitude_str, sg_longitude);

char lat_long_str[256];
if (cJSON_PrintPreallocated(cj_params, lat_long_str, sizeof(lat_long_str), false))
if (cJSON_PrintPreallocated(__FUNCTION__, cj_params, lat_long_str, sizeof(lat_long_str), false))
{
ezlopi_nvs_write_latitude_longitude(lat_long_str);
}
Expand All @@ -37,8 +37,8 @@ void hub_coordinates_get(cJSON* cj_request, cJSON* cj_response)
char* lat_long_vals = ezlopi_nvs_read_latidtude_longitude();
if (lat_long_vals)
{
cJSON_AddRawToObject(cj_response, ezlopi_result_str, lat_long_vals);
free(lat_long_vals);
cJSON_AddRawToObject(__FUNCTION__, cj_response, ezlopi_result_str, lat_long_vals);
ezlopi_free(__FUNCTION__, lat_long_vals);
}
}

Expand Down
52 changes: 26 additions & 26 deletions ezlopi-cloud/ezlopi-cloud-data/ezlopi_cloud_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

void data_list(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cjson_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
cJSON* cjson_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cjson_result)
{
cJSON* cj_settings = cJSON_AddObjectToObject(cjson_result, ezlopi_settings_str);
cJSON* cj_settings = cJSON_AddObjectToObject(__FUNCTION__, cjson_result, ezlopi_settings_str);
if (cj_settings)
{
cJSON* cj_first_start = cJSON_AddObjectToObject(cj_settings, ezlopi_first_start_str);
cJSON* cj_first_start = cJSON_AddObjectToObject(__FUNCTION__, cj_settings, ezlopi_first_start_str);
if (cj_first_start)
{
cJSON_AddNumberToObject(cj_first_start, ezlopi_value_str, 0);
cJSON_AddNumberToObject(__FUNCTION__, cj_first_start, ezlopi_value_str, 0);
}

#warning "WARNING: work required here!"
Expand All @@ -44,23 +44,23 @@ void data_list(cJSON* cj_request, cJSON* cj_response)
#if 0
static cJSON* ezlopi_cloud_data_create_device_list(void)
{
cJSON* cjson_device_list = cJSON_CreateObject();
cJSON* cjson_device_list = cJSON_CreateObject(__FUNCTION__);

if (cjson_device_list)
{
cJSON_AddNumberToObject(cjson_device_list, "ids", 1234);
cJSON_AddNumberToObject(__FUNCTION__, cjson_device_list, "ids", 1234);
}

return cjson_device_list;
}

static cJSON* ezlopi_cloud_data_create_settings_list(void)
{
cJSON* cjson_device_list = cJSON_CreateObject();
cJSON* cjson_device_list = cJSON_CreateObject(__FUNCTION__);

if (cjson_device_list)
{
cJSON_AddNumberToObject(cjson_device_list, "ids", 1234);
cJSON_AddNumberToObject(__FUNCTION__, cjson_device_list, "ids", 1234);
}

return cjson_device_list;
Expand All @@ -71,29 +71,29 @@ static cJSON* ezlopi_cloud_data_list_settings(l_ezlopi_configured_devices_t* ezl
cJSON* cjson_settings = NULL;
if (ezlopi_device)
{
cjson_settings = cJSON_CreateObject();
cjson_settings = cJSON_CreateObject(__FUNCTION__);
if (cjson_settings)
{
char tmp_string[64];
snprintf(tmp_string, sizeof(tmp_string), "%08x", ezlopi_device->properties->ezlopi_cloud.device_id);
cJSON_AddStringToObject(cjson_settings, ezlopi__id_str, tmp_string);
cJSON_AddStringToObject(cjson_settings, ezlopi_deviceTypeId_str, ezlopi_ezlopi_str);
cJSON_AddStringToObject(cjson_settings, ezlopi_parentDeviceId_str, ezlopi__str);
cJSON_AddStringToObject(cjson_settings, ezlopi_category_str, ezlopi_device->properties->ezlopi_cloud.category);
cJSON_AddStringToObject(cjson_settings, ezlopi_subcategory_str, ezlopi_device->properties->ezlopi_cloud.subcategory);
cJSON_AddBoolToObject(cjson_settings, ezlopi_batteryPowered_str, ezlopi_device->properties->ezlopi_cloud.battery_powered);
cJSON_AddStringToObject(cjson_settings, "name", ezlopi_device->properties->ezlopi_cloud.device_name);
cJSON_AddStringToObject(cjson_settings, ezlopi_type_str, ezlopi_device->properties->ezlopi_cloud.device_type);
cJSON_AddBoolToObject(cjson_settings, ezlopi_reachable_str, ezlopi_device->properties->ezlopi_cloud.reachable);
cJSON_AddBoolToObject(cjson_settings, ezlopi_persistent_str, true);
cJSON_AddBoolToObject(cjson_settings, ezlopi_serviceNotification_str, false);
cJSON_AddBoolToObject(cjson_settings, "armed", false);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi__id_str, tmp_string);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_deviceTypeId_str, ezlopi_ezlopi_str);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_parentDeviceId_str, ezlopi__str);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_category_str, ezlopi_device->properties->ezlopi_cloud.category);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_subcategory_str, ezlopi_device->properties->ezlopi_cloud.subcategory);
cJSON_AddBoolToObject(__FUNCTION__, cjson_settings, ezlopi_batteryPowered_str, ezlopi_device->properties->ezlopi_cloud.battery_powered);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, "name", ezlopi_device->properties->ezlopi_cloud.device_name);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_type_str, ezlopi_device->properties->ezlopi_cloud.device_type);
cJSON_AddBoolToObject(__FUNCTION__, cjson_settings, ezlopi_reachable_str, ezlopi_device->properties->ezlopi_cloud.reachable);
cJSON_AddBoolToObject(__FUNCTION__, cjson_settings, ezlopi_persistent_str, true);
cJSON_AddBoolToObject(__FUNCTION__, cjson_settings, ezlopi_serviceNotification_str, false);
cJSON_AddBoolToObject(__FUNCTION__, cjson_settings, "armed", false);
snprintf(tmp_string, sizeof(tmp_string), "%08x", ezlopi_device->properties->ezlopi_cloud.room_id);
cJSON_AddStringToObject(cjson_settings, ezlopi_roomId_str, tmp_string);
cJSON_AddStringToObject(cjson_settings, ezlopi_security_str, ezlopi__str);
cJSON_AddBoolToObject(cjson_settings, ezlopi_ready_str, true);
cJSON_AddStringToObject(cjson_settings, ezlopi_status_str, ezlopi_synced_str);
cJSON_AddStringToObject(cjson_settings, ezlopi_info_str, "{}");
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_roomId_str, tmp_string);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_security_str, ezlopi__str);
cJSON_AddBoolToObject(__FUNCTION__, cjson_settings, ezlopi_ready_str, true);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_status_str, ezlopi_synced_str);
cJSON_AddStringToObject(__FUNCTION__, cjson_settings, ezlopi_info_str, "{}");
}
}

Expand Down
34 changes: 17 additions & 17 deletions ezlopi-cloud/ezlopi-cloud-devices/ezlopi_cloud_devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

void devices_list_v3(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cjson_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
cJSON* cjson_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cjson_result)
{
cJSON* cjson_devices_array = cJSON_AddArrayToObject(cjson_result, "devices");
cJSON* cjson_devices_array = cJSON_AddArrayToObject(__FUNCTION__, cjson_result, "devices");
if (cjson_devices_array)
{
l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
Expand All @@ -27,7 +27,7 @@ void devices_list_v3(cJSON* cj_request, cJSON* cj_response)
{
if (!cJSON_AddItemToArray(cjson_devices_array, cj_properties))
{
cJSON_Delete(cj_properties);
cJSON_Delete(__FUNCTION__, cj_properties);
}
}
curr_device = curr_device->next;
Expand All @@ -51,19 +51,19 @@ void devices_list_v3(cJSON* cj_request, cJSON* cj_response)

void device_name_set(cJSON* cj_request, cJSON* cj_response)
{
cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
cJSON* cj_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cj_result)
{
cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
cJSON* cj_params = cJSON_GetObjectItem(__FUNCTION__, cj_request, ezlopi_params_str);
if (cj_params)
{
cJSON* cj_device_id = cJSON_GetObjectItem(cj_params, ezlopi__id_str);
cJSON* cj_device_id = cJSON_GetObjectItem(__FUNCTION__, cj_params, ezlopi__id_str);
if (cj_device_id)
{
uint32_t device_id = strtoul(cj_device_id->valuestring, NULL, 16);
if (device_id)
{
ezlopi_device_name_set_by_device_id(device_id, cJSON_GetObjectItem(cj_params, ezlopi_name_str));
ezlopi_device_name_set_by_device_id(device_id, cJSON_GetObjectItem(__FUNCTION__, cj_params, ezlopi_name_str));
}
}
}
Expand All @@ -74,16 +74,16 @@ void device_updated(cJSON* cj_request, cJSON* cj_response)
{
if (cj_request)
{
cJSON_AddStringToObject(cj_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
cJSON_AddStringToObject(cj_response, ezlopi_msg_subclass_str, "hub.device.updated");
cJSON_AddStringToObject(__FUNCTION__, cj_response, ezlopi_id_str, ezlopi_ui_broadcast_str);
cJSON_AddStringToObject(__FUNCTION__, cj_response, ezlopi_msg_subclass_str, "hub.device.updated");

cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
cJSON* cj_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
if (cj_result)
{
cJSON* cj_params = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
cJSON* cj_params = cJSON_GetObjectItem(__FUNCTION__, cj_request, ezlopi_params_str);
if (cj_params)
{
cJSON* cj_device_id = cJSON_GetObjectItem(cj_params, ezlopi__id_str);
cJSON* cj_device_id = cJSON_GetObjectItem(__FUNCTION__, cj_params, ezlopi__id_str);
if (cj_device_id && cj_device_id->valuestring)
{
uint32_t device_id = strtoul(cj_device_id->valuestring, NULL, 16);
Expand All @@ -95,16 +95,16 @@ void device_updated(cJSON* cj_request, cJSON* cj_response)
{
char tmp_str[32];
snprintf(tmp_str, sizeof(tmp_str), "%08x", device_id);
cJSON_AddStringToObject(cj_result, ezlopi__id_str, tmp_str);
cJSON_AddStringToObject(cj_result, ezlopi_name_str, device_node->cloud_properties.device_name);
cJSON_AddTrueToObject(cj_result, ezlopi_syncNotification_str);
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi__id_str, tmp_str);
cJSON_AddStringToObject(__FUNCTION__, cj_result, ezlopi_name_str, device_node->cloud_properties.device_name);
cJSON_AddTrueToObject(__FUNCTION__, cj_result, ezlopi_syncNotification_str);

s_ezlopi_cloud_controller_t* controller_info = ezlopi_device_get_controller_information();

if (controller_info)
{
cJSON_AddBoolToObject(cj_result, ezlopi_armed_str, controller_info->armed ? cJSON_True : cJSON_False);
cJSON_AddBoolToObject(cj_result, ezlopi_serviceNotification_str, controller_info->service_notification ? cJSON_True : cJSON_False);
cJSON_AddBoolToObject(__FUNCTION__, cj_result, ezlopi_armed_str, controller_info->armed ? cJSON_True : cJSON_False);
cJSON_AddBoolToObject(__FUNCTION__, cj_result, ezlopi_serviceNotification_str, controller_info->service_notification ? cJSON_True : cJSON_False);
}

break;
Expand Down
20 changes: 10 additions & 10 deletions ezlopi-cloud/ezlopi-cloud-favorite/ezlopi_cloud_favorite.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ void favorite_list_v3(cJSON* cj_request, cJSON* cj_response)
cJSON* cj_items_req = NULL;
// cJSON *cj_rules_req = NULL;

cJSON* cj_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str);
cJSON* cj_param = cJSON_GetObjectItem(cj_request, ezlopi_params_str);
cJSON* cj_result = cJSON_AddObjectToObject(__FUNCTION__, cj_response, ezlopi_result_str);
cJSON* cj_param = cJSON_GetObjectItem(__FUNCTION__, cj_request, ezlopi_params_str);

if (cj_param && cj_param->valuestring)
{
cJSON* cj_request_list = cJSON_GetObjectItem(cj_param, "request");
cJSON* cj_request_list = cJSON_GetObjectItem(__FUNCTION__, cj_param, "request");
if (cj_request_list && cj_request_list->valuestring)
{
int array_size = cJSON_GetArraySize(cj_request_list);
Expand Down Expand Up @@ -47,12 +47,12 @@ void favorite_list_v3(cJSON* cj_request, cJSON* cj_response)

if (cj_result)
{
cJSON* cj_favorites = cJSON_AddObjectToObject(cj_result, "favorites");
cJSON* cj_favorites = cJSON_AddObjectToObject(__FUNCTION__, cj_result, "favorites");
if (cj_favorites)
{
cJSON* cj_device_list = cj_devices_req ? cJSON_AddArrayToObject(cj_favorites, "devices") : NULL;
// cJSON *cj_items_list = cj_items_req ? cJSON_AddArrayToObject(cj_favorites, ezlopi_items_str) : NULL;
// cJSON *cj_rules_list = cj_rules_req ? cJSON_AddArrayToObject(cj_favorites, "rules") : NULL;
cJSON* cj_device_list = cj_devices_req ? cJSON_AddArrayToObject(__FUNCTION__, cj_favorites, "devices") : NULL;
// cJSON *cj_items_list = cj_items_req ? cJSON_AddArrayToObject(__FUNCTION__, cj_favorites, ezlopi_items_str) : NULL;
// cJSON *cj_rules_list = cj_rules_req ? cJSON_AddArrayToObject(__FUNCTION__, cj_favorites, "rules") : NULL;

l_ezlopi_device_t* curr_device = ezlopi_device_get_head();
while (curr_device)
Expand All @@ -61,14 +61,14 @@ void favorite_list_v3(cJSON* cj_request, cJSON* cj_response)
while (curr_item)
{
#warning "Needs works here [Krishna]"
cJSON* cj_device = cJSON_CreateObject();
cJSON* cj_device = cJSON_CreateObject(__FUNCTION__);
if (cj_device)
{
cJSON_AddStringToObject(cj_device, ezlopi__id_str, ezlopi__str);
cJSON_AddStringToObject(__FUNCTION__, cj_device, ezlopi__id_str, ezlopi__str);

if (!cJSON_AddItemToArray(cj_device_list, cj_device))
{
cJSON_Delete(cj_device);
cJSON_Delete(__FUNCTION__, cj_device);
}
}
curr_item = curr_item->next;
Expand Down
Loading