summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2010-09-30 21:06:50 +0000
committerAlasdair Kergon <agk@redhat.com>2010-09-30 21:06:50 +0000
commitac0252ca07e3be5bbb439c913d71c43f551e30ce (patch)
tree45d08af849560161cd6570fa0ff123cc770f1a70 /lib
parent0ca1492ca52365cc86aeaf623e370290446ba16f (diff)
downloadlvm2-ac0252ca07e3be5bbb439c913d71c43f551e30ce.tar.gz
lvm2-ac0252ca07e3be5bbb439c913d71c43f551e30ce.tar.xz
lvm2-ac0252ca07e3be5bbb439c913d71c43f551e30ce.zip
Add dm_zalloc and use it and dm_pool_zalloc throughout.
Diffstat (limited to 'lib')
-rw-r--r--lib/cache/lvmcache.c6
-rw-r--r--lib/commands/toolcontext.c3
-rw-r--r--lib/config/config.c80
-rw-r--r--lib/filters/filter-persistent.c3
-rw-r--r--lib/format1/disk-rep.c3
-rw-r--r--lib/format1/format1.c4
-rw-r--r--lib/format1/import-export.c3
-rw-r--r--lib/format_text/export.c7
-rw-r--r--lib/label/label.c3
9 files changed, 48 insertions, 64 deletions
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 2af4e4a6..35d6f76c 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1064,11 +1064,10 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
}
} else {
***/
- if (!(vginfo = dm_malloc(sizeof(*vginfo)))) {
+ if (!(vginfo = dm_zalloc(sizeof(*vginfo)))) {
log_error("lvmcache_update_vgname: list alloc failed");
return 0;
}
- memset(vginfo, 0, sizeof(*vginfo));
if (!(vginfo->vgname = dm_strdup(vgname))) {
dm_free(vginfo);
log_error("cache vgname alloc failed for %s", vgname);
@@ -1261,12 +1260,11 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
!(existing = info_from_pvid(dev->pvid, 0))) {
if (!(label = label_create(labeller)))
return_NULL;
- if (!(info = dm_malloc(sizeof(*info)))) {
+ if (!(info = dm_zalloc(sizeof(*info)))) {
log_error("lvmcache_info allocation failed");
label_destroy(label);
return NULL;
}
- memset(info, 0, sizeof(*info));
label->info = info;
info->label = label;
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 813da909..289a0fca 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1121,11 +1121,10 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
init_syslog(DEFAULT_LOG_FACILITY);
- if (!(cmd = dm_malloc(sizeof(*cmd)))) {
+ if (!(cmd = dm_zalloc(sizeof(*cmd)))) {
log_error("Failed to allocate command context");
return NULL;
}
- memset(cmd, 0, sizeof(*cmd));
cmd->is_long_lived = is_long_lived;
cmd->handles_missing_pvs = 0;
cmd->handles_unknown_segments = 0;
diff --git a/lib/config/config.c b/lib/config/config.c
index 72f306d7..2b386634 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -724,6 +724,8 @@ static void _get_token(struct parser *p, int tok_prev)
{
int values_allowed = 0;
+ const char *te;
+
p->tb = p->te;
_eat_space(p);
if (p->tb == p->fe || !*p->tb) {
@@ -738,59 +740,61 @@ static void _get_token(struct parser *p, int tok_prev)
p->t = TOK_INT; /* fudge so the fall through for
floats works */
- switch (*p->te) {
+
+ te = p->te;
+ switch (*te) {
case SECTION_B_CHAR:
p->t = TOK_SECTION_B;
- p->te++;
+ te++;
break;
case SECTION_E_CHAR:
p->t = TOK_SECTION_E;
- p->te++;
+ te++;
break;
case '[':
p->t = TOK_ARRAY_B;
- p->te++;
+ te++;
break;
case ']':
p->t = TOK_ARRAY_E;
- p->te++;
+ te++;
break;
case ',':
p->t = TOK_COMMA;
- p->te++;
+ te++;
break;
case '=':
p->t = TOK_EQ;
- p->te++;
+ te++;
break;
case '"':
p->t = TOK_STRING_ESCAPED;
- p->te++;
- while ((p->te != p->fe) && (*p->te) && (*p->te != '"')) {
- if ((*p->te == '\\') && (p->te + 1 != p->fe) &&
- *(p->te + 1))
- p->te++;
- p->te++;
+ te++;
+ while ((te != p->fe) && (*te) && (*te != '"')) {
+ if ((*te == '\\') && (te + 1 != p->fe) &&
+ *(te + 1))
+ te++;
+ te++;
}
- if ((p->te != p->fe) && (*p->te))
- p->te++;
+ if ((te != p->fe) && (*te))
+ te++;
break;
case '\'':
p->t = TOK_STRING;
- p->te++;
- while ((p->te != p->fe) && (*p->te) && (*p->te != '\''))
- p->te++;
+ te++;
+ while ((te != p->fe) && (*te) && (*te != '\''))
+ te++;
- if ((p->te != p->fe) && (*p->te))
- p->te++;
+ if ((te != p->fe) && (*te))
+ te++;
break;
case '.':
@@ -808,28 +812,30 @@ static void _get_token(struct parser *p, int tok_prev)
case '+':
case '-':
if (values_allowed) {
- p->te++;
- while ((p->te != p->fe) && (*p->te)) {
- if (*p->te == '.') {
+ te++;
+ while ((te != p->fe) && (*te)) {
+ if (*te == '.') {
if (p->t == TOK_FLOAT)
break;
p->t = TOK_FLOAT;
- } else if (!isdigit((int) *p->te))
+ } else if (!isdigit((int) *te))
break;
- p->te++;
+ te++;
}
break;
}
default:
p->t = TOK_IDENTIFIER;
- while ((p->te != p->fe) && (*p->te) && !isspace(*p->te) &&
- (*p->te != '#') && (*p->te != '=') &&
- (*p->te != SECTION_B_CHAR) &&
- (*p->te != SECTION_E_CHAR))
- p->te++;
+ while ((te != p->fe) && (*te) && !isspace(*te) &&
+ (*te != '#') && (*te != '=') &&
+ (*te != SECTION_B_CHAR) &&
+ (*te != SECTION_E_CHAR))
+ te++;
break;
}
+
+ p->te = te;
}
static void _eat_space(struct parser *p)
@@ -859,22 +865,12 @@ static void _eat_space(struct parser *p)
*/
static struct config_value *_create_value(struct dm_pool *mem)
{
- struct config_value *v = dm_pool_alloc(mem, sizeof(*v));
-
- if (v)
- memset(v, 0, sizeof(*v));
-
- return v;
+ return dm_pool_zalloc(mem, sizeof(struct config_value));
}
static struct config_node *_create_node(struct dm_pool *mem)
{
- struct config_node *n = dm_pool_alloc(mem, sizeof(*n));
-
- if (n)
- memset(n, 0, sizeof(*n));
-
- return n;
+ return dm_pool_zalloc(mem, sizeof(struct config_node));
}
static char *_dup_tok(struct parser *p)
diff --git a/lib/filters/filter-persistent.c b/lib/filters/filter-persistent.c
index 7f48a479..2ed94007 100644
--- a/lib/filters/filter-persistent.c
+++ b/lib/filters/filter-persistent.c
@@ -318,9 +318,8 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
struct dev_filter *f = NULL;
struct stat info;
- if (!(pf = dm_malloc(sizeof(*pf))))
+ if (!(pf = dm_zalloc(sizeof(*pf))))
return_NULL;
- memset(pf, 0, sizeof(*pf));
if (!(pf->file = dm_malloc(strlen(file) + 1)))
goto_bad;
diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c
index d38c8874..bc587442 100644
--- a/lib/format1/disk-rep.c
+++ b/lib/format1/disk-rep.c
@@ -624,13 +624,12 @@ static int _write_pvd(struct disk_list *data)
/* Make sure that the gap between the PV structure and
the next one is zeroed in order to make non LVM tools
happy (idea from AED) */
- buf = dm_malloc(size);
+ buf = dm_zalloc(size);
if (!buf) {
log_error("Couldn't allocate temporary PV buffer.");
return 0;
}
- memset(buf, 0, size);
memcpy(buf, &data->pvd, sizeof(struct pv_disk));
log_debug("Writing %s PV metadata to %s at %" PRIu64 " len %"
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index f41fd7f6..d6c462a5 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -157,7 +157,7 @@ static struct volume_group *_build_vg(struct format_instance *fid,
struct dm_list *pvs,
struct dm_pool *mem)
{
- struct volume_group *vg = dm_pool_alloc(mem, sizeof(*vg));
+ struct volume_group *vg = dm_pool_zalloc(mem, sizeof(*vg));
struct disk_list *dl;
if (!vg)
@@ -166,8 +166,6 @@ static struct volume_group *_build_vg(struct format_instance *fid,
if (dm_list_empty(pvs))
goto_bad;
- memset(vg, 0, sizeof(*vg));
-
vg->cmd = fid->fmt->cmd;
vg->vgmem = mem;
vg->fid = fid;
diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c
index 864034bb..e2617372 100644
--- a/lib/format1/import-export.c
+++ b/lib/format1/import-export.c
@@ -506,9 +506,8 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
* setup the pv's extents array
*/
len = sizeof(struct pe_disk) * dl->pvd.pe_total;
- if (!(dl->extents = dm_pool_alloc(dl->mem, len)))
+ if (!(dl->extents = dm_pool_zalloc(dl->mem, len)))
goto_out;
- memset(dl->extents, 0, len);
dm_list_iterate_items(ll, &vg->lvs) {
if (ll->lv->status & SNAPSHOT)
diff --git a/lib/format_text/export.c b/lib/format_text/export.c
index d16a7fcf..d49090cc 100644
--- a/lib/format_text/export.c
+++ b/lib/format_text/export.c
@@ -742,10 +742,9 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp)
_init();
- if (!(f = dm_malloc(sizeof(*f))))
+ if (!(f = dm_zalloc(sizeof(*f))))
return_0;
- memset(f, 0, sizeof(*f));
f->data.fp = fp;
f->indent = 0;
f->header = 1;
@@ -767,11 +766,9 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
_init();
- if (!(f = dm_malloc(sizeof(*f))))
+ if (!(f = dm_zalloc(sizeof(*f))))
return_0;
- memset(f, 0, sizeof(*f));
-
f->data.buf.size = 65536; /* Initial metadata limit */
if (!(f->data.buf.start = dm_malloc(f->data.buf.size))) {
log_error("text_export buffer allocation failed");
diff --git a/lib/label/label.c b/lib/label/label.c
index 9a10d066..c622812f 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -383,11 +383,10 @@ struct label *label_create(struct labeller *labeller)
{
struct label *label;
- if (!(label = dm_malloc(sizeof(*label)))) {
+ if (!(label = dm_zalloc(sizeof(*label)))) {
log_error("label allocaction failed");
return NULL;
}
- memset(label, 0, sizeof(*label));
label->labeller = labeller;