AIPM
Theme

AIPM package

Memory Safety Patterns

@wshobson/memory-safety-patterns@1.0.0

Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C.

Scanned · no issues · Oct 28, 2026

GitHub stars: ★ 42K

LinkedInPost

Install Skill

Pins this version in aipm.package.json and aipm-lock.json.

aipm add @wshobson/memory-safety-patterns@1.0.0

Without project tracking

Writes the skill files only. Add --no-init to skip aipm.package.json and the lockfile.

aipm add @wshobson/memory-safety-patterns@1.0.0 --no-init

How to use

Install the skill above, then run this in your AI tool:

/memory-safety-patterns <your description>

About

Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management.

Source

What gets added to your project

Preview every file this package writes on install before you run the command above.

Summary

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.

Skill instructions

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 TypeDescriptionPrevention
Use-after-freeAccess freed memoryOwnership, RAII
Double-freeFree same memory twiceSmart pointers
Memory leakNever free memoryRAII, GC
Buffer overflowWrite past buffer endBounds checking
Dangling pointerPointer to freed memoryLifetime tracking
Data raceConcurrent unsynchronized accessOwnership, Sync

2. Safety Spectrum

code
Manual (C) → Smart Pointers (C++) → Ownership (Rust) → GC (Go, Java)
Less safe                                              More safe
More control                                           Less control

Detailed 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 unsafe carelessly - In Rust, minimize it
  • Don't assume thread safety - Be explicit

Debugging Tools

bash
# 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

Loading package files…

Share this package

Add an Install with AIPM badge

Add this badge to a GitHub README so readers can open the package page and install the same version.

Install with AIPM
[![Install with AIPM](https://www.aipm-registry.com/install-with-aipm.svg)](https://www.aipm-registry.com/skills/wshobson/memory-safety-patterns/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)

Publisher

Seth Hobson

This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.

AI assistant context

What this skill is for

@wshobson/memory-safety-patterns@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: 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
aipm add @wshobson/memory-safety-patterns@1.0.0
Use after install
/memory-safety-patterns <your description>

Tool targets

Install command by target

Add --no-init to any of these when you want the skill files without aipm.package.json or aipm-lock.json.

cursor

Run this variant when you want to install the package into cursor.

aipm add @wshobson/memory-safety-patterns@1.0.0 --target cursor --ci

claude

Run this variant when you want to install the package into claude.

aipm add @wshobson/memory-safety-patterns@1.0.0 --target claude --ci

Discussion

Comments (0)

Loading comments…

Package FAQ

Install and compatibility

How to install
Run aipm add @wshobson/memory-safety-patterns@1.0.0 in a project that has AIPM initialized.
Supported tools
@wshobson/memory-safety-patterns@1.0.0 supports All tools.

Before installing

AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.