Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, managing resources, or preventing memory bugs.
Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management.
| Bug Type | Description | Prevention | | -------------------- | -------------------------------- | ----------------- | | Use-after-free | Access freed memory | Ownership, RAII | | Double-free | Free same memory twice | Smart pointers | | Memory leak | Never free memory | RAII, GC | | Buffer overflow | Write past buffer end | Bounds checking | | Dangling pointer | Pointer to freed memory | Lifetime tracking | | Data race | Concurrent unsynchronized access | Ownership, Sync |
Manual (C) → Smart Pointers (C++) → Ownership (Rust) → GC (Go, Java)
Less safe More safe
More control Less control
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
unsafe carelessly - In Rust, minimize it# AddressSanitizer (Clang/GCC)
clang++ -fsanitize=address -g source.cpp
# Valgrind
valgrind --leak-check=full ./program
# Rust Miri (undefined behavior detector)
cargo +nightly miri run
# ThreadSanitizer
clang++ -fsanitize=thread -g source.cpp
Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/memory-safety-patterns · pinned to the source commit
# Run from your project root
git clone https://github.com/wshobson/agents.git .skillboard-tmp
git -C .skillboard-tmp checkout 38e19c20d2b154510b0e624a2e3e186b19b5c527
mkdir -p ".claude/skills"
cp -r ".skillboard-tmp/plugins/systems-programming/skills/memory-safety-patterns" ".claude/skills/"
rm -rf .skillboard-tmpReview the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
sudo apt update && sudo apt install -y gitnpm install -g @anthropic-ai/claude-code# Run from your project root
git clone https://github.com/wshobson/agents.git .skillboard-tmp
git -C .skillboard-tmp checkout 38e19c20d2b154510b0e624a2e3e186b19b5c527
mkdir -p ".claude/skills"
cp -r ".skillboard-tmp/plugins/systems-programming/skills/memory-safety-patterns" ".claude/skills/"
rm -rf .skillboard-tmpDestination: .claude/skills/memory-safety-patterns
Scanner static-checks@0.1.0 · commit 38e19c20d2b1. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
No static rules matched. This is not a safety guarantee.