Agent skill · software engineering · aiskillstore

memory-safety-patterns

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.

Why this skill is useful

Provides specific patterns and code examples for implementing memory safety in systems programming across multiple languages, which the AI may not generate reliably on its own.

What it needs

About 7k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.

What this skill does

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 Patterns by Language Pattern 1: RAII in C++ Pattern 2: Smart Pointers in C++ Pattern 3: Ownership in Rust Pattern 4: Safe Resource Management in C Pattern 5: Bounds Checking Pattern 6: Preventing Data Races 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 Resources C++ Core Guidelines Rust Ownership AddressSanitizer

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills aiskillstore/memory-safety-patterns--240ffb

View the source on GitHub

Browse the @skills marketplace