Memory Safety Patterns
Unverified●30/40Claude Code◐PartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
Cursor·UnknownWe have not crawled the repo tree, so we will not guess
Codex·UnknownWe have not crawled the repo tree, so we will not guess
Gemini CLI·UnknownThe spec defines no detection rule for Gemini
Copilot·UnknownWe have not crawled the repo tree, so we will not guess
npx agentalley add memory-safety-patternsWho is stuck, and on what
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.
The whole source
Frontmatter — 2 properties
| name | memory-safety-patterns |
|---|---|
| description | 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. |
| 1 | --- |
| 2 | name: memory-safety-patterns |
| 3 | description: 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. |
| 4 | ---A5 — No allowed-tools declared — no way to tell what this skill may touch |
| 5 | |
| 6 | # Memory Safety Patterns |
| 7 | |
| 8 | Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | - Writing memory-safe systems code |
| 13 | - Managing resources (files, sockets, memory) |
| 14 | - Preventing use-after-free and leaks |
| 15 | - Implementing RAII patterns |
| 16 | - Choosing between languages for safety |
| 17 | - Debugging memory issues |
| 18 | |
| 19 | ## Core Concepts |
| 20 | |
| 21 | ### 1. Memory Bug Categories |
| 22 | |
| 23 | | Bug Type | Description | Prevention | |
| 24 | | -------------------- | -------------------------------- | ----------------- | |
| 25 | | **Use-after-free** | Access freed memory | Ownership, RAII | |
| 26 | | **Double-free** | Free same memory twice | Smart pointers | |
| 27 | | **Memory leak** | Never free memory | RAII, GC | |
| 28 | | **Buffer overflow** | Write past buffer end | Bounds checking | |
| 29 | | **Dangling pointer** | Pointer to freed memory | Lifetime tracking | |
| 30 | | **Data race** | Concurrent unsynchronized access | Ownership, Sync | |
| 31 | |
| 32 | ### 2. Safety Spectrum |
| 33 | |
| 34 | ``` |
| 35 | Manual (C) → Smart Pointers (C++) → Ownership (Rust) → GC (Go, Java) |
| 36 | Less safe More safe |
| 37 | More control Less control |
| 38 | ``` |
| 39 | |
| 40 | ## Detailed patterns and worked examples |
| 41 | |
| 42 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 43 | |
| 44 | ## Best Practices |
| 45 | |
| 46 | ### Do's |
| 47 | |
| 48 | - **Prefer RAII** - Tie resource lifetime to scope |
| 49 | - **Use smart pointers** - Avoid raw pointers in C++ |
| 50 | - **Understand ownership** - Know who owns what |
| 51 | - **Check bounds** - Use safe access methods |
| 52 | - **Use tools** - AddressSanitizer, Valgrind, Miri |
| 53 | |
| 54 | ### Don'ts |
| 55 | |
| 56 | - **Don't use raw pointers** - Unless interfacing with C |
| 57 | - **Don't return local references** - Dangling pointer |
| 58 | - **Don't ignore compiler warnings** - They catch bugs |
| 59 | - **Don't use `unsafe` carelessly** - In Rust, minimize it |
| 60 | - **Don't assume thread safety** - Be explicit |
| 61 | |
| 62 | ## Debugging Tools |
| 63 | |
| 64 | ```bash |
| 65 | # AddressSanitizer (Clang/GCC) |
| 66 | clang++ -fsanitize=address -g source.cpp |
| 67 | |
| 68 | # Valgrind |
| 69 | valgrind --leak-check=full ./program |
| 70 | |
| 71 | # Rust Miri (undefined behavior detector) |
| 72 | cargo +nightly miri run |
| 73 | |
| 74 | # ThreadSanitizer |
| 75 | clang++ -fsanitize=thread -g source.cpp |
| 76 | ``` |
| 77 |
Reviews
Installed this one?Write the first review and take the Trailblazer badge.
Alternatives
Subagent Driven DevelopmentUse when executing implementation plans with independent tasks in the current session◐◐◐◐◐●36/40Python Code Style & DocumentationPython code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.◐····●35/40Competitor Price Analysis 💲Competitor pricing strategy analysis and market positioning. Price mapping, pricing gaps identification, elasticity signals evaluation, and strategic pricing optimization. Use when the user asks about competitor pricing, price analysis, pricing strategy, or co◐····●34/40Competitor Price Tracker 📊Set up competitor price tracking and monitoring workflows. Track price changes, detect promotions, analyze pricing patterns, and get alerts for competitive price movements.◐····●34/40