]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Fix memory leak in virAuthGetCredential
authorJohn Ferlan <jferlan@redhat.com>
Tue, 16 Jun 2020 12:07:02 +0000 (08:07 -0400)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 16 Jun 2020 13:01:05 +0000 (15:01 +0200)
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>
src/remote/remote_driver.c
src/util/virauth.c
src/util/virauthconfig.c
src/util/virauthconfig.h
tests/virauthconfigtest.c

index 0aeab9db279c6b9cd6616491ec9784cf9efe05cd..653c68472ae7d139daa8c654cadd5b278f2813c9 100644 (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:
index f75e6745861f130cdadc47d28ba0dff446298bc2..105fca16eb4fed5d1bf1784800fe706208653f5c 100644 (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;
 }
 
index 1c007757c772023fe12775ef5d163a25c74b1175..8289b28d348e5f1b94c5f1ff8e24e0a18e7f0999 100644 (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;
index de28b1ff284161513499b1cb81230d8b4377e798..b6f5b5c110b49130eb8b8e8b02dc2ad46d934582 100644 (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);
index 20855f004e65bbd55f2538f29025d522f5b77fad..a88b4535433cea84b53b4eb80cdfc960712d384e 100644 (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,