diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index ea967045e7eaac61538249d250dd28e35a451af0..86bc17957fa697f3d082b5d27b079bb2425e35b6 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -31,10 +31,10 @@ #define __VIR_BUFFER_C__ #include "virbuffer.h" -#include "viralloc.h" #include "virerror.h" #include "virstring.h" +#define VIR_FROM_THIS VIR_FROM_NONE /* If adding more fields, ensure to edit buf.h to match the number of fields */ @@ -656,6 +656,19 @@ struct _virBufferEscapePair { char *toescape; }; +static void +virBufferEscapePairFree(virBufferEscapePairPtr pair) +{ + if (!pair) + return; + + VIR_FREE(pair->toescape); + VIR_FREE(pair); +} + +VIR_DEFINE_AUTOPTR_FUNC(virBufferEscapePair, virBufferEscapePairFree) + + /** * virBufferEscapeN: * @buf: the buffer to append to @@ -696,7 +709,7 @@ virBufferEscapeN(virBufferPtr buf, va_start(ap, str); while ((escapeItem.escape = va_arg(ap, int))) { - if (!(escapeItem.toescape = va_arg(ap, char *))) { + if (VIR_STRDUP(escapeItem.toescape, va_arg(ap, char *)) < 0) { virBufferSetError(buf, errno); goto cleanup; } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index e95ee878a17546c9c3779b1b6aec3becaeeffe09..c662e8ea7206b252822ae1eaa0b304b01d04a91c 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -23,9 +23,11 @@ #ifndef __VIR_BUFFER_H__ # define __VIR_BUFFER_H__ +# include + # include "internal.h" +# include "viralloc.h" -# include /** * virBuffer: @@ -119,4 +121,6 @@ int virBufferGetIndent(const virBuffer *buf, bool dynamic); void virBufferTrim(virBufferPtr buf, const char *trim, int len); void virBufferAddStr(virBufferPtr buf, const char *str); +VIR_DEFINE_AUTOPTR_FUNC(virBuffer, virBufferFreeAndReset) + #endif /* __VIR_BUFFER_H__ */