Fixed format error
[platform/core/connectivity/net-config.git] / src / wifi-eap-config.c
index adaa63d..5b40642 100755 (executable)
@@ -94,7 +94,7 @@ static int __config_save(const char *ssid, GKeyFile *keyfile)
 
        /* Do POSIX file operation to create and remove config files,
         * Do not use g_file_set_contents, it breaks inotify operations */
-       if (fputs(data, file) < 0) {
+       if (data && fputs(data, file) < 0) {
                ERR("Failed to write %s", config_file);
 
                err = -EIO;
@@ -196,7 +196,7 @@ static gboolean __netconfig_copy_config(const char *src, const char *dst)
 
        result = g_file_get_contents(src, &buf, &length, &error);
        if (result != TRUE) {
-               ERR("Failed to read %s[%s]", error->message);
+               ERR("Failed to read [%s]", error->message);
                g_error_free(error);
 
                return result;
@@ -204,11 +204,11 @@ static gboolean __netconfig_copy_config(const char *src, const char *dst)
 
        result = g_file_set_contents(dst, buf, length, &error);
        if (result != TRUE) {
-               ERR("Failed to write %s[%s]", error->message);
+               ERR("Failed to write [%s]", error->message);
                g_error_free(error);
        }
 
-       INFO("Successfully installed[%d]", length);
+       INFO("Successfully installed[%zd]", length);
        g_free(buf);
 
        if (remove(src) != 0)
@@ -287,6 +287,8 @@ static gboolean __netconfig_create_config(GVariant *fields)
                                cert_file = strrchr(value, '/');
                                if (cert_file == NULL) {
                                        ERR("Failed to get cert file: %s", value);
+                                       g_free(field);
+                                       g_free(value);
                                        goto out;
                                }
 
@@ -297,6 +299,8 @@ static gboolean __netconfig_create_config(GVariant *fields)
                                                WIFI_CERT_STORAGEDIR, encoded_ssid);
                                if (dirname == NULL) {
                                        ERR("Failed to create dirname");
+                                       g_free(field);
+                                       g_free(value);
                                        goto out;
                                }
                                if (g_file_test(dirname, G_FILE_TEST_IS_DIR) != TRUE) {
@@ -304,6 +308,8 @@ static gboolean __netconfig_create_config(GVariant *fields)
                                                        S_IXGRP | S_IROTH | S_IXOTH) < 0) {
                                                if (errno != EEXIST) {
                                                        g_free(dirname);
+                                                       g_free(field);
+                                                       g_free(value);
                                                        goto out;
                                                }
                                        }
@@ -314,11 +320,15 @@ static gboolean __netconfig_create_config(GVariant *fields)
                                                WIFI_CERT_STORAGEDIR, encoded_ssid, cert_file);
                                if (cert_path == NULL) {
                                        ERR("Failed to create cert path");
+                                       g_free(field);
+                                       g_free(value);
                                        goto out;
                                }
                                if (__netconfig_copy_config(value, cert_path) != TRUE) {
                                        ERR("Failed to read cert file %s", value);
                                        g_free(cert_path);
+                                       g_free(field);
+                                       g_free(value);
                                        goto out;
                                }
 
@@ -347,12 +357,6 @@ out:
 
        g_variant_iter_free(iter);
 
-       if (field)
-               g_free(field);
-
-       if (value)
-               g_free(value);
-
        g_free(group_name);
        g_free(encoded_ssid);
 
@@ -372,13 +376,11 @@ static gboolean _delete_configuration(const gchar *profile)
        ERR("get config_id [%s] from [%s]", config_id, profile);
 
        ret = wifi_config_remove_configuration(config_id);
-       if (ret != TRUE) {
+       if (ret != TRUE)
                ERR("Fail to wifi_config_remove_configuration [%s]", config_id);
-       }
 
-       if (config_id != NULL) {
+       if (config_id != NULL)
                g_free(config_id);
-       }
 
        return ret;
 }
@@ -397,9 +399,8 @@ static gboolean __netconfig_delete_config(const char *profile)
                return FALSE;
        }
 
-       if (_delete_configuration(profile) != TRUE) {
+       if (_delete_configuration(profile) != TRUE)
                ERR("Fail to delete configuration [%s]", profile);
-       }
 
        wifi_ident = strstr(profile, "wifi_");
        if (wifi_ident == NULL) {
@@ -472,16 +473,15 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
                const gchar *service, GVariant *fields)
 {
        gboolean updated = FALSE;
-       gboolean reply = FALSE;
        gboolean result = FALSE;
 
-       g_return_val_if_fail(wifi != NULL, FALSE);
+       g_return_val_if_fail(wifi != NULL, TRUE);
 
        DBG("Set agent fields for %s", service);
 
        if (netconfig_is_wifi_profile(service) != TRUE) {
                netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_WRONG_PROFILE, "InvalidService");
-               return reply;
+               return TRUE;
        }
 
        updated = __netconfig_create_config(fields);
@@ -533,20 +533,18 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
 
        if (result != TRUE)
                ERR("Fail to connect %s", service);
-       else
-               reply = TRUE;
 
-       return reply;
+       return TRUE;
 }
 
 gboolean handle_delete_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
                const gchar *profile)
 {
-       g_return_val_if_fail(wifi != NULL, FALSE);
+       g_return_val_if_fail(wifi != NULL, TRUE);
 
        wifi_complete_delete_eap_config(wifi, context);
 
-       gboolean ret = __netconfig_delete_config((const char *)profile);
+       __netconfig_delete_config((const char *)profile);
 
-       return ret;
+       return TRUE;
 }