[PATCH v1] qemu: Use g_autofree and g_autoptr in qemuAgentSetUserPassword

Seeteena Thoufeek posted 1 patch 4 years ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1584962039-4286-1-git-send-email-s1seetee@linux.vnet.ibm.com
src/qemu/qemu_agent.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
[PATCH v1] qemu: Use g_autofree and g_autoptr in qemuAgentSetUserPassword
Posted by Seeteena Thoufeek 4 years ago
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
---
 src/qemu/qemu_agent.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 9ea2c59563..1583a4eee2 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -2274,10 +2274,9 @@ qemuAgentSetUserPassword(qemuAgentPtr agent,
                          const char *password,
                          bool crypted)
 {
-    int ret = -1;
-    virJSONValuePtr cmd = NULL;
-    virJSONValuePtr reply = NULL;
-    char *password64 = NULL;
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
+    g_autofree char *password64 = NULL;
 
     password64 = g_base64_encode((unsigned char *)password,
                                  strlen(password));
@@ -2287,18 +2286,12 @@ qemuAgentSetUserPassword(qemuAgentPtr agent,
                                      "s:username", user,
                                      "s:password", password64,
                                      NULL)))
-        goto cleanup;
+        return -1;
 
     if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    virJSONValueFree(cmd);
-    virJSONValueFree(reply);
-    VIR_FREE(password64);
-    return ret;
+    return 0;
 }
 
 /* Returns: 0 on success
-- 
2.18.2


Re: [PATCH v1] qemu: Use g_autofree and g_autoptr in qemuAgentSetUserPassword
Posted by Daniel Henrique Barboza 4 years ago

On 3/23/20 8:13 AM, Seeteena Thoufeek wrote:
> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
> ---


Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>


>   src/qemu/qemu_agent.c | 19 ++++++-------------
>   1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index 9ea2c59563..1583a4eee2 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -2274,10 +2274,9 @@ qemuAgentSetUserPassword(qemuAgentPtr agent,
>                            const char *password,
>                            bool crypted)
>   {
> -    int ret = -1;
> -    virJSONValuePtr cmd = NULL;
> -    virJSONValuePtr reply = NULL;
> -    char *password64 = NULL;
> +    g_autoptr(virJSONValue) cmd = NULL;
> +    g_autoptr(virJSONValue) reply = NULL;
> +    g_autofree char *password64 = NULL;
>   
>       password64 = g_base64_encode((unsigned char *)password,
>                                    strlen(password));
> @@ -2287,18 +2286,12 @@ qemuAgentSetUserPassword(qemuAgentPtr agent,
>                                        "s:username", user,
>                                        "s:password", password64,
>                                        NULL)))
> -        goto cleanup;
> +        return -1;
>   
>       if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
> -        goto cleanup;
> -
> -    ret = 0;
> +        return -1;
>   
> - cleanup:
> -    virJSONValueFree(cmd);
> -    virJSONValueFree(reply);
> -    VIR_FREE(password64);
> -    return ret;
> +    return 0;
>   }
>   
>   /* Returns: 0 on success
> 

Re: [PATCH v1] qemu: Use g_autofree and g_autoptr in qemuAgentSetUserPassword
Posted by Michal Prívozník 4 years ago
On 23. 3. 2020 12:26, Daniel Henrique Barboza wrote:
> 
> 
> On 3/23/20 8:13 AM, Seeteena Thoufeek wrote:
>> Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
>> ---
> 
> 
> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

And now pushed. Congratulations on your first libvirt contribution!

Michal