* mu_util_read_password: fix mem mgmt

This commit is contained in:
djcb 2012-09-14 12:16:53 +03:00
parent 3ae4fb965e
commit 70824bf978
1 changed files with 4 additions and 8 deletions

View File

@ -499,22 +499,18 @@ mu_util_printerr_encoded (const char *frm, ...)
char* char*
mu_util_read_password (const char *prompt) mu_util_read_password (const char *prompt)
{ {
char *pass, *tmp; char *pass;
g_return_val_if_fail (prompt, NULL); g_return_val_if_fail (prompt, NULL);
/* note: getpass is obsolete; replace with something better */ /* note: getpass is obsolete; replace with something better */
tmp = getpass (prompt); pass = getpass (prompt); /* returns static mem, don't free */
if (!tmp) { if (!pass) {
if (errno) if (errno)
g_warning ("error: %s", strerror(errno)); g_warning ("error: %s", strerror(errno));
return NULL; return NULL;
} }
/* make sure we can free with g_free(), not free() */
pass = g_strdup (tmp); return g_strdup (pass);
free (tmp);
return pass;
} }