diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-10 14:30:37 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-02-04 14:03:13 +0100 |
commit | 337dbc392253af92b0577da062a5abc1d032b1ef (patch) | |
tree | e540dc7dc861f575d841970561651a9fac506120 /vncviewer/UserDialog.cxx | |
parent | dde95fccca9fffff0da2dc486d639b162115bb9e (diff) | |
download | tigervnc-337dbc392253af92b0577da062a5abc1d032b1ef.tar.gz tigervnc-337dbc392253af92b0577da062a5abc1d032b1ef.zip |
Return std::string instead of dynamic allocations
We mostly use classical C strings, but the memory management around them
can get confusing and error prone. Let's use std::string for the cases
where we need to return a newly allocated string.
Diffstat (limited to 'vncviewer/UserDialog.cxx')
-rw-r--r-- | vncviewer/UserDialog.cxx | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index ea5a8053..ff5b6123 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -34,7 +34,6 @@ #include <FL/Fl_Return_Button.H> #include <FL/Fl_Pixmap.H> -#include <rfb/util.h> #include <rfb/Password.h> #include <rfb/Exception.h> @@ -71,7 +70,8 @@ UserDialog::~UserDialog() { } -void UserDialog::getUserPasswd(bool secure, char** user, char** password) +void UserDialog::getUserPasswd(bool secure, std::string* user, + std::string* password) { const char *passwordFileName(passwordFile); @@ -80,13 +80,13 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password) char *envPassword = getenv("VNC_PASSWORD"); if(user && envUsername && envPassword) { - *user = strdup(envUsername); - *password = strdup(envPassword); + *user = envUsername; + *password = envPassword; return; } if (!user && envPassword) { - *password = strdup(envPassword); + *password = envPassword; return; } @@ -102,7 +102,7 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password) fclose(fp); PlainPasswd passwd(obfPwd); - *password = passwd.takeBuf(); + *password = passwd.buf; return; } @@ -198,8 +198,8 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password) if (ret_val == 0) { if (user) - *user = strDup(username->value()); - *password = strDup(passwd->value()); + *user = username->value(); + *password = passwd->value(); } delete win; |