util: Fix memory leak in virAuthGetCredential

Since 5084091a, @tmp is filled by a g_key_file_get_string which is
now an allocated string as opposed to some hash table lookup value,
so we need to treat it as so.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
John Ferlan 2020-06-16 08:07:02 -04:00 committed by Peter Krempa
parent 3a58613b0c
commit d585847d2e
5 changed files with 5 additions and 8 deletions

View File

@ -4097,7 +4097,7 @@ static int remoteAuthFillFromConfig(virConnectPtr conn,
}
for (ninteract = 0; state->interact[ninteract].id != 0; ninteract++) {
const char *value = NULL;
char *value = NULL;
switch (state->interact[ninteract].id) {
case SASL_CB_USER:

View File

@ -107,7 +107,6 @@ virAuthGetCredential(const char *servicename,
char **value)
{
g_autoptr(virAuthConfig) config = NULL;
const char *tmp;
*value = NULL;
@ -121,11 +120,9 @@ virAuthGetCredential(const char *servicename,
servicename,
hostname,
credname,
&tmp) < 0)
value) < 0)
return -1;
*value = g_strdup(tmp);
return 0;
}

View File

@ -99,7 +99,7 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
const char *service,
const char *hostname,
const char *credname,
const char **value)
char **value)
{
g_autofree char *authgroup = NULL;
g_autofree char *credgroup = NULL;

View File

@ -37,6 +37,6 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
const char *service,
const char *hostname,
const char *credname,
const char **value);
char **value);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virAuthConfig, virAuthConfigFree);

View File

@ -42,7 +42,7 @@ struct ConfigLookupData {
static int testAuthLookup(const void *args)
{
const struct ConfigLookupData *data = args;
const char *actual = NULL;
g_autofree char *actual = NULL;
int rv;
rv = virAuthConfigLookup(data->config,