[PATCH 3/5] ch: use g_auto in virCHMonitorBuildMemoryJson

William Douglas posted 5 patches 4 years, 4 months ago
[PATCH 3/5] ch: use g_auto in virCHMonitorBuildMemoryJson
Posted by William Douglas 4 years, 4 months ago
Signed-off-by: William Douglas <william.douglas@intel.com>
---
 src/ch/ch_monitor.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 800457af41..7326ac645b 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -154,22 +154,17 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *content, virDomainDef *vmdef)
 static int
 virCHMonitorBuildMemoryJson(virJSONValue *content, virDomainDef *vmdef)
 {
-    virJSONValue *memory;
     unsigned long long total_memory = virDomainDefGetMemoryInitial(vmdef) * 1024;
 
     if (total_memory != 0) {
-        memory = virJSONValueNewObject();
+        g_autoptr(virJSONValue) memory = virJSONValueNewObject();
         if (virJSONValueObjectAppendNumberUlong(memory, "size", total_memory) < 0)
-            goto cleanup;
+            return -1;
         if (virJSONValueObjectAppend(content, "memory", &memory) < 0)
-            goto cleanup;
+            return -1;
     }
 
     return 0;
-
- cleanup:
-    virJSONValueFree(memory);
-    return -1;
 }
 
 static int
-- 
2.33.0

Re: [PATCH 3/5] ch: use g_auto in virCHMonitorBuildMemoryJson
Posted by Laine Stump 4 years, 4 months ago
On 10/1/21 2:12 PM, William Douglas wrote:
> Signed-off-by: William Douglas <william.douglas@intel.com>
> ---
>   src/ch/ch_monitor.c | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
> index 800457af41..7326ac645b 100644
> --- a/src/ch/ch_monitor.c
> +++ b/src/ch/ch_monitor.c
> @@ -154,22 +154,17 @@ virCHMonitorBuildKernelRelatedJson(virJSONValue *content, virDomainDef *vmdef)
>   static int
>   virCHMonitorBuildMemoryJson(virJSONValue *content, virDomainDef *vmdef)
>   {
> -    virJSONValue *memory;
>       unsigned long long total_memory = virDomainDefGetMemoryInitial(vmdef) * 1024;
>   
>       if (total_memory != 0) {
> -        memory = virJSONValueNewObject();
> +        g_autoptr(virJSONValue) memory = virJSONValueNewObject();

there should be an extra empy line here between variable definition and 
the start of instructions.

>           if (virJSONValueObjectAppendNumberUlong(memory, "size", total_memory) < 0)
> -            goto cleanup;
> +            return -1;

also an empty line here makes the code more readable.

>           if (virJSONValueObjectAppend(content, "memory", &memory) < 0)
> -            goto cleanup;
> +            return -1;
>       }
>   
>       return 0;
> -
> - cleanup:
> -    virJSONValueFree(memory);
> -    return -1;
>   }
>   
>   static int
> 

Reviewed-by: Laine Stump <laine@redhat.com>

I'll add the extra empty lines before pushing.