memory-safety-patterns – Agents & Automation skill for AI agents
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.
Install the memory-safety-patterns skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/memory-safety-patterns-b2b84.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /memory-safety-patterns – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/memory-safety-patterns-b2b84.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $memory-safety-patterns – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/memory-safety-patterns-b2b84.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /memory-safety-patterns – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/memory-safety-patterns-b2b84.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /memory-safety-patterns – then describe the task you want done.
SKILL.md content
Memory Safety Patterns
Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management.
When to Use This Skill
- Writing memory-safe systems code
- Managing resources (files, sockets, memory)
- Preventing use-after-free and leaks
- Implementing RAII patterns
- Choosing between languages for safety
- Debugging memory issues
Core Concepts
1. Memory Bug Categories
| 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 |
2. Safety Spectrum
Manual (C) → Smart Pointers (C++) → Ownership (Rust) → GC (Go, Java)
Less safe More safe
More control Less controlDetailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
Do's
- Prefer RAII - Tie resource lifetime to scope
- Use smart pointers - Avoid raw pointers in C++
- Understand ownership - Know who owns what
- Check bounds - Use safe access methods
- Use tools - AddressSanitizer, Valgrind, Miri
Don'ts
- Don't use raw pointers - Unless interfacing with C
- Don't return local references - Dangling pointer
- Don't ignore compiler warnings - They catch bugs
- Don't use
unsafecarelessly - In Rust, minimize it - Don't assume thread safety - Be explicit
Debugging Tools
# 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.cppRelated skills
- hermes-agent – Use, configure, theme, extend, and orchestrate Hermes Agent.
- hermes-agent-skill-authoring – Author in-repo SKILL.md files: frontmatter and structure.
- cross-eval – /c-level-agents:cross-eval [memo] — Multi-model consensus on a board memo or strategy…
- honcho – Configure and troubleshoot Honcho memory for Hermes.
- decide – /c-level-agents:decide [memo] — Log a decision to two-layer memory via decision-logger…
- kanban-video-orchestrator – Plan and run multi-agent video production pipelines.
- parallel-feature-development – Coordinate parallel feature development with file ownership strategies, conflict…
- engineering-advanced-skills – Index of 37 advanced engineering agent skills for Claude Code, Codex, Gemini CLI…