]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: buffer: use VIR_AUTOFREE instead of VIR_FREE for scalar types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Tue, 24 Jul 2018 15:52:05 +0000 (21:22 +0530)
committerErik Skultety <eskultet@redhat.com>
Fri, 27 Jul 2018 15:19:14 +0000 (17:19 +0200)
By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virbuffer.c

index 86bc17957fa697f3d082b5d27b079bb2425e35b6..2d7bd5152e0386aa4341d7d000a36b92d2220d5f 100644 (file)
@@ -456,7 +456,8 @@ void
 virBufferEscapeString(virBufferPtr buf, const char *format, const char *str)
 {
     int len;
-    char *escaped, *out;
+    VIR_AUTOFREE(char *) escaped = NULL;
+    char *out;
     const char *cur;
     const char forbidden_characters[] = {
         0x01,   0x02,   0x03,   0x04,   0x05,   0x06,   0x07,   0x08,
@@ -533,7 +534,6 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str)
     *out = 0;
 
     virBufferAsprintf(buf, format, escaped);
-    VIR_FREE(escaped);
 }
 
 /**
@@ -612,7 +612,8 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
                 const char *format, const char *str)
 {
     int len;
-    char *escaped, *out;
+    VIR_AUTOFREE(char *) escaped = NULL;
+    char *out;
     const char *cur;
 
     if ((format == NULL) || (buf == NULL) || (str == NULL))
@@ -644,7 +645,6 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
     *out = 0;
 
     virBufferAsprintf(buf, format, escaped);
-    VIR_FREE(escaped);
 }
 
 
@@ -690,7 +690,7 @@ virBufferEscapeN(virBufferPtr buf,
 {
     int len;
     size_t i;
-    char *escaped = NULL;
+    VIR_AUTOFREE(char *) escaped = NULL;
     char *out;
     const char *cur;
     virBufferEscapePair escapeItem;
@@ -753,7 +753,6 @@ virBufferEscapeN(virBufferPtr buf,
  cleanup:
     va_end(ap);
     VIR_FREE(escapeList);
-    VIR_FREE(escaped);
 }
 
 
@@ -818,7 +817,8 @@ void
 virBufferEscapeShell(virBufferPtr buf, const char *str)
 {
     int len;
-    char *escaped, *out;
+    VIR_AUTOFREE(char *) escaped = NULL;
+    char *out;
     const char *cur;
 
     if ((buf == NULL) || (str == NULL))
@@ -862,7 +862,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
     *out = 0;
 
     virBufferAdd(buf, escaped, -1);
-    VIR_FREE(escaped);
 }
 
 /**