* 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:
Daniel Veillard 2007-03-22 18:30:57 +00:00
parent f39faaa708
commit fb624fbecf
8 changed files with 22 additions and 36 deletions

View File

@ -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>
* docs/*.html: repair the damages made by Amaya on the content

View File

@ -270,11 +270,9 @@ iptRulesNew(const char *table,
{
iptRules *rules;
if (!(rules = (iptRules *)malloc(sizeof (iptRules))))
if (!(rules = (iptRules *)calloc(1, sizeof (iptRules))))
return NULL;
memset (rules, 0, sizeof (iptRules));
if (!(rules->table = strdup(table)))
goto error;
@ -353,11 +351,9 @@ iptablesAddRemoveChain(iptRules *rules, int action)
2 + /* --table foo */
2; /* --new-chain bar */
if (!(argv = (char **)malloc(sizeof(char *) * (n+1))))
if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
goto error;
memset(argv, 0, sizeof(char *) * (n + 1));
n = 0;
if (!(argv[n++] = strdup(IPTABLES_PATH)))
@ -413,14 +409,12 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
va_end(args);
if (!(argv = (char **)malloc(sizeof(char *) * (n + 1))))
if (!(argv = (char **)calloc(n + 1, sizeof(char *))))
goto error;
if (!(rule = (char *)malloc(rulelen)))
goto error;
memset(argv, 0, sizeof(char *) * (n + 1));
n = 0;
if (!(argv[n++] = strdup(IPTABLES_PATH)))

View File

@ -1132,11 +1132,9 @@ qemudBuildDnsmasqArgv(struct qemud_server *server,
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
1; /* NULL */
if (!(*argv = malloc(len * sizeof(char *))))
if (!(*argv = calloc(len, sizeof(char *))))
goto no_memory;
memset(*argv, 0, len * sizeof(char *));
#define APPEND_ARG(v, n, s) do { \
if (!((v)[(n)] = strdup(s))) \
goto no_memory; \

View File

@ -151,13 +151,11 @@ __virConfNew(void)
{
virConfPtr ret;
ret = (virConfPtr) malloc(sizeof(virConf));
ret = (virConfPtr) calloc(1, sizeof(virConf));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL);
}
memset(ret, 0, sizeof(virConf));
ret->filename = NULL;
return(ret);
@ -202,13 +200,12 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
if ((comm == NULL) && (name == NULL))
return(NULL);
ret = (virConfEntryPtr) malloc(sizeof(virConfEntry));
ret = (virConfEntryPtr) calloc(1, sizeof(virConfEntry));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL);
}
memset(ret, 0, sizeof(virConfEntry));
ret->name = name;
ret->value = value;
ret->comment = comm;
@ -486,14 +483,13 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
ctxt->line);
return(NULL);
}
ret = (virConfValuePtr) malloc(sizeof(virConfValue));
ret = (virConfValuePtr) calloc(1, sizeof(virConfValue));
if (ret == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
if (str != NULL)
free(str);
return(NULL);
}
memset(ret, 0, sizeof(virConfValue));
ret->type = type;
ret->l = l;
ret->str = str;

View File

@ -89,9 +89,8 @@ virHashCreate(int size)
if (table) {
table->size = size;
table->nbElems = 0;
table->table = malloc(size * sizeof(virHashEntry));
table->table = calloc(1, size * sizeof(virHashEntry));
if (table->table) {
memset(table->table, 0, size * sizeof(virHashEntry));
return (table);
}
free(table);
@ -132,12 +131,11 @@ virHashGrow(virHashTablePtr table, int size)
if (oldtable == NULL)
return (-1);
table->table = malloc(size * sizeof(virHashEntry));
table->table = calloc(1, size * sizeof(virHashEntry));
if (table->table == NULL) {
table->table = oldtable;
return (-1);
}
memset(table->table, 0, size * sizeof(virHashEntry));
table->size = size;
/* If the two loops are merged, there would be situations where
@ -661,12 +659,11 @@ virConnectPtr
virGetConnect(void) {
virConnectPtr ret;
ret = (virConnectPtr) malloc(sizeof(virConnect));
ret = (virConnectPtr) calloc(1, sizeof(virConnect));
if (ret == NULL) {
virHashError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
goto failed;
}
memset(ret, 0, sizeof(virConnect));
ret->magic = VIR_CONNECT_MAGIC;
ret->nb_drivers = 0;
ret->handle = -1;
@ -767,12 +764,11 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
/*
* not found, allocate a new one
*/
ret = (virDomainPtr) malloc(sizeof(virDomain));
ret = (virDomainPtr) calloc(1, sizeof(virDomain));
if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
goto error;
}
memset(ret, 0, sizeof(virDomain));
ret->name = strdup(name);
if (ret->name == NULL) {
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
*/
ret = (virNetworkPtr) malloc(sizeof(virNetwork));
ret = (virNetworkPtr) calloc(1, sizeof(virNetwork));
if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
goto error;
}
memset(ret, 0, sizeof(virNetwork));
ret->name = strdup(name);
if (ret->name == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));

View File

@ -40,7 +40,6 @@
* TODO:
* - use lock to protect against concurrent accesses ?
* - use reference counting to garantee coherent pointer state ?
* - memory wrappers for malloc/free ?
*/
static virDriverPtr virDriverTab[MAX_DRIVERS];

View File

@ -1247,9 +1247,9 @@ cmdVcpuinfo(vshControl * ctl, vshCmd * cmd)
return FALSE;
}
cpuinfo = malloc(sizeof(virVcpuInfo)*info.nrVirtCpu);
cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
cpumap = malloc(info.nrVirtCpu * cpumaplen);
cpumap = vshMalloc(ctl, info.nrVirtCpu * cpumaplen);
if ((ncpus = virDomainGetVcpus(dom,
cpuinfo, info.nrVirtCpu,
@ -1350,8 +1350,7 @@ cmdVcpupin(vshControl * ctl, vshCmd * cmd)
}
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
cpumap = malloc(cpumaplen);
memset(cpumap, 0, cpumaplen);
cpumap = vshCalloc(ctl, 1, cpumaplen);
do {
unsigned int cpu = atoi(cpulist);

View File

@ -2113,11 +2113,10 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
goto error;
}
if (!(entry = malloc(sizeof(xenXMConfCache)))) {
if (!(entry = calloc(1, sizeof(xenXMConfCache)))) {
xenXMError(conn, VIR_ERR_NO_MEMORY, "config");
goto error;
}
memset(entry, 0, sizeof(xenXMConfCache));
if ((entry->refreshedAt = time(NULL)) == ((time_t)-1)) {
xenXMError(conn, VIR_ERR_INTERNAL_ERROR, "unable to get current time");