summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-10-30 23:15:09 +0100
committerMichael Adam <obnox@samba.org>2012-11-07 15:32:24 +0100
commit647a0fb098bada862b49a51e3a31be847207c59a (patch)
treef395f2c59b12f5e6734f8420a87d41e20297294f
parent7f4d55d1b8bda4f0d7a8bdbfe82c9a623dfe5843 (diff)
downloadsamba-647a0fb098bada862b49a51e3a31be847207c59a.tar.gz
samba-647a0fb098bada862b49a51e3a31be847207c59a.tar.bz2
samba-647a0fb098bada862b49a51e3a31be847207c59a.zip
lib/util: Simplify bitmap.c a bit
This avoids the double-talloc for bitmaps Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
-rw-r--r--lib/util/bitmap.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/util/bitmap.c b/lib/util/bitmap.c
index 1ae2aaaf71..77de55aec7 100644
--- a/lib/util/bitmap.c
+++ b/lib/util/bitmap.c
@@ -21,8 +21,8 @@
#include "lib/util/bitmap.h"
struct bitmap {
- uint32_t *b;
unsigned int n;
+ uint32_t b[1]; /* We allocate more */
};
/* these functions provide a simple way to allocate integers from a
@@ -35,16 +35,15 @@ struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n)
{
struct bitmap *bm;
- bm = talloc(mem_ctx, struct bitmap);
+ bm = (struct bitmap *)talloc_zero_size(
+ mem_ctx,
+ offsetof(struct bitmap, b) + sizeof(uint32_t)*((n+31)/32));
if (!bm) return NULL;
+ talloc_set_name_const(bm, "struct bitmap");
+
bm->n = n;
- bm->b = talloc_zero_array(bm, uint32_t, (n+31)/32);
- if (!bm->b) {
- TALLOC_FREE(bm);
- return NULL;
- }
return bm;
}