diff options
author | Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> | 2012-10-17 10:46:13 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-10-17 12:19:25 +0300 |
commit | 9f03ec3e6b54222a5d7f9993e8543d6699c15f89 (patch) | |
tree | 0b3f4ea36f87c133e2b6cfec59e70a0a5248173e /client | |
parent | 3cbacaa29749799fb34c7a8d715db01d7fe1d31a (diff) | |
download | connman-9f03ec3e6b54222a5d7f9993e8543d6699c15f89.tar.gz connman-9f03ec3e6b54222a5d7f9993e8543d6699c15f89.tar.bz2 connman-9f03ec3e6b54222a5d7f9993e8543d6699c15f89.zip |
client: Fix some memory leaks in data_manager part
Diffstat (limited to 'client')
-rw-r--r-- | client/data_manager.c | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/client/data_manager.c b/client/data_manager.c index 723b9790..13994c81 100644 --- a/client/data_manager.c +++ b/client/data_manager.c @@ -90,26 +90,31 @@ free_servers: int connect_service(DBusConnection *connection, char *name) { - DBusMessage *message, *message_connect; + DBusMessage *message, *message_connect = NULL; struct service_data service; - char *path; + char *path = NULL; const char *path_name; DBusError err; + int err_ret = 0; message = get_message(connection, "GetServices"); if (message == NULL) return -ENOMEM; path_name = find_service(connection, message, name, &service); - if (path_name == NULL) - return -ENXIO; + if (path_name == NULL) { + err_ret = -ENXIO; + goto error; + } path = g_strdup_printf("/net/connman/service/%s", path_name); message_connect = dbus_message_new_method_call("net.connman", path, "net.connman.Service", "Connect"); - if (message_connect == NULL) - return -ENOMEM; + if (message_connect == NULL) { + err_ret = -ENOMEM; + goto error; + } dbus_error_init(&err); dbus_connection_send_with_reply_and_block(connection, message_connect, @@ -117,40 +122,51 @@ int connect_service(DBusConnection *connection, char *name) if (dbus_error_is_set(&err)) { printf("Connection failed; error: '%s'\n", err.message); - return -EINVAL; + err_ret = -EINVAL; + goto error; } dbus_connection_send(connection, message_connect, NULL); dbus_connection_flush(connection); - dbus_message_unref(message_connect); + +error: + if (message != NULL) + dbus_message_unref(message); + if (message_connect != NULL) + dbus_message_unref(message_connect); g_free(path); - return 0; + return err_ret; } int disconnect_service(DBusConnection *connection, char *name) { - DBusMessage *message, *message_disconnect; + DBusMessage *message, *message_disconnect = NULL; struct service_data service; - char *path; + char *path = NULL; const char *path_name; DBusError err; + int err_ret = 0; message = get_message(connection, "GetServices"); if (message == NULL) return -ENOMEM; path_name = find_service(connection, message, name, &service); - if (path_name == NULL) - return -ENXIO; + if (path_name == NULL) { + err_ret = -ENXIO; + goto error; + } path = g_strdup_printf("/net/connman/service/%s", path_name); printf("%s\n", path); message_disconnect = dbus_message_new_method_call("net.connman", path, "net.connman.Service", "Disconnect"); - if (message_disconnect == NULL) - return -ENOMEM; + if (message_disconnect == NULL) { + err_ret = -ENOMEM; + goto error; + } dbus_error_init(&err); dbus_connection_send_with_reply_and_block(connection, @@ -159,15 +175,21 @@ int disconnect_service(DBusConnection *connection, char *name) if (dbus_error_is_set(&err)) { printf("Connection failed; error: '%s'\n", err.message); - return -EINVAL; + err_ret = -EINVAL; + goto error; } dbus_connection_send(connection, message_disconnect, NULL); dbus_connection_flush(connection); - dbus_message_unref(message_disconnect); + +error: + if (message != NULL) + dbus_message_unref(message); + if (message_disconnect != NULL) + dbus_message_unref(message_disconnect); g_free(path); - return 0; + return err_ret; } int set_manager(DBusConnection *connection, char *key, dbus_bool_t value) |