# Is zeroing user or lib responsibility

**URL:** <https://ziggit.dev/t/is-zeroing-user-or-lib-responsibility/18073>\
**Category:** Help\
**Tags:** memory-management\
**Created:** [October 24, 2026, 3:14am UTC](https://ziggit.dev/t/is-zeroing-user-or-lib-responsibility/18073 "2026-10-24T03:14:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vexo413](https://ziggit.dev/user_avatar/ziggit.dev/vexo413/32/10418_2.png) [@Vexo413](https://ziggit.dev/u/Vexo413)\
**Post date:** [October 24, 2026, 3:14am UTC](https://ziggit.dev/t/is-zeroing-user-or-lib-responsibility/18073/1 "2026-10-24T03:14:32Z")

</div>

I’m making a core password manager/vault library, and I’m wondering whether I should zero the memory or the user should do this.

One way they could do this is through a `ZeroingAllocator`, which `std.crypto.secureZero`’s all memory that is freed. This also makes it easier for me because I have a `StringHashMap` where the keys need to be freed, and the allocators already `@constCast`.

Two problems with this:

1. User doesn’t know about having to do this.
2. User would prefer not to worry about it and have the library do it for them.

I could maybe provide a `ZeroingAllocator` with the library in the second problem, but I would like to know what other people think!

---

<div class="post-metadata">

**Author:** ![cancername](https://ziggit.dev/user_avatar/ziggit.dev/cancername/32/8752_2.png) [@cancername](https://ziggit.dev/u/cancername)\
**Post date:** [October 24, 2026, 3:46am UTC](https://ziggit.dev/t/is-zeroing-user-or-lib-responsibility/18073/2 "2026-10-24T03:46:57Z")

</div>

As far as I can tell, a most misuse resistant way is to do it yourself, either with a custom allocator that wraps the one the user provides or manually. Do see Frank Denis’ series on zeroization:

- [Part 1](https://00f.net/2026/10/06/zeroization-1/)
- [Part 2](https://00f.net/2026/10/06/zeroization-2/)
- [Part 3](https://00f.net/2026/10/06/zeroization-3/)

---

<div class="post-metadata">

**Author:** ![Vexo413](https://ziggit.dev/user_avatar/ziggit.dev/vexo413/32/10418_2.png) [@Vexo413](https://ziggit.dev/u/Vexo413)\
**Post date:** [October 24, 2026, 2:41pm UTC](https://ziggit.dev/t/is-zeroing-user-or-lib-responsibility/18073/3 "2026-10-24T14:41:52Z")

</div>

Thank you, I didn’t think of wrapping the user provided `Allocator` with `ZeroingAllocator`! I’ll make sure to read the series.
