memory-safety-patterns

Apply RAII, ownership, and smart pointers to prevent memory bugs in C, C++, and Rust.

Updated May 16, 2026
One-click install
npx skills add https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory --skill memory-safety-patterns-p-o-ke-nae
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory-safety-patterns
Source: https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory/tree/main/.github/skills/memory-safety-patterns
Command: npx skills add https://github.com/p-o-ke-nae/pokemondamagecalculatorforstory --skill memory-safety-patterns-p-o-ke-nae

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you design and refactor systems code to avoid memory leaks, dangling references, double frees, buffer overflows, and data races across low-level languages.

Core Features & Use Cases

  • Resource lifetime management: Apply RAII, ownership, and scoped cleanup to files, sockets, locks, and heap allocations.
  • Language-specific safety patterns: Use smart pointers in C++, borrowing and lifetimes in Rust, and structured cleanup patterns in C.
  • Debugging and prevention: Identify common memory hazards, choose safer abstractions, and use tools such as sanitizers, Valgrind, and Miri.
  • Use case: Refactor a C++ service that leaks sockets and crashes under concurrency by introducing ownership boundaries, lock guards, and explicit cleanup paths.

Quick Start

Ask for a memory-safe rewrite of your C, C++, or Rust code and request RAII, ownership fixes, and resource cleanup guidance.

Frequently Asked Questions about memory-safety-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent memory leaks and dangling pointers in C++ systems code?

To prevent memory leaks and dangling pointers in C++ systems code, apply RAII principles and use smart pointers to bind resource lifetimes to object scope, ensuring automatic cleanup and safe ownership transfer.

What's the best way to manage resource cleanup for sockets and file handles in Rust?

The best way to manage resource cleanup for sockets and file handles in Rust is using ownership and lifetime rules, which automatically drop resources when they go out of scope without manual intervention.

How do I fix data races and double frees in concurrent C and C++ programs?

To fix data races and double frees in concurrent C and C++ programs, establish strict ownership boundaries and apply thread-safe synchronization patterns like lock guards to protect shared state.

Can I use RAII and smart pointers to refactor unsafe heap allocations?

Yes, you can use RAII and smart pointers to refactor unsafe heap allocations by replacing raw pointers with scoped abstractions that automatically enforce bounds checking and prevent buffer overflows.

What tools work with memory safety patterns to detect buffer overflows?

Tools that work with memory safety patterns to detect buffer overflows include sanitizers, Valgrind, and Miri, which validate low-level code, identify unsafe memory access, and verify concurrency-safe execution.

Why does my C++ service crash under concurrency, and how do I apply structured cleanup?

Your C++ service crashes under concurrency due to improper lock management; apply structured cleanup by introducing explicit ownership boundaries and lock guards to ensure thread-safe synchronization and reliable resource release.