Skip to content
BENIBIX Learn

Memory Safety

Also known as Memory-Safe Language, Memory Safe, Memory Unsafety

A guard that stops code from using memory it does not own.

Think of it like

It is like a parking lot with painted lines and a guard. Nobody can park in a space that is not theirs.

Example

The team that makes the Chromium web browser looked at its worst security bugs. About 70% of them came from unsafe use of memory.

Why it matters

Memory bugs cause a lot of the worst security holes. A safe language rules out whole kinds of them.

Definition

Memory safety means a program cannot read or write memory it should not touch. In C and C++, code can write past the end of an array. It can also use memory after it was freed. That can crash the program or let an attacker take over. Rust, Go, Java, C# and Python check for or block these mistakes.

Example code

python
scores = [90, 75, 88, 60]
scores[6] = 100
# IndexError: list assignment index out of range
Python stops the write past the end. It does not let it hit other memory.
Without memory safety, a write past the end hits the password. With it, the write is stopped.

Common mistake

Thinking a memory-safe language means no bugs at all. Logic errors and leaks can still happen.

Key takeaways

  1. 1
    Stay in bounds. No reading past the end.
  2. 2
    No use after free. Freed memory stays off limits.
  3. 3
    Fewer security holes. Whole bug types disappear.

Compare