diff options
author | Jerome Forissier <jerome.forissier@linaro.org> | 2019-02-13 13:19:38 +0100 |
---|---|---|
committer | Jérôme Forissier <jerome.forissier@linaro.org> | 2019-05-13 15:58:03 +0200 |
commit | 4e5706550a9624fbb6eadfc275036563a8737893 (patch) | |
tree | 2863de9ab363cd1fe4b076eb536763b80b355268 /lib/libutils/isoc/bget.c | |
parent | e1509d6e6178011df581c535ee8bf8c147053df2 (diff) |
libutils: add free_wipe()
Adds function free_wipe(void *ptr) to clear a buffer before returning
it to the heap. The pattern used to overwrite the data is 0x55.
Users have to #include <stdlib_ext.h> to import the declaration.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Diffstat (limited to 'lib/libutils/isoc/bget.c')
-rw-r--r-- | lib/libutils/isoc/bget.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/libutils/isoc/bget.c b/lib/libutils/isoc/bget.c index f70a1145..2619874d 100644 --- a/lib/libutils/isoc/bget.c +++ b/lib/libutils/isoc/bget.c @@ -460,6 +460,7 @@ #endif #include <stdio.h> +#include <stdbool.h> #ifdef lint #define NDEBUG /* Exits in asserts confuse lint */ @@ -838,15 +839,16 @@ void *bgetr(buf, size, poolset) if (size > osize) V memset((char *) nbuf + osize, 0, size - osize); #endif - brel(buf, poolset); + brel(buf, poolset, false /* !wipe */); return nbuf; } /* BREL -- Release a buffer. */ -void brel(buf, poolset) +void brel(buf, poolset, wipe) void *buf; struct bpoolset *poolset; + int wipe; { struct bfhead *b, *bn; bufsize bs; @@ -857,6 +859,9 @@ void brel(buf, poolset) #endif assert(buf != NULL); +#ifdef FreeWipe + wipe = true; +#endif #ifdef BECtl if (b->bh.bsize == 0) { /* Directly-acquired buffer? */ struct bdhead *bdh; @@ -868,10 +873,11 @@ void brel(buf, poolset) assert(poolset->totalloc >= 0); poolset->numdrel++; /* Number of direct releases */ #endif /* BufStats */ -#ifdef FreeWipe - V memset_unchecked((char *) buf, 0x55, - (MemSize) (bdh->tsize - sizeof(struct bdhead))); -#endif /* FreeWipe */ + if (wipe) { + V memset_unchecked((char *) buf, 0x55, + (MemSize) (bdh->tsize - + sizeof(struct bdhead))); + } bs = bdh->tsize - sizeof(struct bdhead); assert(poolset->relfcn != NULL); poolset->relfcn((void *) bdh); /* Release it directly. */ @@ -956,10 +962,10 @@ void brel(buf, poolset) bn = BFH(((char *) b) + b->bh.bsize); } -#ifdef FreeWipe - V memset_unchecked(((char *) b) + sizeof(struct bfhead), 0x55, - (MemSize) (b->bh.bsize - sizeof(struct bfhead))); -#endif + if (wipe) { + V memset_unchecked(((char *) b) + sizeof(struct bfhead), 0x55, + (MemSize) (b->bh.bsize - sizeof(struct bfhead))); + } assert(bn->bh.bsize < 0); /* The next buffer is allocated. Set the backpointer in it to point |