Fix some memory mngment issues

This commit is contained in:
Omar Kallel 2021-03-05 15:31:40 +01:00
parent 934a0cf1e3
commit 3bd3f9093b
8 changed files with 89 additions and 157 deletions

View file

@ -165,22 +165,6 @@ error:
return -1;
}
void cwmp_json_obj_init(char *str, json_object **obj)
{
if (*obj) {
json_object_put(*obj);
*obj = NULL;
}
*obj = json_tokener_parse(str);
}
void cwmp_json_obj_clean(json_object **obj)
{
if (*obj) {
json_object_put(*obj);
*obj = NULL;
}
}
void cwmp_add_json_obj(json_object *json_obj_out, char *object, char *string)
{
if (object != NULL && string != NULL) {
@ -207,14 +191,3 @@ void cwmp_json_fprintf(FILE *fp, int argc, struct cwmp_json_arg cwmp_arg[])
json_object_put(json_obj_out);
}
void cwmp_json_get_string(json_object *obj, char *key, char **value)
{
json_object *key_obj = NULL;
json_object_object_get_ex(obj, key, &key_obj);
*value = strdup(key_obj ? (char *)json_object_get_string(key_obj) : "");
if (key_obj) {
json_object_put(key_obj);
key_obj = NULL;
}
}

View file

@ -13,10 +13,7 @@
#include "cwmp_uci.h"
struct uci_paths uci_save_conf_paths[] = {
[UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci" },
[UCI_DB_CONFIG] = { "/lib/db/config", NULL },
[UCI_BOARD_DB_CONFIG] = { "/etc/board-db/config", NULL },
[UCI_VARSTATE_CONFIG] = { NULL, "/var/state" },
[UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci" }, [UCI_DB_CONFIG] = { "/lib/db/config", NULL }, [UCI_BOARD_DB_CONFIG] = { "/etc/board-db/config", NULL }, [UCI_VARSTATE_CONFIG] = { NULL, "/var/state" },
};
struct uci_context *cwmp_uci_ctx = ((void *)0);
@ -270,6 +267,7 @@ int cwmp_uci_get_value_common(char *cmd, char **value, bool state)
*value = NULL;
if (!c) {
CWMP_LOG(ERROR, "Out of memory");
uci_free_context(c);
return CWMP_GEN_ERR;
}
if (state) {

View file

@ -19,6 +19,7 @@ json_object *old_global_json_obj = NULL;
json_object *actual_global_json_obj = NULL;
json_object *old_list_notify = NULL;
json_object *actual_list_notify = NULL;
json_object *str_json_parse_object = NULL;
/*
* Transaction Functions
@ -29,6 +30,7 @@ int cwmp_transaction_start(char *app)
json_object *transaction_ret = NULL, *status_obj = NULL, *transaction_id_obj = NULL;
int e = cwmp_ubus_call("usp.raw", "transaction_start", CWMP_UBUS_ARGS{ { "app", {.str_val = app }, UBUS_String } }, 1, &transaction_ret);
if (e != 0) {
FREE_JSON(transaction_ret)
CWMP_LOG(INFO, "Transaction start failed: Ubus err code: %d", e);
return 0;
}
@ -36,20 +38,16 @@ int cwmp_transaction_start(char *app)
if (strcmp((char *)json_object_get_string(status_obj), "true") != 0) {
json_object *error = NULL;
json_object_object_get_ex(transaction_ret, "error", &error);
FREE_JSON(status_obj)
FREE_JSON(error)
FREE_JSON(transaction_ret)
CWMP_LOG(INFO, "Transaction start failed: %s\n", (char *)json_object_get_string(error));
FREE_JSON(transaction_ret)
return 0;
}
FREE_JSON(status_obj)
json_object_object_get_ex(transaction_ret, "transaction_id", &transaction_id_obj);
if (transaction_id_obj == NULL) {
FREE_JSON(transaction_ret)
return 0;
}
transaction_id = atoi((char *)json_object_get_string(transaction_id_obj));
FREE_JSON(transaction_id_obj)
FREE_JSON(transaction_ret)
return 1;
}
@ -60,6 +58,7 @@ int cwmp_transaction_commit()
json_object *transaction_ret = NULL, *status_obj = NULL;
int e = cwmp_ubus_call("usp.raw", "transaction_commit", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, &transaction_ret);
if (e != 0) {
FREE_JSON(transaction_ret)
CWMP_LOG(INFO, "Transaction commit failed: Ubus err code: %d", e)
return 0;
}
@ -69,14 +68,11 @@ int cwmp_transaction_commit()
json_object_object_get_ex(transaction_ret, "error", &error);
CWMP_LOG(INFO, "Transaction commit failed: %s\n", (char *)json_object_get_string(error));
transaction_id = 0;
FREE_JSON(status_obj)
FREE_JSON(error)
FREE_JSON(transaction_ret)
return 0;
}
transaction_id = 0;
FREE_JSON(status_obj)
FREE_JSON(transaction_ret)
transaction_id = 0;
return 1;
}
@ -86,6 +82,7 @@ int cwmp_transaction_abort()
json_object *transaction_ret = NULL, *status_obj = NULL;
int e = cwmp_ubus_call("usp.raw", "transaction_abort", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, &transaction_ret);
if (e != 0) {
FREE_JSON(transaction_ret)
CWMP_LOG(INFO, "Transaction abort failed: Ubus err code: %d", e);
return 0;
}
@ -94,13 +91,9 @@ int cwmp_transaction_abort()
json_object *error = NULL;
json_object_object_get_ex(transaction_ret, "error", &error);
CWMP_LOG(INFO, "Transaction abort failed: %s\n", (char *)json_object_get_string(error));
FREE_JSON(status_obj)
FREE_JSON(error)
FREE_JSON(transaction_ret)
return 0;
}
FREE_JSON(status_obj)
FREE_JSON(transaction_ret)
return 1;
}
@ -116,36 +109,31 @@ int cwmp_transaction_status()
json_object_object_get_ex(transaction_ret, "status", &status_obj);
if (!status_obj || strcmp((char *)json_object_get_string(status_obj), "on-going") != 0) {
CWMP_LOG(INFO, "Transaction with id: %d is not available anymore\n", transaction_id);
FREE_JSON(status_obj)
FREE_JSON(transaction_ret)
return 0;
}
FREE_JSON(status_obj)
FREE_JSON(transaction_ret)
return 1;
}
/*
* RPC Methods Functions
*/
char *cwmp_get_parameter_values(char *parameter_name, json_object **parameters)
{
json_object *params_obj = NULL;
char *fault = NULL;
int e = cwmp_ubus_call("usp.raw", "get", CWMP_UBUS_ARGS{ { "path", {.str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String } }, 1, &params_obj);
if (e < 0 || params_obj == NULL) {
int e = cwmp_ubus_call("usp.raw", "get", CWMP_UBUS_ARGS{ { "path", {.str_val = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name }, UBUS_String } }, 1, &str_json_parse_object);
if (e < 0 || str_json_parse_object == NULL) {
*parameters = NULL;
return "9002";
}
json_object *fault_code = NULL;
json_object_object_get_ex(params_obj, "fault", &fault_code);
json_object_object_get_ex(str_json_parse_object, "fault", &fault_code);
if (fault_code != NULL) {
*parameters = NULL;
fault = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
FREE_JSON(params_obj)
return fault;
}
json_object_object_get_ex(params_obj, "parameters", parameters);
json_object_object_get_ex(str_json_parse_object, "parameters", parameters);
return NULL;
}
@ -163,8 +151,6 @@ char *cwmp_set_parameter_value(char *parameter_name, char *value, char *paramete
json_object_object_get_ex(set_res, "fault", &fault_code);
if (fault_code != NULL) {
fault = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
FREE_JSON(set_res)
return fault;
}
json_object *status = NULL;
@ -176,8 +162,6 @@ char *cwmp_set_parameter_value(char *parameter_name, char *value, char *paramete
json_object *flag_obj = NULL;
json_object_object_get_ex(set_res, "flag", &flag_obj);
*flag = flag_obj ? atoi((char *)json_object_get_string(flag_obj)) : 0;
FREE_JSON(flag_obj)
FREE_JSON(status)
FREE_JSON(set_res)
return NULL;
}
@ -185,8 +169,10 @@ char *cwmp_set_parameter_value(char *parameter_name, char *value, char *paramete
json_object *parameters = NULL;
json_object_object_get_ex(set_res, "parameters", &parameters);
if (!parameters)
return "9002";
if (!parameters) {
FREE_JSON(set_res)
return strdup("9002");
}
json_object *param_obj = json_object_array_get_idx(parameters, 0);
json_object_object_get_ex(param_obj, "status", &status);
@ -194,26 +180,29 @@ char *cwmp_set_parameter_value(char *parameter_name, char *value, char *paramete
if (status_str && strcmp(status_str, "false") == 0) {
json_object *fault = NULL;
json_object_object_get_ex(param_obj, "fault", &fault);
return (char *)json_object_get_string(fault);
char *fault_code = strdup(fault ? (char *)json_object_get_string(fault) : "");
FREE_JSON(set_res)
return fault_code;
}
FREE_JSON(set_res)
return NULL;
}
char *cwmp_set_multiple_parameters_values(struct list_head parameters_values_list, char *parameter_key, int *flag, json_object **faults_array)
{
json_object *set_res;
int e = cwmp_ubus_call("usp.raw", "setm_values", CWMP_UBUS_ARGS{ { "pv_tuple", {.param_value_list = &parameters_values_list }, UBUS_List_Param }, { "key", {.str_val = parameter_key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3, &set_res);
if (e < 0 || set_res == NULL)
int e = cwmp_ubus_call("usp.raw", "setm_values", CWMP_UBUS_ARGS{ { "pv_tuple", {.param_value_list = &parameters_values_list }, UBUS_List_Param }, { "key", {.str_val = parameter_key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3,
&str_json_parse_object);
if (e < 0 || str_json_parse_object == NULL)
return "9002";
json_object *status = NULL;
json_object_object_get_ex(set_res, "status", &status);
json_object_object_get_ex(str_json_parse_object, "status", &status);
char *status_str = NULL;
if (status) {
status_str = (char *)json_object_get_string(status);
if (status_str && strcmp(status_str, "true") == 0) {
json_object *flag_obj = NULL;
json_object_object_get_ex(set_res, "flag", &flag_obj);
json_object_object_get_ex(str_json_parse_object, "flag", &flag_obj);
*flag = flag_obj ? atoi((char *)json_object_get_string(flag_obj)) : 0;
free(status_str);
status_str = NULL;
@ -224,7 +213,7 @@ char *cwmp_set_multiple_parameters_values(struct list_head parameters_values_lis
status_str = NULL;
}
}
json_object_object_get_ex(set_res, "parameters", faults_array);
json_object_object_get_ex(str_json_parse_object, "parameters", faults_array);
return "Fault";
}
@ -234,13 +223,14 @@ char *cwmp_add_object(char *object_name, char *key, char **instance)
char *err = NULL;
int e = cwmp_ubus_call("usp.raw", "add_object", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "key", {.str_val = key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3, &add_res);
if (e < 0 || add_res == NULL)
if (e < 0 || add_res == NULL) {
FREE_JSON(add_res)
return "9002";
}
json_object *fault_code = NULL;
json_object_object_get_ex(add_res, "fault", &fault_code);
if (fault_code != NULL) {
err = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
FREE_JSON(add_res)
return err;
}
@ -256,15 +246,12 @@ char *cwmp_add_object(char *object_name, char *key, char **instance)
json_object_object_get_ex(param_obj, "fault", &fault);
if (fault) {
err = strdup((char *)json_object_get_string(fault));
FREE_JSON(parameters)
FREE_JSON(fault)
FREE_JSON(add_res)
return err;
}
json_object *instance_obj = NULL;
json_object_object_get_ex(param_obj, "instance", &instance_obj);
*instance = strdup((char *)json_object_get_string(instance_obj));
FREE_JSON(instance_obj)
FREE_JSON(add_res)
return NULL;
}
@ -275,13 +262,14 @@ char *cwmp_delete_object(char *object_name, char *key)
char *err = NULL;
int e = cwmp_ubus_call("usp.raw", "del_object", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "key", {.str_val = key }, UBUS_String }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 3, &del_res);
if (e < 0 || del_res == NULL)
if (e < 0 || del_res == NULL) {
FREE_JSON(del_res)
return "9002";
}
json_object *fault_code = NULL;
json_object_object_get_ex(del_res, "fault", &fault_code);
if (fault_code != NULL) {
err = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
FREE_JSON(del_res)
return err;
}
@ -295,67 +283,55 @@ char *cwmp_delete_object(char *object_name, char *key)
json_object *fault = NULL;
json_object_object_get_ex(param_obj, "fault", &fault);
err = strdup((char *)json_object_get_string(fault));
FREE_JSON(fault)
FREE_JSON(status)
FREE_JSON(del_res)
return err;
}
FREE_JSON(status)
FREE_JSON(del_res)
return NULL;
}
char *cwmp_get_parameter_names(char *object_name, bool next_level, json_object **parameters)
{
json_object *get_name_res;
char *err = NULL;
int e = cwmp_ubus_call("usp.raw", "object_names", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "next-level", {.bool_val = next_level }, UBUS_Bool } }, 2, &get_name_res);
if (e < 0 || get_name_res == NULL)
int e = cwmp_ubus_call("usp.raw", "object_names", CWMP_UBUS_ARGS{ { "path", {.str_val = object_name }, UBUS_String }, { "next-level", {.bool_val = next_level }, UBUS_Bool } }, 2, &str_json_parse_object);
if (e < 0 || str_json_parse_object == NULL)
return "9002";
json_object *fault_code = NULL;
json_object_object_get_ex(get_name_res, "fault", &fault_code);
json_object_object_get_ex(str_json_parse_object, "fault", &fault_code);
if (fault_code != NULL) {
*parameters = NULL;
err = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
FREE_JSON(get_name_res)
return err;
}
json_object_object_get_ex(get_name_res, "parameters", parameters);
json_object_object_get_ex(str_json_parse_object, "parameters", parameters);
return NULL;
}
char *cwmp_get_parameter_attributes(char *parameter_name, json_object **parameters)
{
json_object *get_attributes_res = NULL;
char *err = NULL;
int e = cwmp_ubus_call("usp.raw", "getm_attributes", CWMP_UBUS_ARGS{ { "paths", {.array_value = { {.str_value = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name } } }, UBUS_Array_Str } }, 1, &get_attributes_res);
if (e < 0 || get_attributes_res == NULL)
int e = cwmp_ubus_call("usp.raw", "getm_attributes", CWMP_UBUS_ARGS{ { "paths", {.array_value = { {.str_value = !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name } } }, UBUS_Array_Str } }, 1, &str_json_parse_object);
if (e < 0 || str_json_parse_object == NULL)
return "9002";
json_object *fault_code = NULL;
json_object_object_get_ex(get_attributes_res, "fault", &fault_code);
json_object_object_get_ex(str_json_parse_object, "fault", &fault_code);
if (fault_code != NULL) {
*parameters = NULL;
err = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
FREE_JSON(get_attributes_res)
return err;
}
json_object_object_get_ex(get_attributes_res, "parameters", parameters);
json_object_object_get_ex(str_json_parse_object, "parameters", parameters);
json_object *fault = NULL, *param_obj = NULL;
foreach_jsonobj_in_array(param_obj, *parameters)
{
json_object_object_get_ex(param_obj, "fault", &fault);
if (fault) {
err = strdup((char *)json_object_get_string(fault));
FREE_JSON(fault)
FREE_JSON(*parameters)
break;
}
}
FREE_JSON(param_obj)
return err;
}
@ -366,19 +342,17 @@ char *cwmp_set_parameter_attributes(char *parameter_name, char *notification)
int e = cwmp_ubus_call("usp.raw", "setm_attributes",
CWMP_UBUS_ARGS{ { "paths", {.array_value = { {.param_value = { "path", parameter_name } }, {.param_value = { "notify-type", notification } }, {.param_value = { "notify", "1" } } } }, UBUS_Array_Obj }, { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } },
2, &set_attribute_res);
if (e < 0 || set_attribute_res == NULL)
if (e < 0 || set_attribute_res == NULL) {
FREE_JSON(set_attribute_res)
return "9002";
}
json_object *parameters = NULL;
json_object_object_get_ex(set_attribute_res, "parameters", &parameters);
json_object *param_obj = json_object_array_get_idx(parameters, 0);
json_object *fault_code = NULL;
json_object_object_get_ex(param_obj, "fault", &fault_code);
if (fault_code != NULL) {
if (fault_code != NULL)
err = strdup((char *)json_object_get_string(fault_code));
FREE_JSON(fault_code)
}
FREE_JSON(param_obj)
FREE_JSON(parameters)
FREE_JSON(set_attribute_res)
return err;
}
@ -391,14 +365,12 @@ int cwmp_update_enabled_list_notify(int instance_mode, int notify_type)
int e;
CWMP_LOG(DEBUG, "Get List Notify for %s paramters values", notify_type == OLD_LIST_NOTIFY ? "old" : "actual");
if (notify_type == OLD_LIST_NOTIFY) {
FREE_JSON(old_list_notify)
FREE_JSON(old_global_json_obj)
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{ { "instance_mode", {.int_val = instance_mode }, UBUS_Integer } }, 1, &old_global_json_obj);
if (e)
return e;
json_object_object_get_ex(old_global_json_obj, "parameters", &old_list_notify);
} else {
FREE_JSON(actual_list_notify)
FREE_JSON(actual_global_json_obj)
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{ { "instance_mode", {.int_val = instance_mode }, UBUS_Integer } }, 1, &actual_global_json_obj);
if (e)

View file

@ -30,9 +30,6 @@ int cwmp_handle_upload_fault(char *msg);
int cwmp_handle_dustate_change_fault(char *msg);
int cwmp_handle_uninstall_fault(char *msg);
void cwmp_json_fprintf(FILE *fp, int argc, struct cwmp_json_arg cwmp_arg[]);
void cwmp_json_get_string(json_object *obj, char *key, char **value);
void cwmp_json_obj_init(char *str, json_object **obj);
void cwmp_json_obj_clean(json_object **obj);
#define foreach_jsonobj_in_array(param_obj, parameters) \
int k, array_length = json_object_array_length(parameters); \

View file

@ -10,6 +10,7 @@ extern json_object *old_global_json_obj;
extern json_object *actual_global_json_obj;
extern json_object *old_list_notify;
extern json_object *actual_list_notify;
extern json_object *str_json_parse_object;
enum notify_type
{

View file

@ -81,42 +81,33 @@ int check_value_change(void)
struct cwmp_dm_parameter *dm_parameter = NULL;
json_object *buf_json_obj = NULL, *param_name_obj = NULL, *value_obj = NULL, *notification_obj = NULL;
int is_notify = 0;
fp = fopen(DM_ENABLED_NOTIFY, "r");
if (fp == NULL)
return false;
cwmp_update_enabled_list_notify(cwmp->conf.instance_mode, ACTUAL_LIST_NOTIFY);
while (fgets(buf, 512, fp) != NULL) {
int len = strlen(buf);
if (len)
buf[len - 1] = '\0';
cwmp_json_obj_init(buf, &buf_json_obj);
buf_json_obj = json_tokener_parse(buf);
json_object_object_get_ex(buf_json_obj, "parameter", &param_name_obj);
if (param_name_obj == NULL || strlen((char *)json_object_get_string(param_name_obj)) <= 0)
if (param_name_obj == NULL || strlen((char *)json_object_get_string(param_name_obj)) <= 0) {
FREE_JSON(buf_json_obj)
continue;
}
parameter = strdup((char *)json_object_get_string(param_name_obj));
json_object_object_get_ex(buf_json_obj, "value", &value_obj);
json_object_object_get_ex(buf_json_obj, "notification", &notification_obj);
value = strdup(value_obj ? (char *)json_object_get_string(value_obj) : "");
notification = strdup(notification_obj ? (char *)json_object_get_string(notification_obj) : "");
cwmp_json_obj_clean(&buf_json_obj);
if (param_name_obj) {
json_object_put(param_name_obj);
param_name_obj = NULL;
}
if (value_obj) {
json_object_put(value_obj);
value_obj = NULL;
}
if (notification_obj) {
json_object_put(notification_obj);
notification_obj = NULL;
}
FREE_JSON(buf_json_obj)
get_parameter_value_from_parameters_list(actual_list_notify, parameter, &dm_parameter);
if (dm_parameter == NULL)
if (dm_parameter == NULL) {
FREE(value);
FREE(notification);
FREE(parameter);
continue;
}
if (notification && (strlen(notification) > 0) && (notification[0] >= '1') && (dm_parameter->data != NULL) && (value != NULL) && (strcmp(dm_parameter->data, value) != 0)) {
if (notification[0] == '1' || notification[0] == '2')
add_list_value_change(parameter, dm_parameter->data, dm_parameter->type);

2
ubus.c
View file

@ -26,6 +26,7 @@
#include "cwmp_time.h"
#include "event.h"
#include "backupSession.h"
#include "cwmp_json.h"
static struct ubus_context *ctx = NULL;
static struct blob_buf b;
@ -320,7 +321,6 @@ static void receive_ubus_call_result_data(struct ubus_request *req __attribute__
json_res = NULL;
return;
}
json_res = json_tokener_parse(str);
free((char *)str);
}

64
xml.c
View file

@ -566,6 +566,7 @@ static int xml_prepare_parameters_inform(struct cwmp_dm_parameter *dm_parameter,
} else if (!b && dm_parameter->data == NULL) {
json_object *parameters = NULL;
cwmp_get_parameter_values(dm_parameter->name, &parameters);
FREE_JSON(str_json_parse_object)
return 0;
}
node = mxmlNewElement(parameter_list, "ParameterValueStruct");
@ -846,22 +847,19 @@ int cwmp_rpc_acs_prepare_message_inform(struct cwmp *cwmp, struct session *sessi
FREE(fault);
continue;
}
foreach_jsonobj_in_array(param_obj, parameters)
{
param_obj = json_object_array_get_idx(parameters, 0);
json_object_object_get_ex(param_obj, "parameter", &param_name);
json_object_object_get_ex(param_obj, "value", &param_value);
json_object_object_get_ex(param_obj, "type", &param_type);
cwmp_dm_param.name = strdup(param_name ? (char *)json_object_get_string(param_name) : "");
cwmp_dm_param.data = strdup(param_value ? (char *)json_object_get_string(param_value) : "");
cwmp_dm_param.type = strdup(param_type ? (char *)json_object_get_string(param_type) : "");
if (xml_prepare_parameters_inform(&cwmp_dm_param, parameter_list, &size))
goto error;
FREE(cwmp_dm_param.name);
FREE(cwmp_dm_param.data);
FREE(cwmp_dm_param.type);
}
FREE_JSON(parameters);
param_obj = json_object_array_get_idx(parameters, 0);
json_object_object_get_ex(param_obj, "parameter", &param_name);
json_object_object_get_ex(param_obj, "value", &param_value);
json_object_object_get_ex(param_obj, "type", &param_type);
cwmp_dm_param.name = strdup(param_name ? (char *)json_object_get_string(param_name) : "");
cwmp_dm_param.data = strdup(param_value ? (char *)json_object_get_string(param_value) : "");
cwmp_dm_param.type = strdup(param_type ? (char *)json_object_get_string(param_type) : "");
if (xml_prepare_parameters_inform(&cwmp_dm_param, parameter_list, &size))
goto error;
FREE(cwmp_dm_param.name);
FREE(cwmp_dm_param.data);
FREE(cwmp_dm_param.type);
FREE_JSON(str_json_parse_object)
}
if (cwmp_asprintf(&c, "cwmp:ParameterValueStruct[%d]", size) == -1)
goto error;
@ -1316,12 +1314,13 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
n = mxmlNewOpaque(n, param_value ? json_object_get_string(param_value) : "");
if (!n)
goto fault;
counter++;
}
FREE_JSON(parameters)
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
parameter_name = NULL;
FREE_JSON(str_json_parse_object)
}
#ifdef ACS_MULTI
@ -1339,6 +1338,7 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
return 0;
fault:
FREE_JSON(str_json_parse_object)
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
return 0;
@ -1436,11 +1436,11 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
mxmlElementSetAttr(b, "soap_enc:arrayType", c);
FREE(c);
#endif
FREE_JSON(parameters)
FREE_JSON(str_json_parse_object)
return 0;
fault:
FREE_JSON(parameters)
FREE_JSON(str_json_parse_object)
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
return 0;
@ -1529,8 +1529,6 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
counter++;
}
FREE_JSON(param_obj)
FREE_JSON(parameters)
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
parameter_name = NULL;
@ -1546,12 +1544,11 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
mxmlElementSetAttr(b, "soap_enc:arrayType", c);
FREE(c);
#endif
FREE_JSON(str_json_parse_object)
return 0;
fault:
FREE_JSON(param_obj)
FREE_JSON(parameters)
FREE_JSON(str_json_parse_object)
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
return 0;
@ -1658,8 +1655,6 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
cwmp_add_list_fault_param((char *)json_object_get_string(param_name), atoi(json_object_get_string(fault_value)), rpc->list_set_value_fault);
}
fault_code = FAULT_CPE_INVALID_ARGUMENTS;
FREE_JSON(fault_obj)
FREE_JSON(faults_array)
goto fault;
}
struct cwmp_param_value *param_value;
@ -1685,9 +1680,11 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
goto fault;
cwmp_set_end_session(flag | END_SESSION_TRANSACTION_COMMIT | END_SESSION_SET_NOTIFICATION_UPDATE);
//FREE_JSON(str_json_parse_object)
return 0;
fault:
//FREE_JSON(str_json_parse_object)
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
if (transaction_started) {
@ -2485,6 +2482,7 @@ int lookup_vcf_name(char *instance, char **value)
cwmp_asprintf(&vcf_name_parameter, "Device.DeviceInfo.VendorConfigFile.%s.Name", instance);
if (cwmp_get_parameter_values(vcf_name_parameter, &parameters) != NULL) {
FREE(vcf_name_parameter);
FREE_JSON(str_json_parse_object)
return -1;
}
@ -2492,6 +2490,7 @@ int lookup_vcf_name(char *instance, char **value)
json_object_object_get_ex(param_obj, "value", &value_obj);
*value = (char *)json_object_get_string(value_obj);
FREE(vcf_name_parameter);
FREE_JSON(str_json_parse_object)
return 0;
}
@ -3037,6 +3036,7 @@ static char *get_software_module_object_eq(char *param1, char *val1, char *param
if (err) {
FREE(sw_parameter_name);
FREE(err);
FREE_JSON(str_json_parse_object)
return NULL;
}
json_object_object_get_ex(swdu_get_obj, "parameters", parameters);
@ -3045,17 +3045,20 @@ static char *get_software_module_object_eq(char *param1, char *val1, char *param
param_obj = json_object_array_get_idx(*parameters, 0);
if (!param_obj) {
FREE(sw_parameter_name);
FREE_JSON(str_json_parse_object)
return NULL;
}
json_object *first_param = NULL;
json_object_object_get_ex(param_obj, "parameter", &first_param);
if (!first_param) {
FREE(sw_parameter_name);
FREE_JSON(str_json_parse_object)
return NULL;
}
char *first_param_name = strdup(json_object_get_string(first_param));
char instance[8];
snprintf(instance, (size_t)(strchr(first_param_name + strlen("Device.SoftwareModules.DeploymentUnit."), '.') - first_param_name - strlen("Device.SoftwareModules.DeploymentUnit.") + 1), "%s", (char *)(first_param_name + strlen("Device.SoftwareModules.DeploymentUnit.")));
FREE_JSON(str_json_parse_object)
return strdup(instance);
}
@ -3093,7 +3096,6 @@ static int get_deployment_unit_name_version(char *uuid, char **name, char **vers
continue;
}
}
FREE_JSON(arrobj);
return 1;
}
@ -3121,7 +3123,6 @@ static char *get_softwaremodules_uuid(char *url)
break;
}
}
FREE_JSON(arrobj);
return uuid;
}
@ -3149,7 +3150,6 @@ static char *get_softwaremodules_url(char *uuid)
break;
}
}
FREE_JSON(arrobj);
return url;
}
@ -3161,7 +3161,6 @@ static char *get_deployment_unit_reference(char *package_name, char *package_env
if (!sw_by_name_env_instance)
return NULL;
FREE_JSON(arrobj);
cwmp_asprintf(&deployment_unit_ref, "Device.SoftwareModules.DeploymentUnit.%s", sw_by_name_env_instance);
return deployment_unit_ref;
}
@ -3171,11 +3170,11 @@ static bool environment_exists(char *environment_path)
json_object *sw_env_get_obj = NULL;
char *err = cwmp_get_parameter_values(environment_path, &sw_env_get_obj);
FREE_JSON(str_json_parse_object)
if (err) {
FREE(err);
return false;
} else {
FREE_JSON(sw_env_get_obj);
return true;
}
}
@ -3188,6 +3187,7 @@ static char *get_exec_env_name(char *environment_path)
char *err = cwmp_get_parameter_values(environment_path, &sw_env_get_obj);
if (err) {
FREE(err);
FREE_JSON(str_json_parse_object)
return "";
}
@ -3206,7 +3206,7 @@ static char *get_exec_env_name(char *environment_path)
break;
}
}
FREE_JSON(sw_env_get_obj);
FREE_JSON(str_json_parse_object)
return env_name;
}