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

2021-10-03 Thread Laine Stump

On 10/1/21 2:12 PM, William Douglas wrote:

Signed-off-by: William Douglas 
---
  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", ) < 0)
-goto cleanup;
+return -1;
  }
  
  return 0;

-
- cleanup:
-virJSONValueFree(memory);
-return -1;
  }
  
  static int




Reviewed-by: Laine Stump 

I'll add the extra empty lines before pushing.



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

2021-10-01 Thread William Douglas
Signed-off-by: William Douglas 
---
 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", ) < 0)
-goto cleanup;
+return -1;
 }
 
 return 0;
-
- cleanup:
-virJSONValueFree(memory);
-return -1;
 }
 
 static int
-- 
2.33.0