memory-safety-patterns

Provide cross-language memory safety patterns for Rust, C++, and C.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/drgaciw/academic-compliance-hub-glm --skill memory-safety-patterns-drgaciw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory-safety-patterns
Source: https://github.com/drgaciw/academic-compliance-hub-glm/tree/main/agents/plugins/systems-programming/skills/memory-safety-patterns
Command: npx skills add https://github.com/drgaciw/academic-compliance-hub-glm --skill memory-safety-patterns-drgaciw

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more secure and reliable systems code by implementing robust memory management and preventing common memory-related bugs across multiple programming languages.

Core Features & Use Cases

  • Cross-Language Patterns: Learn and apply RAII, ownership, smart pointers, and resource management techniques in C++, Rust, and C.
  • Bug Prevention: Understand and mitigate common memory errors like use-after-free, double-free, memory leaks, and buffer overflows.
  • Use Case: When developing a high-performance C++ application that handles sensitive data, use this Skill to ensure all dynamically allocated memory is properly managed and freed, preventing leaks and security vulnerabilities.

Quick Start

Implement RAII for file handling in C++ using the provided FileHandle class example.

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 use-after-free and double-free bugs in C++?

Prevent use-after-free and double-free bugs in C++ by implementing RAII and smart pointers to bind resource lifetimes to object scope, ensuring automatic deallocation. Cross-language patterns detail safe ownership transfers.

What is the best way to implement memory safety in C and C++?

Memory safety in C and C++ relies on RAII for resource management, strict bounds checking, and debugging tools like AddressSanitizer and Valgrind to detect buffer overflows and dangling pointers.

How does Rust ownership compare to C++ resource management for preventing memory leaks?

Rust ownership enforces memory safety at compile-time via borrow checker rules, preventing data races and leaks without runtime overhead. C++ resource management uses RAII and smart pointers, requiring developer discipline to avoid similar bugs.

Can I use AddressSanitizer and Valgrind to fix buffer overflows in C?

Yes, AddressSanitizer and Valgrind detect buffer overflows, memory leaks, and dangling pointers in C by runtime instrumentation. Combine these debugging tools with bounds checking patterns to mitigate common memory errors.

When do I need RAII for file handling in high-performance C++ applications?

Implement RAII for file handling in high-performance C++ applications when managing sensitive data to ensure dynamically allocated memory and file descriptors are properly freed, preventing resource leaks and security vulnerabilities.