1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Use a variable name as sizeof argument, not a type name.

Given code like: T *var = calloc (n, sizeof (T));
Convert to this: T *var = calloc (n, sizeof (*var));
This first-cut change adjusts all malloc, calloc, and
realloc statements.

The only binary differences are in remote_internal.c
(due to the bug fix) and in xmlrpc.c (due to factorization).

* python/libvir.c: As above.
* qemud/event.c: Likewise.
* qemud/mdns.c: Likewise.
* qemud/qemud.c: Likewise.
* qemud/remote.c: Likewise.
* src/bridge.c: Likewise.
* src/buf.c: Likewise.
* src/conf.c: Likewise.
* src/hash.c: Likewise.
* src/iptables.c: Likewise.
* src/openvz_conf.c: Likewise.
* src/qemu_conf.c: Likewise.
* src/qemu_driver.c: Likewise.
* src/test.c: Likewise.
* src/xen_internal.c: Likewise.
* src/xen_unified.c: Likewise.
* src/xm_internal.c: Likewise.
* src/xml.c: Likewise.
* tests/qemuxml2argvtest.c: Likewise.
* src/xmlrpc.c (xmlRpcValuePtr): Likewise, and minor factorization.
* src/remote_internal.c (remoteAuthMakeCredentials): Use the right
type when allocating space for an array of cred _pointers_.
This commit is contained in:
Jim Meyering 2007-12-11 21:57:29 +00:00
parent 5a190594f4
commit 49230350fa
22 changed files with 150 additions and 116 deletions

View File

@ -1,3 +1,35 @@
Tue Dec 11 22:56:47 CET 2007 Jim Meyering <meyering@redhat.com>
Use a variable name as sizeof argument, not a type name.
Given code like: T *var = calloc (n, sizeof (T));
Convert to this: T *var = calloc (n, sizeof (*var));
This first-cut change adjusts all malloc, calloc, and
realloc statements.
The only binary differences are in remote_internal.c
(due to the bug fix) and in xmlrpc.c (due to factorization).
* python/libvir.c: As above.
* qemud/event.c: Likewise.
* qemud/mdns.c: Likewise.
* qemud/qemud.c: Likewise.
* qemud/remote.c: Likewise.
* src/bridge.c: Likewise.
* src/buf.c: Likewise.
* src/conf.c: Likewise.
* src/hash.c: Likewise.
* src/iptables.c: Likewise.
* src/openvz_conf.c: Likewise.
* src/qemu_conf.c: Likewise.
* src/qemu_driver.c: Likewise.
* src/test.c: Likewise.
* src/xen_internal.c: Likewise.
* src/xen_unified.c: Likewise.
* src/xm_internal.c: Likewise.
* src/xml.c: Likewise.
* tests/qemuxml2argvtest.c: Likewise.
* src/xmlrpc.c (xmlRpcValuePtr): Likewise, and minor factorization.
* src/remote_internal.c (remoteAuthMakeCredentials): Use the right
type when allocating space for an array of cred _pointers_.
Tue Dec 11 22:19:22 CET 2007 Jim Meyering <meyering@redhat.com> Tue Dec 11 22:19:22 CET 2007 Jim Meyering <meyering@redhat.com>
Test libvirtd's config-processing code. Test libvirtd's config-processing code.

View File

