Skip to content

Commit

Permalink
More checks and fix memory leaks
Browse files Browse the repository at this point in the history
Change-Id: Ide0aa6b989bfd4a9d4cbd4d073e33c5fe0ded9df
  • Loading branch information
Guittet Thibault committed Aug 26, 2014
1 parent 1b5357f commit 0a83cfb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 0 additions & 2 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,7 @@ static DBusHandlerResult monitor_changed(DBusConnection *connection,
json_object_object_add(res, key_command_path,
json_object_new_string(path));
json_object_object_add(res, key_command_data, dbus_to_json(&iter));

json_object_object_add(res, key_signal, sig_name);
json_object_get(res);

commands_signal(res);

Expand Down
4 changes: 2 additions & 2 deletions engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static void react_to_sig_service(struct json_object *interface,

if (serv_dict && json_object_object_get_ex(serv_dict, key, NULL)) {
json_object_object_del(serv_dict, key);
json_object_object_add(serv_dict, key, val);
json_object_object_add(serv_dict, key, json_object_get(val));
}
}

Expand Down Expand Up @@ -818,7 +818,7 @@ static void react_to_sig_technology(struct json_object *interface,

if (tech_dict && json_object_object_get_ex(tech_dict, key, NULL)) {
json_object_object_del(tech_dict, key);
json_object_object_add(tech_dict, key, val);
json_object_object_add(tech_dict, key, json_object_get(val));
}
}

Expand Down
35 changes: 31 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ static void exec_action(struct userptr_data *data)
*/
static void exec_back(void)
{
if (context.current_context != CONTEXT_SERVICE_CONFIG_STANDALONE)
if (context.current_context == CONTEXT_SERVICE_CONFIG_STANDALONE) {
free(context.serv->dbus_name);
context.serv->dbus_name = NULL;
} else
context_free_userptr_data();

context_actions[context.current_context].func_free();
Expand Down Expand Up @@ -478,9 +481,10 @@ static void action_on_cmd_callback(struct json_object *jobj)
else if (strcmp(key_engine_get_service, cmd_name) == 0) {
tmp = json_object_new_object();
array = json_object_new_array();
json_object_array_add(array, data);
json_object_array_add(array, json_object_get(data));
json_object_object_add(tmp, key_services, array);
__renderers_services(tmp);
json_object_put(tmp);

} else
print_info_in_footer(true, "Unknown command called");
Expand Down Expand Up @@ -531,7 +535,8 @@ static void action_on_signal(struct json_object *jobj)
got_removed = true;
}

if (context.current_context == CONTEXT_SERVICE_CONFIG) {
if (context.current_context == CONTEXT_SERVICE_CONFIG ||
context.current_context == CONTEXT_SERVICE_CONFIG_STANDALONE) {
if (context.serv->dbus_name == NULL)
return;

Expand Down Expand Up @@ -899,6 +904,9 @@ static void print_services_for_tech(void)
{
struct json_object *cmd, *tmp;

if (!context.tech || !context.tech->dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

Expand All @@ -919,6 +927,9 @@ static void connect_to_service(void)
{
struct json_object *cmd, *tmp;

if (!context.serv || !context.serv->dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

Expand All @@ -945,6 +956,9 @@ static void disconnect_of_service(struct userptr_data *data)
{
struct json_object *cmd, *tmp;

if (!data || !data->dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

Expand All @@ -966,6 +980,9 @@ static void toggle_power_tech(struct userptr_data *data)
{
struct json_object *cmd, *tmp;

if (!data || !data->dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

Expand Down Expand Up @@ -1002,6 +1019,9 @@ static void scan_tech(const char *tech_dbus_name)
{
struct json_object *cmd, *tmp;

if (!tech_dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

Expand All @@ -1024,6 +1044,9 @@ static void remove_service(struct userptr_data *data)
{
struct json_object *cmd, *tmp;

if (!data || !data->dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

Expand All @@ -1045,7 +1068,7 @@ static void get_service_settings(void)
{
struct json_object *cmd, *tmp;

if (!context.serv->dbus_name)
if (!context.serv || !context.serv->dbus_name)
return;

cmd = json_object_new_object();
Expand Down Expand Up @@ -1165,6 +1188,9 @@ static void modify_service_config(void)
const char *are_obj[] = { key_serv_ipv4_config, key_serv_ipv6_config,
key_serv_proxy_config };

if (!context.serv || !context.serv->dbus_name)
return;

for (i = 0; main_fields[i]; i++) {
if (!((unsigned)field_opts(main_fields[i]) & O_EDIT))
continue;
Expand Down Expand Up @@ -1391,6 +1417,7 @@ static void exec_action_context_services(int ch)
break;

context.serv->dbus_name = strdup(userptr->dbus_name);
__renderers_free_services();
get_service_settings();
break;
}
Expand Down

0 comments on commit 0a83cfb

Please sign in to comment.