mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Convert to use new memory allocation APIs
This commit is contained in:
parent
489da1c4b1
commit
46f52f32b2
@ -1,3 +1,7 @@
|
|||||||
|
Thu May 29 14:45:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/buf.c: Convert to use new memory allocation APIs
|
||||||
|
|
||||||
Thu May 29 14:44:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
|
Thu May 29 14:44:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/xend_internal.c: Fix missing check for failure
|
* src/xend_internal.c: Fix missing check for failure
|
||||||
|
16
src/buf.c
16
src/buf.c
@ -19,6 +19,7 @@
|
|||||||
#define __VIR_BUFFER_C__
|
#define __VIR_BUFFER_C__
|
||||||
|
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
|
||||||
/* If adding more fields, ensure to edit buf.h to match
|
/* If adding more fields, ensure to edit buf.h to match
|
||||||
@ -40,8 +41,7 @@ struct _virBuffer {
|
|||||||
static void
|
static void
|
||||||
virBufferNoMemory(const virBufferPtr buf)
|
virBufferNoMemory(const virBufferPtr buf)
|
||||||
{
|
{
|
||||||
free(buf->content);
|
VIR_FREE(buf->content);
|
||||||
buf->content = NULL;
|
|
||||||
buf->size = 0;
|
buf->size = 0;
|
||||||
buf->use = 0;
|
buf->use = 0;
|
||||||
buf->error = 1;
|
buf->error = 1;
|
||||||
@ -60,7 +60,6 @@ static int
|
|||||||
virBufferGrow(virBufferPtr buf, unsigned int len)
|
virBufferGrow(virBufferPtr buf, unsigned int len)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
char *newbuf;
|
|
||||||
|
|
||||||
if (buf->error)
|
if (buf->error)
|
||||||
return -1;
|
return -1;
|
||||||
@ -70,12 +69,10 @@ virBufferGrow(virBufferPtr buf, unsigned int len)
|
|||||||
|
|
||||||
size = buf->use + len + 1000;
|
size = buf->use + len + 1000;
|
||||||
|
|
||||||
newbuf = realloc(buf->content, size);
|
if (VIR_REALLOC_N(buf->content, size) < 0) {
|
||||||
if (newbuf == NULL) {
|
|
||||||
virBufferNoMemory(buf);
|
virBufferNoMemory(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buf->content = newbuf;
|
|
||||||
buf->size = size;
|
buf->size = size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -269,8 +266,7 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
escaped = malloc(5 * len + 1);
|
if (VIR_ALLOC_N(escaped, 5 * len + 1) < 0) {
|
||||||
if (escaped == NULL) {
|
|
||||||
virBufferNoMemory(buf);
|
virBufferNoMemory(buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -314,14 +310,14 @@ virBufferEscapeString(const virBufferPtr buf, const char *format, const char *st
|
|||||||
buf->content[buf->use] = 0;
|
buf->content[buf->use] = 0;
|
||||||
grow_size = (count > 1000) ? count : 1000;
|
grow_size = (count > 1000) ? count : 1000;
|
||||||
if (virBufferGrow(buf, grow_size) < 0) {
|
if (virBufferGrow(buf, grow_size) < 0) {
|
||||||
free(escaped);
|
VIR_FREE(escaped);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size = buf->size - buf->use - 1;
|
size = buf->size - buf->use - 1;
|
||||||
}
|
}
|
||||||
buf->use += count;
|
buf->use += count;
|
||||||
buf->content[buf->use] = '\0';
|
buf->content[buf->use] = '\0';
|
||||||
free(escaped);
|
VIR_FREE(escaped);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user