Fix some notifications memory leak

This commit is contained in:
Omar Kallel 2021-08-11 10:33:42 +01:00
parent f8bcdb5af1
commit 30795d2be5
3 changed files with 18 additions and 10 deletions

View file

@ -425,7 +425,7 @@ int cwmp_uci_get_section_type(char *package, char *section, char **value)
return -1;
}
if (ptr.s) {
*value = strdup(ptr.s->type);
*value = icwmp_strdup(ptr.s->type);
} else {
*value = "";
return -1;
@ -450,7 +450,7 @@ char *cwmp_uci_add_section(char *package, char *stype, struct uci_section **s)
}
if (cwmp_uci_lookup_ptr(cwmp_uci_ctx, &ptr, package, NULL, NULL, NULL) == 0
&& uci_add_section(cwmp_uci_ctx, ptr.p, stype, s) == UCI_OK) {
val = strdup((*s)->e.name);
val = icwmp_strdup((*s)->e.name);
}
return val;
}

View file

@ -79,7 +79,7 @@ int add_uci_option_notification(char *parameter_name, int notification)
int ret = 0;
cwmp_uci_init(UCI_STANDARD_CONFIG);
ret =cwmp_uci_get_section_type("cwmp", "@notifications[0]", &notification_type);
ret = cwmp_uci_get_section_type("cwmp", "@notifications[0]", &notification_type);
if (notification_type == NULL || notification_type[0] == '\0') {
cwmp_uci_add_section("cwmp", "notifications", &s);
}
@ -401,7 +401,7 @@ int check_value_change(void)
int int_ret = 0;
struct blob_buf bbuf;
char *parameter = NULL, *value = NULL, *type = NULL;
char *parameter = NULL, *value = NULL;
int notification = 0;
fp = fopen(DM_ENABLED_NOTIFY, "r");
if (fp == NULL)
@ -427,14 +427,14 @@ int check_value_change(void)
blobmsg_parse(p, 4, tb, blobmsg_data(bbuf.head), blobmsg_len(bbuf.head));
parameter = blobmsg_get_string(tb[0]);
notification = blobmsg_get_u32(tb[1]);
type = blobmsg_get_string(tb[2]);
//type = blobmsg_get_string(tb[2]);
value = blobmsg_get_string(tb[3]);
get_parameter_value_from_parameters_list(&list_notify_params, parameter, &dm_value, &dm_type);
if (dm_value == NULL && dm_type == NULL){
blob_buf_free(&bbuf);
parameter = NULL;
notification = 0;
type = NULL;
//type = NULL;
value = NULL;
continue;
}
@ -456,7 +456,7 @@ int check_value_change(void)
FREE(dm_type);
parameter = NULL;
notification = 0;
type = NULL;
//type = NULL;
value = NULL;
blob_buf_free(&bbuf);
}

View file

@ -22,6 +22,15 @@
*/
char *notifications_test[7] = {"disabled" , "passive", "active", "passive_lw", "passive_passive_lw", "active_lw", "passive_active_lw"};
LIST_HEAD(parameters_list);
static int cwmp_notifications_unit_tests_clean(void **state)
{
icwmp_cleanmem();
cwmp_free_all_dm_parameter_list(&parameters_list);
return 0;
}
int check_notify_file(char *param, int *ret_notification)
{
FILE *fp;
@ -42,6 +51,7 @@ int check_notify_file(char *param, int *ret_notification)
*ret_notification = atoi(notification);
}
}
fclose(fp);
return nbre_iterations;
}
@ -109,7 +119,6 @@ static void cwmp_update_notify_file_unit_test_default(void **state)
static void cwmp_get_parameter_attribute_unit_test_default(void **state)
{
LIST_HEAD(parameters_list);
char *err = NULL;
err = cwmp_get_parameter_attributes("Device.DeviceInfo.SoftwareVersion", &parameters_list);
@ -182,7 +191,6 @@ static void cwmp_set_parameter_attributes_parameter_sub_parameter_1_unit_test(vo
static void cwmp_get_parameter_attributes_parameter_sub_parameter_1_unit_test(void **state)
{
LIST_HEAD(parameters_list);
char *err = NULL;
err = cwmp_get_parameter_attributes("Device.DeviceInfo.UpTime", &parameters_list);
@ -248,5 +256,5 @@ int main(void)
cmocka_unit_test(cwmp_check_value_change_1_unit_test),
};
return cmocka_run_group_tests(tests, NULL, NULL);
return cmocka_run_group_tests(tests, NULL, cwmp_notifications_unit_tests_clean);
}