+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
{
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;
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)))
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)))
(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; \
{
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);
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;
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;
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);
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
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;
/*
* 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"));
/*
* 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"));
* 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];
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,
}
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);
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");