提交 6fee3da2 编写于 作者: W Wen Congyang

free buf->content when vsnprintf() failed

When buf->error is 1, we do not return buf->content in the function
virBufferContentAndReset(). So we should free buf->content when
vsnprintf() failed.
上级 4a9019af
...@@ -39,7 +39,7 @@ struct _virBuffer { ...@@ -39,7 +39,7 @@ struct _virBuffer {
* freeing the content and setting the error flag. * freeing the content and setting the error flag.
*/ */
static void static void
virBufferNoMemory(const virBufferPtr buf) virBufferSetError(const virBufferPtr buf)
{ {
VIR_FREE(buf->content); VIR_FREE(buf->content);
buf->size = 0; buf->size = 0;
...@@ -70,7 +70,7 @@ virBufferGrow(virBufferPtr buf, unsigned int len) ...@@ -70,7 +70,7 @@ virBufferGrow(virBufferPtr buf, unsigned int len)
size = buf->use + len + 1000; size = buf->use + len + 1000;
if (VIR_REALLOC_N(buf->content, size) < 0) { if (VIR_REALLOC_N(buf->content, size) < 0) {
virBufferNoMemory(buf); virBufferSetError(buf);
return -1; return -1;
} }
buf->size = size; buf->size = size;
...@@ -241,7 +241,7 @@ virBufferVSprintf(const virBufferPtr buf, const char *format, ...) ...@@ -241,7 +241,7 @@ virBufferVSprintf(const virBufferPtr buf, const char *format, ...)
size = buf->size - buf->use; size = buf->size - buf->use;
if ((count = vsnprintf(&buf->content[buf->use], if ((count = vsnprintf(&buf->content[buf->use],
size, format, argptr)) < 0) { size, format, argptr)) < 0) {
buf->error = 1; virBufferSetError(buf);
goto err; goto err;
} }
...@@ -259,7 +259,7 @@ virBufferVSprintf(const virBufferPtr buf, const char *format, ...) ...@@ -259,7 +259,7 @@ virBufferVSprintf(const virBufferPtr buf, const char *format, ...)
size = buf->size - buf->use; size = buf->size - buf->use;
if ((count = vsnprintf(&buf->content[buf->use], if ((count = vsnprintf(&buf->content[buf->use],
size, format, argptr)) < 0) { size, format, argptr)) < 0) {
buf->error = 1; virBufferSetError(buf);
goto err; goto err;
} }
} }
...@@ -299,7 +299,7 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st ...@@ -299,7 +299,7 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st
} }
if (VIR_ALLOC_N(escaped, 6 * len + 1) < 0) { if (VIR_ALLOC_N(escaped, 6 * len + 1) < 0) {
virBufferNoMemory(buf); virBufferSetError(buf);
return; return;
} }
...@@ -386,7 +386,7 @@ virBufferEscapeSexpr(const virBufferPtr buf, ...@@ -386,7 +386,7 @@ virBufferEscapeSexpr(const virBufferPtr buf,
} }
if (VIR_ALLOC_N(escaped, 2 * len + 1) < 0) { if (VIR_ALLOC_N(escaped, 2 * len + 1) < 0) {
virBufferNoMemory(buf); virBufferSetError(buf);
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册