Get the latest tech news
Tip of the day #2: A safer arena allocator
Published on 2024-10-29 Discussions: /r/programming, /r/cprogramming The most transformative action you can do to dramatically improve your code in a programming language where you are in control of the memory is: to use arenas. Much has been written about arenas (1, 2).
Very simple, just ask the OS to give us a region of virtual memory and off we go (on Windows, the system call is named differently but is equivalent). Replace all direct array and pointer accesses with macros that check bounds (like most modern programming languages) Tweak how the arena is created to make it safer. Also, reusing a previously allocated-then-freed object with a different type, without zero-initializing it, can leak secrets or information about the state of the program, to an attacker.
Or read this on Hacker News