#include "qemud.h"
#include "event.h"
+#include "memory.h"
#define EVENT_DEBUG(fmt, ...) qemudDebug("EVENT: " fmt, __VA_ARGS__)
int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque) {
EVENT_DEBUG("Add handle %d %d %p %p", fd, events, cb, opaque);
if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
- struct virEventHandle *tmp;
EVENT_DEBUG("Used %d handle slots, adding %d more",
eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.handles,
- sizeof(struct virEventHandle) *
- (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.handles,
+ (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.handles = tmp;
eventLoop.handlesAlloc += EVENT_ALLOC_EXTENT;
}
}
if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) {
- struct virEventTimeout *tmp;
EVENT_DEBUG("Used %d timeout slots, adding %d more",
eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.timeouts,
- sizeof(struct virEventTimeout) *
- (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.timeouts,
+ (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.timeouts = tmp;
eventLoop.timeoutsAlloc += EVENT_ALLOC_EXTENT;
}
}
*retfds = NULL;
/* Setup the poll file handle data structs */
- if (!(fds = malloc(sizeof(*fds) * nfds)))
+ if (VIR_ALLOC_N(fds, nfds) < 0)
return -1;
for (i = 0, nfds = 0 ; i < eventLoop.handlesCount ; i++) {
/* Release some memory if we've got a big chunk free */
if ((eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT) > eventLoop.timeoutsCount) {
- struct virEventTimeout *tmp;
EVENT_DEBUG("Releasing %d out of %d timeout slots used, releasing %d",
eventLoop.timeoutsCount, eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.timeouts,
- sizeof(struct virEventTimeout) *
- (eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.timeouts,
+ (eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.timeouts = tmp;
eventLoop.timeoutsAlloc -= EVENT_ALLOC_EXTENT;
}
return 0;
/* Release some memory if we've got a big chunk free */
if ((eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT) > eventLoop.handlesCount) {
- struct virEventHandle *tmp;
EVENT_DEBUG("Releasing %d out of %d handles slots used, releasing %d",
eventLoop.handlesCount, eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.handles,
- sizeof(struct virEventHandle) *
- (eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.handles,
+ (eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.handles = tmp;
eventLoop.handlesAlloc -= EVENT_ALLOC_EXTENT;
}
return 0;
return -1;
if (virEventCalculateTimeout(&timeout) < 0) {
- free(fds);
+ VIR_FREE(fds);
return -1;
}
if (errno == EINTR) {
goto retry;
}
- free(fds);
+ VIR_FREE(fds);
return -1;
}
if (virEventDispatchTimeouts() < 0) {
- free(fds);
+ VIR_FREE(fds);
return -1;
}
if (ret > 0 &&
virEventDispatchHandles(fds) < 0) {
- free(fds);
+ VIR_FREE(fds);
return -1;
}
- free(fds);
+ VIR_FREE(fds);
if (virEventCleanupTimeouts() < 0)
return -1;
#include "mdns.h"
#include "event.h"
#include "remote_internal.h"
+#include "memory.h"
#define AVAHI_DEBUG(fmt, ...) qemudDebug("AVAHI: " fmt, __VA_ARGS__)
/* A service name collision happened. Let's pick a new name */
n = avahi_alternative_service_name(group->name);
- free(group->name);
+ VIR_FREE(group->name);
group->name = n;
AVAHI_DEBUG("Group name collision, renaming service to '%s'", group->name);
static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED,
int fd, AvahiWatchEvent event, AvahiWatchCallback cb, void *userdata) {
- AvahiWatch *w = malloc(sizeof(*w));
- if (!w)
+ AvahiWatch *w;
+ if (VIR_ALLOC(w) < 0)
return NULL;
w->fd = fd;
AVAHI_DEBUG("New handle %p FD %d Event %d", w, w->fd, event);
if (virEventAddHandleImpl(fd, event, libvirtd_mdns_watch_dispatch, w) < 0) {
- free(w);
+ VIR_FREE(w);
return NULL;
}
{
AVAHI_DEBUG("Free handle %p %d", w, w->fd);
virEventRemoveHandleImpl(w->fd);
- free(w);
+ VIR_FREE(w);
}
static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opaque)
AvahiTimeoutCallback cb,
void *userdata)
{
- AvahiTimeout *t = malloc(sizeof(*t));
+ AvahiTimeout *t;
struct timeval now;
long long nowms, thenms, timeout;
AVAHI_DEBUG("Add timeout %p TV %p", t, tv);
- if (!t)
+ if (VIR_ALLOC(t) < 0)
return NULL;
if (gettimeofday(&now, NULL) < 0) {
- free(t);
+ VIR_FREE(t);
return NULL;
}
t->userdata = userdata;
if (t->timer < 0) {
- free(t);
+ VIR_FREE(t);
return NULL;
}
long long nowms, thenms, timeout;
AVAHI_DEBUG("Update timeout %p TV %p", t, tv);
if (gettimeofday(&now, NULL) < 0) {
- free(t);
+ VIR_FREE(t);
return;
}
{
AVAHI_DEBUG("Free timeout %p", t);
virEventRemoveTimeoutImpl(t->timer);
- free(t);
+ VIR_FREE(t);
}
static AvahiPoll *libvirtd_create_poll(void)
{
- AvahiPoll *p = malloc(sizeof(*p));
- if (!p)
+ AvahiPoll *p;
+ if (VIR_ALLOC(p) < 0)
return NULL;
p->userdata = NULL;
struct libvirtd_mdns *libvirtd_mdns_new(void)
{
- struct libvirtd_mdns *mdns = malloc(sizeof(*mdns));
- if (!mdns)
+ struct libvirtd_mdns *mdns;
+ if (VIR_ALLOC(mdns) < 0)
return NULL;
- memset(mdns, 0, sizeof(*mdns));
/* Allocate main loop object */
if (!(mdns->poller = libvirtd_create_poll())) {
- free(mdns);
+ VIR_FREE(mdns);
return NULL;
}
}
struct libvirtd_mdns_group *libvirtd_mdns_add_group(struct libvirtd_mdns *mdns, const char *name) {
- struct libvirtd_mdns_group *group = malloc(sizeof(*group));
+ struct libvirtd_mdns_group *group;
AVAHI_DEBUG("Adding group '%s'", name);
- if (!group)
+ if (VIR_ALLOC(group) < 0)
return NULL;
- memset(group, 0, sizeof(*group));
if (!(group->name = strdup(name))) {
- free(group);
+ VIR_FREE(group);
return NULL;
}
group->mdns = mdns;
while (tmp) {
if (tmp == group) {
- free(group->name);
+ VIR_FREE(group->name);
if (prev)
prev->next = group->next;
else
group->mdns->group = group->next;
- free(group);
+ VIR_FREE(group);
return;
}
prev = tmp;
}
struct libvirtd_mdns_entry *libvirtd_mdns_add_entry(struct libvirtd_mdns_group *group, const char *type, int port) {
- struct libvirtd_mdns_entry *entry = malloc(sizeof(*entry));
+ struct libvirtd_mdns_entry *entry;
AVAHI_DEBUG("Adding entry %s %d to group %s", type, port, group->name);
- if (!entry)
+ if (VIR_ALLOC(entry) < 0)
return NULL;
entry->port = port;
if (!(entry->type = strdup(type))) {
- free(entry);
+ VIR_FREE(entry);
return NULL;
}
entry->next = group->entry;
while (tmp) {
if (tmp == entry) {
- free(entry->type);
+ VIR_FREE(entry->type);
if (prev)
prev->next = entry->next;
else
#include "remote_internal.h"
#include "conf.h"
#include "event.h"
+#include "memory.h"
#ifdef HAVE_AVAHI
#include "mdns.h"
#endif
static int qemudListenUnix(struct qemud_server *server,
const char *path, int readonly, int auth) {
- struct qemud_socket *sock = calloc(1, sizeof(*sock));
+ struct qemud_socket *sock;
struct sockaddr_un addr;
mode_t oldmask;
gid_t oldgrp;
- if (!sock) {
+ if (VIR_ALLOC(sock) < 0) {
qemudLog(QEMUD_ERR,
"%s", _("Failed to allocate memory for struct qemud_socket"));
return -1;
struct sockaddr_storage sa;
socklen_t salen = sizeof(sa);
- sock = calloc (1, sizeof *sock);
-
- if (!sock) {
+ if (VIR_ALLOC(sock) < 0) {
qemudLog (QEMUD_ERR,
_("remoteListenTCP: calloc: %s"), strerror (errno));
- return -1;
+ goto cleanup;
}
sock->readonly = 0;
sock->auth = auth;
if (getsockname(sock->fd, (struct sockaddr *)(&sa), &salen) < 0)
- return -1;
+ goto cleanup;
if (sa.ss_family == AF_INET)
sock->port = htons(((struct sockaddr_in*)&sa)->sin_port);
if (qemudSetCloseExec(sock->fd) < 0 ||
qemudSetNonBlock(sock->fd) < 0)
- return -1;
+ goto cleanup;
if (listen (sock->fd, 30) < 0) {
qemudLog (QEMUD_ERR,
_("remoteListenTCP: listen: %s"), strerror (errno));
- return -1;
+ goto cleanup;
}
if (virEventAddHandleImpl(sock->fd,
qemudDispatchServerEvent,
server) < 0) {
qemudLog(QEMUD_ERR, "%s", _("Failed to add server event callback"));
- return -1;
+ goto cleanup;
}
}
return 0;
+
+cleanup:
+ for (i = 0; i < nfds; ++i)
+ close(fds[0]);
+ return -1;
}
static int qemudInitPaths(struct qemud_server *server,
static struct qemud_server *qemudInitialize(int sigread) {
struct qemud_server *server;
- if (!(server = calloc(1, sizeof(*server)))) {
+ if (VIR_ALLOC(server) < 0) {
qemudLog(QEMUD_ERR, "%s", _("Failed to allocate struct qemud_server"));
return NULL;
}
return -1;
}
- client = calloc(1, sizeof(*client));
- if (client == NULL)
+ if (VIR_ALLOC(client) < 0)
goto cleanup;
client->magic = QEMUD_CLIENT_MAGIC;
client->fd = fd;
switch (p->type) {
case VIR_CONF_STRING:
- list = malloc (2 * sizeof (*list));
- if (list == NULL) {
+ if (VIR_ALLOC_N(list, 2) < 0) {
qemudLog (QEMUD_ERR,
_("failed to allocate memory for %s config list"), key);
return -1;
qemudLog (QEMUD_ERR,
_("failed to allocate memory for %s config list value"),
key);
- free (list);
+ VIR_FREE(list);
return -1;
}
break;
virConfValuePtr pp;
for (pp = p->list; pp; pp = pp->next)
len++;
- list = calloc (1+len, sizeof (*list));
- if (list == NULL) {
+ if (VIR_ALLOC_N(list, 1+len) < 0) {
qemudLog (QEMUD_ERR,
_("failed to allocate memory for %s config list"), key);
return -1;
qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s: %s:"
" must be a string or list of strings\n"),
filename, key);
- free (list);
+ VIR_FREE(list);
return -1;
}
list[i] = strdup (pp->str);
if (list[i] == NULL) {
int j;
for (j = 0 ; j < i ; j++)
- free (list[j]);
- free (list);
+ VIR_FREE(list[j]);
+ VIR_FREE(list);
qemudLog (QEMUD_ERR, _("failed to allocate memory"
" for %s config list value"), key);
return -1;
#include "internal.h"
#include "qemud.h"
+#include "memory.h"
#define DEBUG 0
}
/* Allocate return buffer. */
- ret->freeMems.freeMems_val = calloc (args->maxCells, sizeof (*(ret->freeMems.freeMems_val)));
+ if (VIR_ALLOC_N(ret->freeMems.freeMems_val, args->maxCells) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->freeMems.freeMems_len = virNodeGetCellsFreeMemory(client->conn,
(unsigned long long *)ret->freeMems.freeMems_val,
args->startCell,
args->maxCells);
- if (ret->freeMems.freeMems_len == 0)
+ if (ret->freeMems.freeMems_len == 0) {
+ VIR_FREE(ret->freeMems.freeMems_val);
return -1;
+ }
return 0;
}
remoteDispatchError (client, req, "%s", _("nparams too large"));
return -2;
}
- params = malloc (sizeof (*params) * nparams);
- if (params == NULL) {
- remoteDispatchError (client, req, "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(params, nparams) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
dom = get_nonnull_domain (client->conn, args->dom);
if (dom == NULL) {
- free (params);
+ VIR_FREE(params);
remoteDispatchError (client, req, "%s", _("domain not found"));
return -2;
}
r = virDomainGetSchedulerParameters (dom, params, &nparams);
if (r == -1) {
virDomainFree(dom);
- free (params);
+ VIR_FREE(params);
return -1;
}
/* Serialise the scheduler parameters. */
ret->params.params_len = nparams;
- ret->params.params_val = malloc (sizeof (*(ret->params.params_val))
- * nparams);
- if (ret->params.params_val == NULL) {
- virDomainFree(dom);
- free (params);
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating return array"));
- return -2;
- }
+ if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0)
+ goto oom;
for (i = 0; i < nparams; ++i) {
// remoteDispatchClientRequest will free this:
ret->params.params_val[i].field = strdup (params[i].field);
- if (ret->params.params_val[i].field == NULL) {
- virDomainFree(dom);
- free (params);
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating return array"));
- return -2;
- }
+ if (ret->params.params_val[i].field == NULL)
+ goto oom;
+
ret->params.params_val[i].value.type = params[i].type;
switch (params[i].type) {
case VIR_DOMAIN_SCHED_FIELD_INT:
case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
ret->params.params_val[i].value.remote_sched_param_value_u.b = params[i].value.b; break;
default:
- virDomainFree(dom);
- free (params);
remoteDispatchError (client, req, "%s", _("unknown type"));
- return -2;
+ goto cleanup;
}
}
virDomainFree(dom);
- free (params);
+ VIR_FREE(params);
return 0;
+
+oom:
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+cleanup:
+ virDomainFree(dom);
+ for (i = 0 ; i < nparams ; i++)
+ VIR_FREE(ret->params.params_val[i].field);
+ VIR_FREE(params);
+ return -2;
}
static int
remoteDispatchError (client, req, "%s", _("nparams too large"));
return -2;
}
- params = malloc (sizeof (*params) * nparams);
- if (params == NULL) {
- remoteDispatchError (client, req, "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(params, nparams)) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
dom = get_nonnull_domain (client->conn, args->dom);
if (dom == NULL) {
- free (params);
+ VIR_FREE(params);
remoteDispatchError (client, req, "%s", _("domain not found"));
return -2;
}
r = virDomainSetSchedulerParameters (dom, params, nparams);
virDomainFree(dom);
- free (params);
+ VIR_FREE(params);
if (r == -1) return -1;
return 0;
flags = args->flags;
if (size > REMOTE_DOMAIN_BLOCK_PEEK_BUFFER_MAX) {
+ virDomainFree (dom);
remoteDispatchError (client, req,
"%s", _("size > maximum buffer size"));
return -2;
}
ret->buffer.buffer_len = size;
- ret->buffer.buffer_val = malloc (size);
- if (!ret->buffer.buffer_val) {
+ if (VIR_ALLOC_N(ret->buffer.buffer_val, size) < 0) {
+ virDomainFree (dom);
remoteDispatchError (client, req, "%s", strerror (errno));
return -2;
}
remote_domain_get_vcpus_args *args,
remote_domain_get_vcpus_ret *ret)
{
- virDomainPtr dom;
- virVcpuInfoPtr info;
- unsigned char *cpumaps;
+ virDomainPtr dom = NULL;
+ virVcpuInfoPtr info = NULL;
+ unsigned char *cpumaps = NULL;
int info_len, i;
CHECK_CONN(client);
}
/* Allocate buffers to take the results. */
- info = calloc (args->maxinfo, sizeof (*info));
- cpumaps = calloc (args->maxinfo * args->maplen, sizeof (*cpumaps));
+ if (VIR_ALLOC_N(info, args->maxinfo) < 0)
+ goto oom;
+ if (VIR_ALLOC_N(cpumaps, args->maxinfo) < 0)
+ goto oom;
info_len = virDomainGetVcpus (dom,
info, args->maxinfo,
cpumaps, args->maplen);
if (info_len == -1) {
+ VIR_FREE(info);
+ VIR_FREE(cpumaps);
virDomainFree(dom);
return -1;
}
/* Allocate the return buffer for info. */
ret->info.info_len = info_len;
- ret->info.info_val = calloc (info_len, sizeof (*(ret->info.info_val)));
+ if (VIR_ALLOC_N(ret->info.info_val, info_len) < 0)
+ goto oom;
for (i = 0; i < info_len; ++i) {
ret->info.info_val[i].number = info[i].number;
ret->cpumaps.cpumaps_len = args->maxinfo * args->maplen;
ret->cpumaps.cpumaps_val = (char *) cpumaps;
+ VIR_FREE(info);
virDomainFree(dom);
return 0;
+
+oom:
+ VIR_FREE(info);
+ VIR_FREE(cpumaps);
+ virDomainFree(dom);
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
}
static int
dname = args->dname == NULL ? NULL : *args->dname;
/* Wacky world of XDR ... */
- uri_out = calloc (1, sizeof (*uri_out));
+ if (VIR_ALLOC(uri_out) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
r = __virDomainMigratePrepare (client->conn, &cookie, &cookielen,
uri_in, uri_out,
args->flags, dname, args->resource);
if (r == -1) {
- free(uri_out);
+ VIR_FREE(uri_out);
return -1;
}
ret->cookie.cookie_val = cookie;
if (*uri_out == NULL) {
ret->uri_out = NULL;
- free(uri_out);
+ VIR_FREE(uri_out);
} else {
ret->uri_out = uri_out;
}
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListDefinedDomains (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListDefinedNetworks (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
}
/* Allocate return buffer. */
- ret->ids.ids_val = calloc (args->maxids, sizeof (*(ret->ids.ids_val)));
+ if (VIR_ALLOC_N(ret->ids.ids_val, args->maxids) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->ids.ids_len = virConnectListDomains (client->conn,
ret->ids.ids_val, args->maxids);
- if (ret->ids.ids_len == -1) return -1;
+ if (ret->ids.ids_len == -1) {
+ VIR_FREE(ret->ids.ids_val);
+ return -1;
+ }
return 0;
}
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListNetworks (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_len);
+ return -1;
+ }
return 0;
}
remote_auth_list_ret *ret)
{
ret->types.types_len = 1;
- if ((ret->types.types_val = calloc (ret->types.types_len, sizeof (*(ret->types.types_val)))) == NULL) {
- remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, "auth types");
+ if (VIR_ALLOC_N(ret->types.types_val, ret->types.types_len) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
ret->types.types_val[0] = client->auth;
return NULL;
}
- addr = malloc(strlen(host) + 1 + strlen(port) + 1);
- if (!addr) {
- remoteDispatchError(client, req, "%s", _("cannot allocate address"));
+ if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
if (getpeername(client->fd, (struct sockaddr*)&sa, &salen) < 0) {
remoteDispatchError(client, req, _("failed to get peer address %d (%s)"),
errno, strerror(errno));
- free(localAddr);
+ VIR_FREE(localAddr);
return -2;
}
if ((remoteAddr = addrToString(client, req, &sa, salen)) == NULL) {
- free(localAddr);
+ VIR_FREE(localAddr);
return -2;
}
NULL, /* XXX Callbacks */
SASL_SUCCESS_DATA,
&client->saslconn);
- free(localAddr);
- free(remoteAddr);
+ VIR_FREE(localAddr);
+ VIR_FREE(remoteAddr);
if (err != SASL_OK) {
qemudLog(QEMUD_ERR, _("sasl context setup failed %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
/* NB, distinction of NULL vs "" is *critical* in SASL */
if (serverout) {
- ret->data.data_val = malloc(serveroutlen);
- if (!ret->data.data_val) {
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
memcpy(ret->data.data_val, serverout, serveroutlen);
/* NB, distinction of NULL vs "" is *critical* in SASL */
if (serverout) {
- ret->data.data_val = malloc(serveroutlen);
- if (!ret->data.data_val) {
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
memcpy(ret->data.data_val, serverout, serveroutlen);
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListDefinedStoragePools (client->conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ ret->names.names_val, args->maxnames);
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListStoragePools (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ virStoragePoolFree(pool);
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virStoragePoolListVolumes (pool,
ret->names.names_val, args->maxnames);
virStoragePoolFree(pool);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}