@ -347,7 +347,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
auth.ncredtype = PyList_Size(pycredtype); auth.ncredtype = PyList_Size(pycredtype);
if (auth.ncredtype) { if (auth.ncredtype) {
int i; int i;
auth.credtype = malloc(sizeof(int) * auth.ncredtype); auth.credtype = malloc(sizeof(*auth.credtype) * auth.ncredtype);
if (auth.credtype == NULL) { if (auth.credtype == NULL) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
@ -490,7 +490,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
} }
if (c_retval) { if (c_retval) {
names = malloc(sizeof(char *) * c_retval); names = malloc(sizeof(*names) * c_retval);
if (!names) { if (!names) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
@ -670,7 +670,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
} }
if (c_retval) { if (c_retval) {
names = malloc(sizeof(char *) * c_retval); names = malloc(sizeof(*names) * c_retval);
if (!names) { if (!names) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
@ -717,7 +717,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
} }
if (c_retval) { if (c_retval) {
names = malloc(sizeof(char *) * c_retval); names = malloc(sizeof(*names) * c_retval);
if (!names) { if (!names) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
@ -863,8 +863,8 @@ PyObject * libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED,
goto error; goto error;
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
freeMems = (unsigned long long *) freeMems =
malloc(maxCells * sizeof(unsigned long long)); malloc(maxCells * sizeof(*freeMems));
if (freeMems == NULL) if (freeMems == NULL)
goto error; goto error;

View File

@ -281,7 +281,7 @@ static int virEventMakePollFDs(struct pollfd **retfds) {
} }
*retfds = NULL; *retfds = NULL;
/* Setup the poll file handle data structs */ /* Setup the poll file handle data structs */
if (!(fds = malloc(sizeof(struct pollfd) * nfds))) if (!(fds = malloc(sizeof(*fds) * nfds)))
return -1; return -1;
for (i = 0, nfds = 0 ; i < eventLoop.handlesCount ; i++) { for (i = 0, nfds = 0 ; i < eventLoop.handlesCount ; i++) {

View File

@ -239,7 +239,7 @@ static void libvirtd_mdns_watch_dispatch(int fd, int events, void *opaque)
static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED, static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED,
int fd, AvahiWatchEvent event, AvahiWatchCallback cb, void *userdata) { int fd, AvahiWatchEvent event, AvahiWatchCallback cb, void *userdata) {
AvahiWatch *w = malloc(sizeof(AvahiWatch)); AvahiWatch *w = malloc(sizeof(*w));
if (!w) if (!w)
return NULL; return NULL;
@ -289,7 +289,7 @@ static AvahiTimeout *libvirtd_mdns_timeout_new(const AvahiPoll *api ATTRIBUTE_UN
AvahiTimeoutCallback cb, AvahiTimeoutCallback cb,
void *userdata) void *userdata)
{ {
AvahiTimeout *t = malloc(sizeof(AvahiTimeout)); AvahiTimeout *t = malloc(sizeof(*t));
struct timeval now; struct timeval now;
long long nowms, thenms, timeout; long long nowms, thenms, timeout;
AVAHI_DEBUG("Add timeout %p TV %p", t, tv); AVAHI_DEBUG("Add timeout %p TV %p", t, tv);
@ -359,7 +359,7 @@ static void libvirtd_mdns_timeout_free(AvahiTimeout *t)
static AvahiPoll *libvirtd_create_poll(void) static AvahiPoll *libvirtd_create_poll(void)
{ {
AvahiPoll *p = malloc(sizeof(AvahiPoll)); AvahiPoll *p = malloc(sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
@ -379,7 +379,7 @@ static AvahiPoll *libvirtd_create_poll(void)
struct libvirtd_mdns *libvirtd_mdns_new(void) struct libvirtd_mdns *libvirtd_mdns_new(void)
{ {
struct libvirtd_mdns *mdns = malloc(sizeof(struct libvirtd_mdns)); struct libvirtd_mdns *mdns = malloc(sizeof(*mdns));
if (!mdns) if (!mdns)
return NULL; return NULL;
memset(mdns, 0, sizeof(*mdns)); memset(mdns, 0, sizeof(*mdns));
@ -408,7 +408,7 @@ int libvirtd_mdns_start(struct libvirtd_mdns *mdns)
} }
struct libvirtd_mdns_group *libvirtd_mdns_add_group(struct libvirtd_mdns *mdns, const char *name) { struct libvirtd_mdns_group *libvirtd_mdns_add_group(struct libvirtd_mdns *mdns, const char *name) {
struct libvirtd_mdns_group *group = malloc(sizeof(struct libvirtd_mdns_group)); struct libvirtd_mdns_group *group = malloc(sizeof(*group));
AVAHI_DEBUG("Adding group '%s'", name); AVAHI_DEBUG("Adding group '%s'", name);
if (!group) if (!group)
@ -444,7 +444,7 @@ void libvirtd_mdns_remove_group(struct libvirtd_mdns *mdns, struct libvirtd_mdns
} }
struct libvirtd_mdns_entry *libvirtd_mdns_add_entry(struct libvirtd_mdns_group *group, const char *type, int port) { 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(struct libvirtd_mdns_entry)); struct libvirtd_mdns_entry *entry = malloc(sizeof(*entry));
AVAHI_DEBUG("Adding entry %s %d to group %s", type, port, group->name); AVAHI_DEBUG("Adding entry %s %d to group %s", type, port, group->name);
if (!entry) if (!entry)

View File

@ -460,7 +460,7 @@ static int qemudWritePidFile(const char *pidFile) {
static int qemudListenUnix(struct qemud_server *server, static int qemudListenUnix(struct qemud_server *server,
const char *path, int readonly, int auth) { const char *path, int readonly, int auth) {
struct qemud_socket *sock = calloc(1, sizeof(struct qemud_socket)); struct qemud_socket *sock = calloc(1, sizeof(*sock));
struct sockaddr_un addr; struct sockaddr_un addr;
mode_t oldmask; mode_t oldmask;
gid_t oldgrp; gid_t oldgrp;
@ -703,7 +703,7 @@ static int qemudInitPaths(struct qemud_server *server,
static struct qemud_server *qemudInitialize(int sigread) { static struct qemud_server *qemudInitialize(int sigread) {
struct qemud_server *server; struct qemud_server *server;
if (!(server = calloc(1, sizeof(struct qemud_server)))) { if (!(server = calloc(1, sizeof(*server)))) {
qemudLog(QEMUD_ERR, "Failed to allocate struct qemud_server"); qemudLog(QEMUD_ERR, "Failed to allocate struct qemud_server");
return NULL; return NULL;
} }
@ -1043,7 +1043,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
return -1; return -1;
} }
client = calloc(1, sizeof(struct qemud_client)); client = calloc(1, sizeof(*client));
if (client == NULL) if (client == NULL)
goto cleanup; goto cleanup;
client->magic = QEMUD_CLIENT_MAGIC; client->magic = QEMUD_CLIENT_MAGIC;

View File

@ -639,7 +639,7 @@ remoteDispatchDomainGetSchedulerParameters (struct qemud_server *server ATTRIBUT
remoteDispatchError (client, req, "nparams too large"); remoteDispatchError (client, req, "nparams too large");
return -2; return -2;
} }
params = malloc (sizeof (virSchedParameter) * nparams); params = malloc (sizeof (*params) * nparams);
if (params == NULL) { if (params == NULL) {
remoteDispatchError (client, req, "out of memory allocating array"); remoteDispatchError (client, req, "out of memory allocating array");
return -2; return -2;
@ -661,7 +661,7 @@ remoteDispatchDomainGetSchedulerParameters (struct qemud_server *server ATTRIBUT
/* Serialise the scheduler parameters. */ /* Serialise the scheduler parameters. */
ret->params.params_len = nparams; ret->params.params_len = nparams;
ret->params.params_val = malloc (sizeof (struct remote_sched_param) ret->params.params_val = malloc (sizeof (*(ret->params.params_val))
* nparams); * nparams);
if (ret->params.params_val == NULL) { if (ret->params.params_val == NULL) {
virDomainFree(dom); virDomainFree(dom);
@ -726,7 +726,7 @@ remoteDispatchDomainSetSchedulerParameters (struct qemud_server *server ATTRIBUT
remoteDispatchError (client, req, "nparams too large"); remoteDispatchError (client, req, "nparams too large");
return -2; return -2;
} }
params = malloc (sizeof (virSchedParameter) * nparams); params = malloc (sizeof (*params) * nparams);
if (params == NULL) { if (params == NULL) {
remoteDispatchError (client, req, "out of memory allocating array"); remoteDispatchError (client, req, "out of memory allocating array");
return -2; return -2;
@ -1158,8 +1158,8 @@ remoteDispatchDomainGetVcpus (struct qemud_server *server ATTRIBUTE_UNUSED,
} }
/* Allocate buffers to take the results. */ /* Allocate buffers to take the results. */
info = calloc (args->maxinfo, sizeof (virVcpuInfo)); info = calloc (args->maxinfo, sizeof (*info));
cpumaps = calloc (args->maxinfo * args->maplen, sizeof (unsigned char)); cpumaps = calloc (args->maxinfo * args->maplen, sizeof (*cpumaps));
info_len = virDomainGetVcpus (dom, info_len = virDomainGetVcpus (dom,
info, args->maxinfo, info, args->maxinfo,
@ -1171,7 +1171,7 @@ remoteDispatchDomainGetVcpus (struct qemud_server *server ATTRIBUTE_UNUSED,
/* Allocate the return buffer for info. */ /* Allocate the return buffer for info. */
ret->info.info_len = info_len; ret->info.info_len = info_len;
ret->info.info_val = calloc (info_len, sizeof (remote_vcpu_info)); ret->info.info_val = calloc (info_len, sizeof (*(ret->info.info_val)));
for (i = 0; i < info_len; ++i) { for (i = 0; i < info_len; ++i) {
ret->info.info_val[i].number = info[i].number; ret->info.info_val[i].number = info[i].number;
@ -1210,7 +1210,7 @@ remoteDispatchDomainMigratePrepare (struct qemud_server *server ATTRIBUTE_UNUSED
dname = args->dname == NULL ? NULL : *args->dname; dname = args->dname == NULL ? NULL : *args->dname;
/* Wacky world of XDR ... */ /* Wacky world of XDR ... */
uri_out = calloc (1, sizeof (char *)); uri_out = calloc (1, sizeof (*uri_out));
r = __virDomainMigratePrepare (client->conn, &cookie, &cookielen, r = __virDomainMigratePrepare (client->conn, &cookie, &cookielen,
uri_in, uri_out, uri_in, uri_out,
@ -1295,7 +1295,7 @@ remoteDispatchListDefinedDomains (struct qemud_server *server ATTRIBUTE_UNUSED,
} }
/* Allocate return buffer. */ /* Allocate return buffer. */
ret->names.names_val = calloc (args->maxnames, sizeof (char *)); ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
ret->names.names_len = ret->names.names_len =
virConnectListDefinedDomains (client->conn, virConnectListDefinedDomains (client->conn,
@ -1703,7 +1703,7 @@ remoteDispatchListDefinedNetworks (struct qemud_server *server ATTRIBUTE_UNUSED,
} }
/* Allocate return buffer. */ /* Allocate return buffer. */
ret->names.names_val = calloc (args->maxnames, sizeof (char *)); ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
ret->names.names_len = ret->names.names_len =
virConnectListDefinedNetworks (client->conn, virConnectListDefinedNetworks (client->conn,
@ -1729,7 +1729,7 @@ remoteDispatchListDomains (struct qemud_server *server ATTRIBUTE_UNUSED,
} }
/* Allocate return buffer. */ /* Allocate return buffer. */
ret->ids.ids_val = calloc (args->maxids, sizeof (int)); ret->ids.ids_val = calloc (args->maxids, sizeof (*(ret->ids.ids_val)));
ret->ids.ids_len = virConnectListDomains (client->conn, ret->ids.ids_len = virConnectListDomains (client->conn,
ret->ids.ids_val, args->maxids); ret->ids.ids_val, args->maxids);
@ -1754,7 +1754,7 @@ remoteDispatchListNetworks (struct qemud_server *server ATTRIBUTE_UNUSED,
} }
/* Allocate return buffer. */ /* Allocate return buffer. */
ret->names.names_val = calloc (args->maxnames, sizeof (char *)); ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
ret->names.names_len = ret->names.names_len =
virConnectListNetworks (client->conn, virConnectListNetworks (client->conn,
@ -2062,7 +2062,7 @@ remoteDispatchAuthList (struct qemud_server *server ATTRIBUTE_UNUSED,
remote_auth_list_ret *ret) remote_auth_list_ret *ret)
{ {
ret->types.types_len = 1; ret->types.types_len = 1;
if ((ret->types.types_val = calloc (ret->types.types_len, sizeof (remote_auth_type))) == NULL) { 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"); remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, "auth types");
return -2; return -2;
} }

View File

@ -83,7 +83,7 @@ brInit(brControl **ctlp)
return err; return err;
} }
*ctlp = (brControl *)malloc(sizeof(struct _brControl)); *ctlp = malloc(sizeof(**ctlp));
if (!*ctlp) { if (!*ctlp) {
close(fd); close(fd);
return ENOMEM; return ENOMEM;
@ -680,7 +680,7 @@ brSetForwardDelay(brControl *ctl ATTRIBUTE_UNUSED,
snprintf(delayStr, sizeof(delayStr), "%d", delay); snprintf(delayStr, sizeof(delayStr), "%d", delay);
if (!(argv = (char **)calloc(n + 1, sizeof(char *)))) if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error; goto error;
n = 0; n = 0;
@ -737,7 +737,7 @@ brSetEnableSTP(brControl *ctl ATTRIBUTE_UNUSED,
1 + /* brige name */ 1 + /* brige name */
1; /* value */ 1; /* value */
if (!(argv = (char **)calloc(n + 1, sizeof(char *)))) if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error; goto error;
n = 0; n = 0;

View File

@ -40,7 +40,7 @@ virBufferGrow(virBufferPtr buf, unsigned int len)
size = buf->use + len + 1000; size = buf->use + len + 1000;
newbuf = (char *) realloc(buf->content, size); newbuf = realloc(buf->content, size);
if (newbuf == NULL) return -1; if (newbuf == NULL) return -1;
buf->content = newbuf; buf->content = newbuf;
buf->size = size; buf->size = size;

View File

@ -152,7 +152,7 @@ __virConfNew(void)
{ {
virConfPtr ret; virConfPtr ret;
ret = (virConfPtr) calloc(1, sizeof(virConf)); ret = calloc(1, sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0); virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL); return(NULL);
@ -201,7 +201,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
if ((comm == NULL) && (name == NULL)) if ((comm == NULL) && (name == NULL))
return(NULL); return(NULL);
ret = (virConfEntryPtr) calloc(1, sizeof(virConfEntry)); ret = calloc(1, sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0); virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL); return(NULL);
@ -486,7 +486,7 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
ctxt->line); ctxt->line);
return(NULL); return(NULL);
} }
ret = (virConfValuePtr) calloc(1, sizeof(virConfValue)); ret = calloc(1, sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0); virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
if (str != NULL) if (str != NULL)
@ -837,7 +837,7 @@ __virConfSetValue (virConfPtr conf,
} }
if (!cur) { if (!cur) {
if (!(cur = malloc(sizeof(virConfEntry)))) { if (!(cur = malloc(sizeof(*cur)))) {
virConfFreeValue(value); virConfFreeValue(value);
return (-1); return (-1);
} }

View File

@ -87,11 +87,11 @@ virHashCreate(int size)
if (size <= 0) if (size <= 0)
size = 256; size = 256;
table = malloc(sizeof(virHashTable)); table = malloc(sizeof(*table));
if (table) { if (table) {
table->size = size; table->size = size;
table->nbElems = 0; table->nbElems = 0;
table->table = calloc(1, size * sizeof(virHashEntry)); table->table = calloc(1, size * sizeof(*(table->table)));
if (table->table) { if (table->table) {
return (table); return (table);
} }
@ -133,7 +133,7 @@ virHashGrow(virHashTablePtr table, int size)
if (oldtable == NULL) if (oldtable == NULL)
return (-1); return (-1);
table->table = calloc(1, size * sizeof(virHashEntry)); table->table = calloc(1, size * sizeof(*(table->table)));
if (table->table == NULL) { if (table->table == NULL) {
table->table = oldtable; table->table = oldtable;
return (-1); return (-1);
@ -279,7 +279,7 @@ virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
if (insert == NULL) { if (insert == NULL) {
entry = &(table->table[key]); entry = &(table->table[key]);
} else { } else {
entry = malloc(sizeof(virHashEntry)); entry = malloc(sizeof(*entry));
if (entry == NULL) if (entry == NULL)
return (-1); return (-1);
} }
@ -352,7 +352,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name,
if (insert == NULL) { if (insert == NULL) {
entry = &(table->table[key]); entry = &(table->table[key]);
} else { } else {
entry = malloc(sizeof(virHashEntry)); entry = malloc(sizeof(*entry));
if (entry == NULL) if (entry == NULL)
return (-1); return (-1);
} }
@ -661,7 +661,7 @@ virConnectPtr
virGetConnect(void) { virGetConnect(void) {
virConnectPtr ret; virConnectPtr ret;
ret = (virConnectPtr) calloc(1, sizeof(virConnect)); ret = calloc(1, sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
virHashError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection")); virHashError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
goto failed; goto failed;
@ -768,7 +768,7 @@ __virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid)
/* /*
* not found, allocate a new one * not found, allocate a new one
*/ */
ret = (virDomainPtr) calloc(1, sizeof(virDomain)); ret = calloc(1, sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating domain")); virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
goto error; goto error;
@ -901,7 +901,7 @@ __virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid)
/* /*
* not found, allocate a new one * not found, allocate a new one
*/ */
ret = (virNetworkPtr) calloc(1, sizeof(virNetwork)); ret = calloc(1, sizeof(*ret));
if (ret == NULL) { if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network")); virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
goto error; goto error;

View File

@ -215,7 +215,7 @@ iptRulesAppend(iptRules *rules,
{ {
iptRule *r; iptRule *r;
if (!(r = (iptRule *)realloc(rules->rules, sizeof(iptRule) * (rules->nrules+1)))) { if (!(r = realloc(rules->rules, sizeof(*r) * (rules->nrules+1)))) {
int i = 0; int i = 0;
while (argv[i]) while (argv[i])
free(argv[i++]); free(argv[i++]);
@ -319,7 +319,7 @@ iptRulesNew(const char *table,
{ {
iptRules *rules; iptRules *rules;
if (!(rules = (iptRules *)calloc(1, sizeof (iptRules)))) if (!(rules = calloc(1, sizeof (*rules))))
return NULL; return NULL;
if (!(rules->table = strdup(table))) if (!(rules->table = strdup(table)))
@ -400,7 +400,7 @@ iptablesAddRemoveChain(iptRules *rules, int action)
2 + /* --table foo */ 2 + /* --table foo */
2; /* --new-chain bar */ 2; /* --new-chain bar */
if (!(argv = (char **)calloc(n + 1, sizeof(char *)))) if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error; goto error;
n = 0; n = 0;
@ -458,7 +458,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
va_end(args); va_end(args);
if (!(argv = (char **)calloc(n + 1, sizeof(char *)))) if (!(argv = calloc(n + 1, sizeof(*argv))))
goto error; goto error;
if (!(rule = (char *)malloc(rulelen))) if (!(rule = (char *)malloc(rulelen)))
@ -549,7 +549,7 @@ iptablesContextNew(void)
{ {
iptablesContext *ctx; iptablesContext *ctx;
if (!(ctx = (iptablesContext *) calloc(1, sizeof (iptablesContext)))) if (!(ctx = calloc(1, sizeof (*ctx))))
return NULL; return NULL;
if (!(ctx->input_filter = iptRulesNew("filter", IPTABLES_PREFIX "INPUT"))) if (!(ctx->input_filter = iptRulesNew("filter", IPTABLES_PREFIX "INPUT")))

View File

@ -246,7 +246,7 @@ openvzAssignVMDef(virConnectPtr conn,
return vm; return vm;
} }
if (!(vm = calloc(1, sizeof(struct openvz_vm)))) { if (!(vm = calloc(1, sizeof(*vm)))) {
openvzFreeVMDef(def); openvzFreeVMDef(def);
error(conn, VIR_ERR_NO_MEMORY, "vm"); error(conn, VIR_ERR_NO_MEMORY, "vm");
return NULL; return NULL;
@ -298,7 +298,7 @@ static struct openvz_vm_def
struct ovz_ip *ovzIp; struct ovz_ip *ovzIp;
struct ovz_ns *ovzNs; struct ovz_ns *ovzNs;
if (!(def = calloc(1, sizeof(struct openvz_vm_def)))) { if (!(def = calloc(1, sizeof(*def)))) {
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext"); error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
return NULL; return NULL;
} }
@ -393,7 +393,7 @@ static struct openvz_vm_def
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage); error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
goto bail_out; goto bail_out;
} }
if (!(ovzIp = calloc(1, sizeof(struct ovz_ip)))) { if (!(ovzIp = calloc(1, sizeof(*ovzIp)))) {
openvzLog(OPENVZ_ERR, "Failed to Create Memory for 'ovz_ip' structure"); openvzLog(OPENVZ_ERR, "Failed to Create Memory for 'ovz_ip' structure");
goto bail_out; goto bail_out;
} }
@ -465,7 +465,7 @@ static struct openvz_vm_def
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage); error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
goto bail_out; goto bail_out;
} }
if (!(ovzNs = calloc(1, sizeof(struct ovz_ns)))) { if (!(ovzNs = calloc(1, sizeof(*ovzNs)))) {
openvzLog(OPENVZ_ERR, "Failed to Create Memory for 'ovz_ns' structure"); openvzLog(OPENVZ_ERR, "Failed to Create Memory for 'ovz_ns' structure");
goto bail_out; goto bail_out;
} }
@ -527,7 +527,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
} }
pnext = &vm; pnext = &vm;
while(!feof(fp)) { while(!feof(fp)) {
*pnext = calloc(1, sizeof(struct openvz_vm)); *pnext = calloc(1, sizeof(**pnext));
if(!*pnext) { if(!*pnext) {
error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed"); error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed");
goto error; goto error;
@ -557,7 +557,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
(*pnext)->vpsid = -1; (*pnext)->vpsid = -1;
} }
vmdef = calloc(1, sizeof(struct openvz_vm_def)); vmdef = calloc(1, sizeof(*vmdef));
if(!vmdef) { if(!vmdef) {
error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed"); error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed");
free(*pnext); free(*pnext);

View File

@ -918,7 +918,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
int i; int i;
struct qemud_vm_def *def; struct qemud_vm_def *def;
if (!(def = calloc(1, sizeof(struct qemud_vm_def)))) { if (!(def = calloc(1, sizeof(*def)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xmlXPathContext");
return NULL; return NULL;
} }
@ -1264,7 +1264,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_disk_def *prev = NULL; struct qemud_vm_disk_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_disk_def *disk = calloc(1, sizeof(struct qemud_vm_disk_def)); struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk));
if (!disk) { if (!disk) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "disk"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "disk");
goto error; goto error;
@ -1292,7 +1292,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_net_def *prev = NULL; struct qemud_vm_net_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_net_def *net = calloc(1, sizeof(struct qemud_vm_net_def)); struct qemud_vm_net_def *net = calloc(1, sizeof(*net));
if (!net) { if (!net) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "net"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "net");
goto error; goto error;
@ -1319,7 +1319,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_input_def *prev = NULL; struct qemud_vm_input_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_input_def *input = calloc(1, sizeof(struct qemud_vm_input_def)); struct qemud_vm_input_def *input = calloc(1, sizeof(*input));
if (!input) { if (!input) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "input"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "input");
goto error; goto error;
@ -1359,7 +1359,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
} }
if (!hasPS2mouse) { if (!hasPS2mouse) {
input = calloc(1, sizeof(struct qemud_vm_input_def)); input = calloc(1, sizeof(*input));
if (!input) { if (!input) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "input"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "input");
goto error; goto error;
@ -1454,7 +1454,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
if (!(retval = strdup(tapfdstr))) if (!(retval = strdup(tapfdstr)))
goto no_memory; goto no_memory;
if (!(tapfds = realloc(vm->tapfds, sizeof(int) * (vm->ntapfds+2)))) if (!(tapfds = realloc(vm->tapfds, sizeof(*tapfds) * (vm->ntapfds+2))))
goto no_memory; goto no_memory;
vm->tapfds = tapfds; vm->tapfds = tapfds;
@ -1554,7 +1554,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
snprintf(memory, sizeof(memory), "%d", vm->def->memory/1024); snprintf(memory, sizeof(memory), "%d", vm->def->memory/1024);
snprintf(vcpus, sizeof(vcpus), "%d", vm->def->vcpus); snprintf(vcpus, sizeof(vcpus), "%d", vm->def->vcpus);
if (!(*argv = malloc(sizeof(char *) * (len+1)))) if (!(*argv = malloc(sizeof(**argv) * (len+1))))
goto no_memory; goto no_memory;
if (!((*argv)[++n] = strdup(vm->def->os.binary))) if (!((*argv)[++n] = strdup(vm->def->os.binary)))
goto no_memory; goto no_memory;
@ -1899,7 +1899,7 @@ qemudParseVMDeviceDef(virConnectPtr conn,
{ {
xmlDocPtr xml; xmlDocPtr xml;
xmlNodePtr node; xmlNodePtr node;
struct qemud_vm_device_def *dev = calloc(1, sizeof(struct qemud_vm_device_def)); struct qemud_vm_device_def *dev = calloc(1, sizeof(*dev));
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, "device.xml", NULL, if (!(xml = xmlReadDoc(BAD_CAST xmlStr, "device.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
@ -1981,7 +1981,7 @@ qemudAssignVMDef(virConnectPtr conn,
return vm; return vm;
} }
if (!(vm = calloc(1, sizeof(struct qemud_vm)))) { if (!(vm = calloc(1, sizeof(*vm)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "vm"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "vm");
return NULL; return NULL;
} }
@ -2180,7 +2180,7 @@ static int qemudParseDhcpRangesXML(virConnectPtr conn,
continue; continue;
} }
if (!(range = calloc(1, sizeof(struct qemud_dhcp_range_def)))) { if (!(range = calloc(1, sizeof(*range)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "range"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "range");
return 0; return 0;
} }
@ -2272,7 +2272,7 @@ static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr conn,
xmlXPathObjectPtr obj = NULL, tmp = NULL; xmlXPathObjectPtr obj = NULL, tmp = NULL;
struct qemud_network_def *def; struct qemud_network_def *def;
if (!(def = calloc(1, sizeof(struct qemud_network_def)))) { if (!(def = calloc(1, sizeof(*def)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network_def");
return NULL; return NULL;
} }
@ -2433,7 +2433,7 @@ qemudAssignNetworkDef(virConnectPtr conn,
return network; return network;
} }
if (!(network = calloc(1, sizeof(struct qemud_network)))) { if (!(network = calloc(1, sizeof(*network)))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network"); qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "network");
return NULL; return NULL;
} }

View File

@ -158,7 +158,7 @@ qemudStartup(void) {
char *base = NULL; char *base = NULL;
char driverConf[PATH_MAX]; char driverConf[PATH_MAX];
if (!(qemu_driver = calloc(1, sizeof(struct qemud_driver)))) { if (!(qemu_driver = calloc(1, sizeof(*qemu_driver)))) {
return -1; return -1;
} }
@ -838,7 +838,7 @@ qemudBuildDnsmasqArgv(virConnectPtr conn,
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */ (2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
1; /* NULL */ 1; /* NULL */
if (!(*argv = calloc(len, sizeof(char *)))) if (!(*argv = calloc(len, sizeof(**argv))))
goto no_memory; goto no_memory;
#define APPEND_ARG(v, n, s) do { \ #define APPEND_ARG(v, n, s) do { \

View File

@ -661,7 +661,7 @@ doRemoteOpen (virConnectPtr conn,
// Generate the final command argv[] array. // Generate the final command argv[] array.
// ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL] // ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL]
cmd_argv = malloc (nr_args * sizeof (char *)); cmd_argv = malloc (nr_args * sizeof (*cmd_argv));
if (cmd_argv == NULL) { if (cmd_argv == NULL) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
goto failed; goto failed;
@ -724,7 +724,7 @@ doRemoteOpen (virConnectPtr conn,
// Run the external process. // Run the external process.
if (!cmd_argv) { if (!cmd_argv) {
cmd_argv = malloc (2 * sizeof (char *)); cmd_argv = malloc (2 * sizeof (*cmd_argv));
if (cmd_argv == NULL) { if (cmd_argv == NULL) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno)); error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
goto failed; goto failed;
@ -833,7 +833,7 @@ remoteOpen (virConnectPtr conn,
if (inside_daemon) if (inside_daemon)
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
priv = malloc (sizeof(struct private_data)); priv = malloc (sizeof(*priv));
if (!priv) { if (!priv) {
error (conn, VIR_ERR_NO_MEMORY, "struct private_data"); error (conn, VIR_ERR_NO_MEMORY, "struct private_data");
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
@ -2381,7 +2381,7 @@ remoteDomainSetSchedulerParameters (virDomainPtr domain,
/* Serialise the scheduler parameters. */ /* Serialise the scheduler parameters. */
args.params.params_len = nparams; args.params.params_len = nparams;
args.params.params_val = malloc (sizeof (struct remote_sched_param) args.params.params_val = malloc (sizeof (*args.params.params_val)
* nparams); * nparams);
if (args.params.params_val == NULL) { if (args.params.params_val == NULL) {
error (domain->conn, VIR_ERR_RPC, "out of memory allocating array"); error (domain->conn, VIR_ERR_RPC, "out of memory allocating array");
@ -2513,7 +2513,7 @@ remoteNetworkOpen (virConnectPtr conn,
* use the UNIX transport. This handles Xen driver * use the UNIX transport. This handles Xen driver
* which doesn't have its own impl of the network APIs. * which doesn't have its own impl of the network APIs.
*/ */
struct private_data *priv = malloc (sizeof(struct private_data)); struct private_data *priv = malloc (sizeof(*priv));
int ret, rflags = 0; int ret, rflags = 0;
if (!priv) { if (!priv) {
error (conn, VIR_ERR_NO_MEMORY, "struct private_data"); error (conn, VIR_ERR_NO_MEMORY, "struct private_data");
@ -3088,7 +3088,7 @@ static int remoteAuthCredSASL2Vir(int vircred)
*/ */
static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype) static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
{ {
sasl_callback_t *cbs = calloc(ncredtype+1, sizeof (sasl_callback_t)); sasl_callback_t *cbs = calloc(ncredtype+1, sizeof (*cbs));
int i, n; int i, n;
if (!cbs) { if (!cbs) {
return NULL; return NULL;
@ -3125,7 +3125,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact,
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++) for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
; /* empty */ ; /* empty */
*cred = calloc(ninteract, sizeof(virConnectCredential)); *cred = calloc(ninteract, sizeof(*cred));
if (!*cred) if (!*cred)
return -1; return -1;

View File

@ -592,7 +592,7 @@ static int testLoadNetworkFromFile(virConnectPtr conn,
static int testOpenDefault(virConnectPtr conn) { static int testOpenDefault(virConnectPtr conn) {
int u; int u;
struct timeval tv; struct timeval tv;
testConnPtr privconn = malloc(sizeof(testConn)); testConnPtr privconn = malloc(sizeof(*privconn));
if (!privconn) { if (!privconn) {
testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn"); testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
@ -678,7 +678,7 @@ static int testOpenFromFile(virConnectPtr conn,
xmlNodePtr *domains, *networks = NULL; xmlNodePtr *domains, *networks = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virNodeInfoPtr nodeInfo; virNodeInfoPtr nodeInfo;
testConnPtr privconn = malloc(sizeof(testConn)); testConnPtr privconn = malloc(sizeof(*privconn));
if (!privconn) { if (!privconn) {
testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn"); testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;

View File

@ -1,7 +1,7 @@
/* /*
* xen_internal.c: direct access to Xen hypervisor level * xen_internal.c: direct access to Xen hypervisor level
* *
* Copyright (C) 2005, 2006 Red Hat, Inc. * Copyright (C) 2005, 2006, 2007 Red Hat, Inc.
* *
* See COPYING.LIB for the License of this software * See COPYING.LIB for the License of this software
* *
@ -220,10 +220,10 @@ typedef struct xen_v2s4_availheap xen_v2s4_availheap;
#define XEN_GETDOMAININFOLIST_ALLOC(domlist, size) \ #define XEN_GETDOMAININFOLIST_ALLOC(domlist, size) \
(hypervisor_version < 2 ? \ (hypervisor_version < 2 ? \
((domlist.v0 = malloc(sizeof(xen_v0_getdomaininfo)*(size))) != NULL) : \ ((domlist.v0 = malloc(sizeof(*domlist.v0)*(size))) != NULL) : \
(dom_interface_version < 5 ? \ (dom_interface_version < 5 ? \
((domlist.v2 = malloc(sizeof(xen_v2_getdomaininfo)*(size))) != NULL) : \ ((domlist.v2 = malloc(sizeof(*domlist.v2)*(size))) != NULL) : \
((domlist.v2d5 = malloc(sizeof(xen_v2d5_getdomaininfo)*(size))) != NULL))) ((domlist.v2d5 = malloc(sizeof(*domlist.v2d5)*(size))) != NULL)))
#define XEN_GETDOMAININFOLIST_FREE(domlist) \ #define XEN_GETDOMAININFOLIST_FREE(domlist) \
(hypervisor_version < 2 ? \ (hypervisor_version < 2 ? \
@ -232,12 +232,12 @@ typedef struct xen_v2s4_availheap xen_v2s4_availheap;
free(domlist.v2) : \ free(domlist.v2) : \
free(domlist.v2d5))) free(domlist.v2d5)))
#define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \ #define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \
(hypervisor_version < 2 ? \ (hypervisor_version < 2 ? \
memset(domlist.v0, 0, sizeof(xen_v0_getdomaininfo) * size) : \ memset(domlist.v0, 0, sizeof(*domlist.v0) * size) : \
(dom_interface_version < 5 ? \ (dom_interface_version < 5 ? \
memset(domlist.v2, 0, sizeof(xen_v2_getdomaininfo) * size) : \ memset(domlist.v2, 0, sizeof(*domlist.v2) * size) : \
memset(domlist.v2d5, 0, sizeof(xen_v2d5_getdomaininfo) * size))) memset(domlist.v2d5, 0, sizeof(*domlist.v2d5) * size)))
#define XEN_GETDOMAININFOLIST_DOMAIN(domlist, n) \ #define XEN_GETDOMAININFOLIST_DOMAIN(domlist, n) \
(hypervisor_version < 2 ? \ (hypervisor_version < 2 ? \
@ -1964,7 +1964,7 @@ xenHypervisorInit(void)
*/ */
hypervisor_version = 2; hypervisor_version = 2;
ipt = malloc(sizeof(virVcpuInfo)); ipt = malloc(sizeof(*ipt));
if (ipt == NULL){ if (ipt == NULL){
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Memory allocation failed at xenHypervisorInit()\n"); fprintf(stderr, "Memory allocation failed at xenHypervisorInit()\n");

View File

@ -168,10 +168,10 @@ xenDomainUsedCpus(virDomainPtr dom)
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0) if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return(NULL); return(NULL);
cpulist = (char *) calloc(nb_cpu, sizeof(char)); cpulist = calloc(nb_cpu, sizeof(*cpulist));
if (cpulist == NULL) if (cpulist == NULL)
goto done; goto done;
cpuinfo = malloc(sizeof(virVcpuInfo) * nb_vcpu); cpuinfo = malloc(sizeof(*cpuinfo) * nb_vcpu);
if (cpuinfo == NULL) if (cpuinfo == NULL)
goto done; goto done;
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));

View File

@ -231,7 +231,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
/* Had better have a name...*/ /* Had better have a name...*/
if (xenXMConfigGetString(conf, "name", &name) < 0) { if (xenXMConfigGetString(conf, "name", &name) < 0) {
virConfValuePtr value; virConfValuePtr value;
value = malloc(sizeof(virConfValue)); value = malloc(sizeof(*value));
if (!value) { if (!value) {
return (-1); return (-1);
} }
@ -252,7 +252,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
virConfValuePtr value; virConfValuePtr value;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
value = malloc(sizeof(virConfValue)); value = malloc(sizeof(*value));
if (!value) { if (!value) {
return (-1); return (-1);
} }
@ -401,7 +401,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
entry->conf = NULL; entry->conf = NULL;
} else { /* Completely new entry */ } else { /* Completely new entry */
newborn = 1; newborn = 1;
if (!(entry = malloc(sizeof(xenXMConfCache)))) { if (!(entry = malloc(sizeof(*entry)))) {
xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno)); xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
goto cleanup; goto cleanup;
} }
@ -1081,7 +1081,7 @@ int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory) {
if (!(entry = virHashLookup(configCache, filename))) if (!(entry = virHashLookup(configCache, filename)))
return (-1); return (-1);
if (!(value = malloc(sizeof(virConfValue)))) if (!(value = malloc(sizeof(*value))))
return (-1); return (-1);
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1123,7 +1123,7 @@ int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
if (!(entry = virHashLookup(configCache, filename))) if (!(entry = virHashLookup(configCache, filename)))
return (-1); return (-1);
if (!(value = malloc(sizeof(virConfValue)))) if (!(value = malloc(sizeof(*value))))
return (-1); return (-1);
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1196,7 +1196,7 @@ int xenXMDomainSetVcpus(virDomainPtr domain, unsigned int vcpus) {
if (!(entry = virHashLookup(configCache, filename))) if (!(entry = virHashLookup(configCache, filename)))
return (-1); return (-1);
if (!(value = malloc(sizeof(virConfValue)))) if (!(value = malloc(sizeof(*value))))
return (-1); return (-1);
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1481,7 +1481,7 @@ static
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) { int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (!(value = malloc(sizeof(virConfValue)))) if (!(value = malloc(sizeof(*value))))
return -1; return -1;
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1496,7 +1496,7 @@ static
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) { int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (!(value = malloc(sizeof(virConfValue)))) if (!(value = malloc(sizeof(*value))))
return -1; return -1;
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
@ -2112,7 +2112,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
if (!(vfb = malloc(sizeof(virConfValue)))) { if (!(vfb = malloc(sizeof(*vfb)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error; goto error;
} }
@ -2177,7 +2177,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
xmlFree(type); xmlFree(type);
if (val) { if (val) {
virConfValuePtr disp; virConfValuePtr disp;
if (!(disp = malloc(sizeof(virConfValue)))) { if (!(disp = malloc(sizeof(*disp)))) {
free(val); free(val);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error; goto error;
@ -2199,7 +2199,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr disks; virConfValuePtr disks;
if (!(disks = malloc(sizeof(virConfValue)))) { if (!(disks = malloc(sizeof(*disks)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error; goto error;
} }
@ -2211,7 +2211,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, priv->xendConfigVersion, &disk) < 0) if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, priv->xendConfigVersion, &disk) < 0)
goto error; goto error;
if (disk) { if (disk) {
if (!(thisDisk = malloc(sizeof(virConfValue)))) { if (!(thisDisk = malloc(sizeof(*thisDisk)))) {
free(disk); free(disk);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error; goto error;
@ -2231,7 +2231,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr vifs; virConfValuePtr vifs;
if (!(vifs = malloc(sizeof(virConfValue)))) { if (!(vifs = malloc(sizeof(*vifs)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error; goto error;
} }
@ -2242,7 +2242,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm); char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm);
if (!vif) if (!vif)
goto error; goto error;
if (!(thisVif = malloc(sizeof(virConfValue)))) { if (!(thisVif = malloc(sizeof(*thisVif)))) {
if (vif) if (vif)
free(vif); free(vif);
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
@ -2377,7 +2377,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
goto error; goto error;
} }
if (!(entry = calloc(1, sizeof(xenXMConfCache)))) { if (!(entry = calloc(1, sizeof(*entry)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config"); xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error; goto error;
} }

View File

@ -322,7 +322,7 @@ virParseXenCpuTopology(virConnectPtr conn, virBufferPtr xml,
if ((str == NULL) || (xml == NULL) || (maxcpu <= 0) || (maxcpu > 100000)) if ((str == NULL) || (xml == NULL) || (maxcpu <= 0) || (maxcpu > 100000))
return (-1); return (-1);
cpuset = malloc(maxcpu * sizeof(char)); cpuset = malloc(maxcpu * sizeof(*cpuset));
if (cpuset == NULL) if (cpuset == NULL)
goto memory_error; goto memory_error;
@ -433,7 +433,7 @@ virConvertCpuSet(virConnectPtr conn, const char *str, int maxcpu) {
if (maxcpu <= 0) if (maxcpu <= 0)
maxcpu = 4096; maxcpu = 4096;
cpuset = calloc(maxcpu, sizeof(char)); cpuset = calloc(maxcpu, sizeof(*cpuset));
if (cpuset == NULL) { if (cpuset == NULL) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0); virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
return(NULL); return(NULL);
@ -676,11 +676,11 @@ virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
ret = obj->nodesetval->nodeNr; ret = obj->nodesetval->nodeNr;
if (list != NULL) { if (list != NULL) {
*list = malloc(ret * sizeof(xmlNodePtr)); *list = malloc(ret * sizeof(**list));
if (*list == NULL) { if (*list == NULL) {
virXMLError(NULL, VIR_ERR_NO_MEMORY, virXMLError(NULL, VIR_ERR_NO_MEMORY,
_("allocate string array"), _("allocate string array"),
ret * sizeof(xmlNodePtr)); ret * sizeof(**list));
} else { } else {
memcpy(*list, obj->nodesetval->nodeTab, memcpy(*list, obj->nodesetval->nodeTab,
ret * sizeof(xmlNodePtr)); ret * sizeof(xmlNodePtr));
@ -1636,7 +1636,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
* it in a range format guaranteed to be understood by Xen. * it in a range format guaranteed to be understood by Xen.
*/ */
if (maxcpu > 0) { if (maxcpu > 0) {
cpuset = malloc(maxcpu * sizeof(char)); cpuset = malloc(maxcpu * sizeof(*cpuset));
if (cpuset != NULL) { if (cpuset != NULL) {
res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu); res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
if (res > 0) { if (res > 0) {

View File

@ -153,6 +153,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
xmlRpcValuePtr ret = xmlRpcValueNew(XML_RPC_ARRAY); xmlRpcValuePtr ret = xmlRpcValueNew(XML_RPC_ARRAY);
xmlNodePtr cur; xmlNodePtr cur;
int n_elements = 0; int n_elements = 0;
xmlRpcValuePtr *elems;
if (!ret) if (!ret)
return NULL; return NULL;
@ -160,19 +161,20 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur)) for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur))
n_elements += 1; n_elements += 1;
ret->value.array.elements = malloc(n_elements * sizeof(xmlRpcValue)); elems = malloc(n_elements * sizeof(*elems));
if (!ret->value.array.elements) { if (!elems) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value array"), xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value array"),
n_elements * sizeof(xmlRpcValue)); n_elements * sizeof(*elems));
free(ret); free(ret);
return NULL; return NULL;
} }
n_elements = 0; n_elements = 0;
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur)) { for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur)) {
ret->value.array.elements[n_elements] = xmlRpcValueUnmarshal(cur); elems[n_elements] = xmlRpcValueUnmarshal(cur);
n_elements += 1; n_elements += 1;
} }
ret->value.array.elements = elems;
ret->value.array.n_elements = n_elements; ret->value.array.n_elements = n_elements;
return ret; return ret;

View File

@ -60,7 +60,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd) {
len += strlen(*tmp) + 1; len += strlen(*tmp) + 1;
tmp++; tmp++;
} }
actualargv = malloc(sizeof(char)*len); actualargv = malloc(sizeof(*actualargv)*len);
actualargv[0] = '\0'; actualargv[0] = '\0';
tmp = argv; tmp = argv;
len = 0; len = 0;