
This one bridges the gap between C's manual memory management and Rust's compile-time guarantees by showing you the actual patterns that prevent use-after-free bugs, double-frees, and memory leaks across all three languages. It covers RAII destructors in C++, Rust's ownership system with borrowing rules, smart pointers like unique_ptr and shared_ptr, and even defensive patterns for C like goto cleanup. What I like is that it doesn't just show syntax but explains the tradeoffs between safety and control, plus it includes concrete examples of breaking reference cycles and handling interior mutability. Great for systems programmers who need to write bulletproof resource management code.
$ npx -y skills add wshobson/agents --skill memory-safety-patterns --agent claude-codeInstalls into .claude/skills of the current project.
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
Sponsors