diff options
author | Thomas Haller <thaller@redhat.com> | 2015-07-17 11:08:31 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-07-24 11:04:01 +0200 |
commit | d5d34ec107a3a101debb57d16487e67cca2159da (patch) | |
tree | 1b422bbd1509450b92ba44060f141e934371e3c7 | |
parent | c0b03debc8dca9b68f9762a98773eb3c3e81e40e (diff) | |
download | NetworkManager-d5d34ec107a3a101debb57d16487e67cca2159da.tar.gz |
keyfile: refactor return paths in _internal_write_connection()
-rw-r--r-- | src/settings/plugins/keyfile/writer.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c index b6a8786dc4..ffe941bbac 100644 --- a/src/settings/plugins/keyfile/writer.c +++ b/src/settings/plugins/keyfile/writer.c @@ -34,6 +34,7 @@ #include "common.h" #include "utils.h" #include "nm-keyfile-internal.h" +#include "gsystem-local-alloc.h" typedef struct { @@ -237,10 +238,9 @@ _internal_write_connection (NMConnection *connection, GError **error) { GKeyFile *key_file; - char *data; + gs_free char *data = NULL; gsize len; - gboolean success = FALSE; - char *path; + gs_free char *path = NULL; const char *id; WriteInfo info = { 0 }; GError *local_err = NULL; @@ -312,8 +312,7 @@ _internal_write_connection (NMConnection *connection, /* this really should not happen, we tried hard to find an unused name... bail out. */ g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, "could not find suitable keyfile file name (%s already used)", path); - g_free (path); - goto out; + return FALSE; } /* Both our preferred path based on connection id and id-uuid are taken. * Fallback to @existing_path */ @@ -334,8 +333,7 @@ _internal_write_connection (NMConnection *connection, "%s.%d: error writing to file '%s': %s", __FILE__, __LINE__, path, local_err->message); g_error_free (local_err); - g_free (path); - goto out; + return FALSE; } if (chown (path, owner_uid, owner_grp) < 0) { @@ -343,25 +341,22 @@ _internal_write_connection (NMConnection *connection, "%s.%d: error chowning '%s': %d", __FILE__, __LINE__, path, errno); unlink (path); - } else { - if (chmod (path, S_IRUSR | S_IWUSR) < 0) { - g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, - "%s.%d: error setting permissions on '%s': %d", __FILE__, - __LINE__, path, errno); - unlink (path); - } else { - if (out_path && g_strcmp0 (existing_path, path)) { - *out_path = path; /* pass path out to caller */ - path = NULL; - } - success = TRUE; - } + return FALSE; } - g_free (path); -out: - g_free (data); - return success; + if (chmod (path, S_IRUSR | S_IWUSR) < 0) { + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, + "%s.%d: error setting permissions on '%s': %d", __FILE__, + __LINE__, path, errno); + unlink (path); + return FALSE; + } + + if (out_path && g_strcmp0 (existing_path, path)) { + *out_path = path; /* pass path out to caller */ + path = NULL; + } + return TRUE; } gboolean |