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(a)gmail.com>
---
src/util/virbuffer.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 65f4a08..a35feb6 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -455,7 +455,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,
@@ -532,7 +533,6 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char
*str)
*out = 0;
virBufferAsprintf(buf, format, escaped);
- VIR_FREE(escaped);
}
/**
@@ -611,7 +611,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))
@@ -643,7 +644,6 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
*out = 0;
virBufferAsprintf(buf, format, escaped);
- VIR_FREE(escaped);
}
@@ -687,7 +687,7 @@ virBufferEscapeN(virBufferPtr buf,
{
int len;
size_t i;
- char *escaped = NULL;
+ VIR_AUTOFREE(char *) escaped = NULL;
char *out;
const char *cur;
virBufferEscapePair escapeItem;
@@ -750,7 +750,6 @@ virBufferEscapeN(virBufferPtr buf,
cleanup:
va_end(ap);
VIR_FREE(escapeList);
- VIR_FREE(escaped);
}
@@ -815,7 +814,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))
@@ -859,7 +859,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
*out = 0;
virBufferAdd(buf, escaped, -1);
- VIR_FREE(escaped);
}
/**
--
1.8.3.1