diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-10-06 10:15:38 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-10-06 10:19:43 +0100 |
commit | 9d8b0addf94c86f224093bb1ca66ebe18494ff7c (patch) | |
tree | 6d6b07d5dfabf73e3c58847af2b15b3754a9a357 /subsurfacestartup.c | |
parent | c75ec7a04ab14c906c3e58febf142ffb8f73b8bc (diff) | |
download | subsurface-9d8b0addf94c86f224093bb1ca66ebe18494ff7c.tar.gz |
Correctly copy preferences
When just assigning one structure to the other we copy the string
pointers. If we then modify those strings in the copy, we happily free
the strings of the original. And then resetting the preferences equally
happily reused those strings, pointing to long since freed memory.
I think what I did now is excessive for the current use case in that it
copies a ton of strings that are unset in the default_prefs. But I figured
this is a rarely used function and I might as well do it correctly.
Also, once we implement multi user support with per user preferences we
will be copying completely populated preferences around (at least that's
my guess).
Fixes #940
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurfacestartup.c')
-rw-r--r-- | subsurfacestartup.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/subsurfacestartup.c b/subsurfacestartup.c index 33aa9fb72..d474ab924 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -272,6 +272,28 @@ void setup_system_prefs(void) default_prefs.units = IMPERIAL_units; } +/* copy a preferences block, including making copies of all included strings */ +void copy_prefs(struct preferences *src, struct preferences *dest) +{ + *dest = *src; + dest->divelist_font = copy_string(src->divelist_font); + dest->default_filename = copy_string(src->default_filename); + dest->default_cylinder = copy_string(src->default_cylinder); + dest->cloud_base_url = copy_string(src->cloud_base_url); + dest->cloud_git_url = copy_string(src->cloud_git_url); + dest->userid = copy_string(src->userid); + dest->proxy_host = copy_string(src->proxy_host); + dest->proxy_user = copy_string(src->proxy_user); + dest->proxy_pass = copy_string(src->proxy_pass); + dest->cloud_storage_password = copy_string(src->cloud_storage_password); + dest->cloud_storage_newpassword = copy_string(src->cloud_storage_newpassword); + dest->cloud_storage_email = copy_string(src->cloud_storage_email); + dest->cloud_storage_email_encoded = copy_string(src->cloud_storage_email_encoded); + dest->facebook.access_token = copy_string(src->facebook.access_token); + dest->facebook.user_id = copy_string(src->facebook.user_id); + dest->facebook.album_id = copy_string(src->facebook.album_id); +} + /* * Free strduped prefs before exit. * |