mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-12 12:55:46 +00:00
* qemud/iptables.c qemud/qemud.c src/conf.c src/hash.c src/libvirt.c
src/virsh.c src/xm_internal.c: change malloc/memset(0) pairs to using calloc() Daniel
This commit is contained in:
parent
f39faaa708
commit
fb624fbecf
@ -1,3 +1,9 @@
|
|||||||
|
Thu Mar 22 19:38:38 CET 2007 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* qemud/iptables.c qemud/qemud.c src/conf.c src/hash.c src/libvirt.c
|
||||||
|
src/virsh.c src/xm_internal.c: change malloc/memset(0) pairs to
|
||||||
|
using calloc()
|
||||||
|
|
||||||
Thu Mar 22 16:25:10 CET 2007 Daniel Veillard <veillard@redhat.com>
|
Thu Mar 22 16:25:10 CET 2007 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* docs/*.html: repair the damages made by Amaya on the content
|
* docs/*.html: repair the damages made by Amaya on the content
|
||||||
|
@ -270,11 +270,9 @@ iptRulesNew(const char *table,
|
|||||||
{
|
{
|
||||||
iptRules *rules;
|
iptRules *rules;
|
||||||
|
|
||||||
if (!(rules = (iptRules *)malloc(sizeof (iptRules))))
|
if (!(rules = (iptRules *)calloc(1, sizeof (iptRules))))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset (rules, 0, sizeof (iptRules));
|
|
||||||
|
|
||||||
if (!(rules->table = strdup(table)))
|
if (!(rules->table = strdup(table)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -353,11 +351,9 @@ iptablesAddRemoveChain(iptRules *rules, int action)
|
|||||||
2 + /* --table foo */
|
2 + /* --table foo */
|
||||||
2; /* --new-chain bar */
|
2; /* --new-chain bar */
|
||||||
|
|
||||||
if (!(argv = (char **)malloc(sizeof(char *) * (n+1))))
|
if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
memset(argv, 0, sizeof(char *) * (n + 1));
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
if (!(argv[n++] = strdup(IPTABLES_PATH)))
|
if (!(argv[n++] = strdup(IPTABLES_PATH)))
|
||||||
@ -413,14 +409,12 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
|
|||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (!(argv = (char **)malloc(sizeof(char *) * (n + 1))))
|
if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(rule = (char *)malloc(rulelen)))
|
if (!(rule = (char *)malloc(rulelen)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
memset(argv, 0, sizeof(char *) * (n + 1));
|
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
if (!(argv[n++] = strdup(IPTABLES_PATH)))
|
if (!(argv[n++] = strdup(IPTABLES_PATH)))
|
||||||
|
@ -1132,11 +1132,9 @@ qemudBuildDnsmasqArgv(struct qemud_server *server,
|
|||||||
(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 = malloc(len * sizeof(char *))))
|
if (!(*argv = calloc(len, sizeof(char *))))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
memset(*argv, 0, len * sizeof(char *));
|
|
||||||
|
|
||||||
#define APPEND_ARG(v, n, s) do { \
|
#define APPEND_ARG(v, n, s) do { \
|
||||||
if (!((v)[(n)] = strdup(s))) \
|
if (!((v)[(n)] = strdup(s))) \
|
||||||
goto no_memory; \
|
goto no_memory; \
|
||||||
|
10
src/conf.c
10
src/conf.c
@ -151,13 +151,11 @@ __virConfNew(void)
|
|||||||
{
|
{
|
||||||
virConfPtr ret;
|
virConfPtr ret;
|
||||||
|
|
||||||
ret = (virConfPtr) malloc(sizeof(virConf));
|
ret = (virConfPtr) calloc(1, sizeof(virConf));
|
||||||
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);
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(virConf));
|
|
||||||
|
|
||||||
ret->filename = NULL;
|
ret->filename = NULL;
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
@ -202,13 +200,12 @@ 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) malloc(sizeof(virConfEntry));
|
ret = (virConfEntryPtr) calloc(1, sizeof(virConfEntry));
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(ret, 0, sizeof(virConfEntry));
|
|
||||||
ret->name = name;
|
ret->name = name;
|
||||||
ret->value = value;
|
ret->value = value;
|
||||||
ret->comment = comm;
|
ret->comment = comm;
|
||||||
@ -486,14 +483,13 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
|
|||||||
ctxt->line);
|
ctxt->line);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
ret = (virConfValuePtr) malloc(sizeof(virConfValue));
|
ret = (virConfValuePtr) calloc(1, sizeof(virConfValue));
|
||||||
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)
|
||||||
free(str);
|
free(str);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(virConfValue));
|
|
||||||
ret->type = type;
|
ret->type = type;
|
||||||
ret->l = l;
|
ret->l = l;
|
||||||
ret->str = str;
|
ret->str = str;
|
||||||
|
15
src/hash.c
15
src/hash.c
@ -89,9 +89,8 @@ virHashCreate(int size)
|
|||||||
if (table) {
|
if (table) {
|
||||||
table->size = size;
|
table->size = size;
|
||||||
table->nbElems = 0;
|
table->nbElems = 0;
|
||||||
table->table = malloc(size * sizeof(virHashEntry));
|
table->table = calloc(1, size * sizeof(virHashEntry));
|
||||||
if (table->table) {
|
if (table->table) {
|
||||||
memset(table->table, 0, size * sizeof(virHashEntry));
|
|
||||||
return (table);
|
return (table);
|
||||||
}
|
}
|
||||||
free(table);
|
free(table);
|
||||||
@ -132,12 +131,11 @@ virHashGrow(virHashTablePtr table, int size)
|
|||||||
if (oldtable == NULL)
|
if (oldtable == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
table->table = malloc(size * sizeof(virHashEntry));
|
table->table = calloc(1, size * sizeof(virHashEntry));
|
||||||
if (table->table == NULL) {
|
if (table->table == NULL) {
|
||||||
table->table = oldtable;
|
table->table = oldtable;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
memset(table->table, 0, size * sizeof(virHashEntry));
|
|
||||||
table->size = size;
|
table->size = size;
|
||||||
|
|
||||||
/* If the two loops are merged, there would be situations where
|
/* If the two loops are merged, there would be situations where
|
||||||
@ -661,12 +659,11 @@ virConnectPtr
|
|||||||
virGetConnect(void) {
|
virGetConnect(void) {
|
||||||
virConnectPtr ret;
|
virConnectPtr ret;
|
||||||
|
|
||||||
ret = (virConnectPtr) malloc(sizeof(virConnect));
|
ret = (virConnectPtr) calloc(1, sizeof(virConnect));
|
||||||
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;
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(virConnect));
|
|
||||||
ret->magic = VIR_CONNECT_MAGIC;
|
ret->magic = VIR_CONNECT_MAGIC;
|
||||||
ret->nb_drivers = 0;
|
ret->nb_drivers = 0;
|
||||||
ret->handle = -1;
|
ret->handle = -1;
|
||||||
@ -767,12 +764,11 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
/*
|
/*
|
||||||
* not found, allocate a new one
|
* not found, allocate a new one
|
||||||
*/
|
*/
|
||||||
ret = (virDomainPtr) malloc(sizeof(virDomain));
|
ret = (virDomainPtr) calloc(1, sizeof(virDomain));
|
||||||
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;
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(virDomain));
|
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
|
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
|
||||||
@ -950,12 +946,11 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
|
|||||||
/*
|
/*
|
||||||
* not found, allocate a new one
|
* not found, allocate a new one
|
||||||
*/
|
*/
|
||||||
ret = (virNetworkPtr) malloc(sizeof(virNetwork));
|
ret = (virNetworkPtr) calloc(1, sizeof(virNetwork));
|
||||||
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;
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(virNetwork));
|
|
||||||
ret->name = strdup(name);
|
ret->name = strdup(name);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
|
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
* TODO:
|
* TODO:
|
||||||
* - use lock to protect against concurrent accesses ?
|
* - use lock to protect against concurrent accesses ?
|
||||||
* - use reference counting to garantee coherent pointer state ?
|
* - use reference counting to garantee coherent pointer state ?
|
||||||
* - memory wrappers for malloc/free ?
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static virDriverPtr virDriverTab[MAX_DRIVERS];
|
static virDriverPtr virDriverTab[MAX_DRIVERS];
|
||||||
|
@ -1247,9 +1247,9 @@ cmdVcpuinfo(vshControl * ctl, vshCmd * cmd)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpuinfo = malloc(sizeof(virVcpuInfo)*info.nrVirtCpu);
|
cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
|
||||||
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
||||||
cpumap = malloc(info.nrVirtCpu * cpumaplen);
|
cpumap = vshMalloc(ctl, info.nrVirtCpu * cpumaplen);
|
||||||
|
|
||||||
if ((ncpus = virDomainGetVcpus(dom,
|
if ((ncpus = virDomainGetVcpus(dom,
|
||||||
cpuinfo, info.nrVirtCpu,
|
cpuinfo, info.nrVirtCpu,
|
||||||
@ -1350,8 +1350,7 @@ cmdVcpupin(vshControl * ctl, vshCmd * cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
||||||
cpumap = malloc(cpumaplen);
|
cpumap = vshCalloc(ctl, 1, cpumaplen);
|
||||||
memset(cpumap, 0, cpumaplen);
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned int cpu = atoi(cpulist);
|
unsigned int cpu = atoi(cpulist);
|
||||||
|
@ -2113,11 +2113,10 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(entry = malloc(sizeof(xenXMConfCache)))) {
|
if (!(entry = calloc(1, sizeof(xenXMConfCache)))) {
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
|
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
memset(entry, 0, sizeof(xenXMConfCache));
|
|
||||||
|
|
||||||
if ((entry->refreshedAt = time(NULL)) == ((time_t)-1)) {
|
if ((entry->refreshedAt = time(NULL)) == ((time_t)-1)) {
|
||||||
xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "unable to get current time");
|
xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "unable to get current time");
|
||||||
|
Loading…
Reference in New Issue
Block a user