]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
* qemud/iptables.c qemud/qemud.c src/conf.c src/hash.c src/libvirt.c
authorDaniel Veillard <veillard@redhat.com>
Thu, 22 Mar 2007 18:30:57 +0000 (18:30 +0000)
committerDaniel Veillard <veillard@redhat.com>
Thu, 22 Mar 2007 18:30:57 +0000 (18:30 +0000)
  src/virsh.c src/xm_internal.c: change malloc/memset(0) pairs to
  using calloc()
Daniel

ChangeLog
qemud/iptables.c
qemud/qemud.c
src/conf.c
src/hash.c
src/libvirt.c
src/virsh.c
src/xm_internal.c

index 83f1d630a0a5379921b7e1dbdd81ae29495d0d35..7f7c3c015c1bfaa1c9f147ea5a9b4cf3fc1c4fc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 6731224e2302aa7efffeb55363bca1d068ecd0c9..10b3e73b9bb488b1597a8a16a1b72b13f424ff1f 100644 (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)))
index e1914a379d776842b5e0071237952b56c63d323a..30245b195af01c4cebe14f87acb4e470272af6d5 100644 (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;          \
index 6530094de2f6f04e5fca3e14ed6cb96362aefeab..7aad6529956d690715631a913f2c4cc3a0e611c6 100644 (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;
index 0427f06bfd2167b644e773c1799354d991be1e69..97a3505375a8043ebed3a3643f29a5e18a985500 100644 (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"));
index df99b6228153abd30a0869a72a6ae97b16dee30d..dd3fd5bb0df9b63edfbe4a80ac8608b04e3594cb 100644 (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];
index 5789292ddb4d4feb1088fe40a359377f1031672a..18241cf4a60439c1b789d45aeb61e9979e8894b9 100644 (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);
index 864ddbac3b3aa2ac8bc3a2c054bd572a187624ca..7511ca2b0364ae566d27d6a55e326a32270d477c 100644 (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");