mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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.
This commit is contained in:
parent
4a9019afbb
commit
6fee3da262
@ -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)
|
|||||||
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, ...)
|
|||||||
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, ...)
|
|||||||
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
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(escaped, 2 * len + 1) < 0) {
|
if (VIR_ALLOC_N(escaped, 2 * len + 1) < 0) {
|
||||||
virBufferNoMemory(buf);
|
virBufferSetError(buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user