diff options
author | Dan Williams <dcbw@redhat.com> | 2014-09-03 17:12:32 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-09-04 09:55:20 -0500 |
commit | 6fc48270eec4a6f36f727aac1eb267802700b24a (patch) | |
tree | 724723bd5fd288d4b1e317368d1cca6657c69c9f | |
parent | 84ae950a31ef405a188661aa381b0644e679c91e (diff) | |
download | NetworkManager-6fc48270eec4a6f36f727aac1eb267802700b24a.tar.gz |
tui: fix requesting and displaying secrets
nmt_sync_op_complete_pointer() completes the operation after the
caller of this function returns. This means that any values passed
to this function must either be allocated from its caller, or
referenced by the caller.
nm_remote_connection_get_secrets() owns the 'secrets' hash passed
to the callback, and it is destroyed when the callback returns.
So nmtui's got_secrets() must copy the hash to ensure the data
sticks around for nmt_sync_op_wait_pointer() later.
(cherry picked from commit 240a9a92ae28ee3e794567d3bf00f1d7b365fa0d)
-rw-r--r-- | tui/nmt-editor.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tui/nmt-editor.c b/tui/nmt-editor.c index b204a5c861..f03e9b17b4 100644 --- a/tui/nmt-editor.c +++ b/tui/nmt-editor.c @@ -171,7 +171,19 @@ got_secrets (NMRemoteConnection *connection, GError *error, gpointer op) { - nmt_sync_op_complete_pointer (op, secrets, error); + GHashTable *copy = NULL, *setting; + GHashTableIter iter; + const char *name; + + if (secrets) { + /* 'secrets' is owned by the caller so we must copy it */ + copy = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); + g_hash_table_iter_init (&iter, secrets); + while (g_hash_table_iter_next (&iter, (gpointer) &name, (gpointer) &setting)) + g_hash_table_insert (copy, g_strdup (name), nm_utils_gvalue_hash_dup (setting)); + } + + nmt_sync_op_complete_pointer (op, copy, error); } static NMConnection * @@ -196,8 +208,10 @@ build_edit_connection (NMConnection *orig_connection) setting_name, got_secrets, &op); /* FIXME: error handling */ secrets = nmt_sync_op_wait_pointer (&op, NULL); - if (secrets) + if (secrets) { (void) nm_connection_update_secrets (edit_connection, setting_name, secrets, NULL); + g_hash_table_unref (secrets); + } } g_hash_table_unref (settings); |