From 647a0fb098bada862b49a51e3a31be847207c59a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Oct 2012 23:15:09 +0100 Subject: [PATCH] lib/util: Simplify bitmap.c a bit This avoids the double-talloc for bitmaps Signed-off-by: Volker Lendecke Reviewed-by: Michael Adam --- lib/util/bitmap.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/util/bitmap.c b/lib/util/bitmap.c index 1ae2aaaf710a..77de55aec7c6 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; } -- 2.34.1