memory-safety-patterns

memory-safety-patterns is a skill for Claude Code, Codex from Harmeet10000/skills. It costs 45 tokens per session (3,441 once invoked), scanned A, a copy of memory-safety-patterns, MIT.

Programming guidance for avoiding memory bugs in Rust, C++, and C by controlling who owns resources such as memory, files, and sockets.

In plain words
What is it for?
Use it when writing systems software, managing resources, choosing between Rust, C++, and C, or investigating memory problems.
Why use it?
It helps prevent problems such as using released memory, freeing it twice, leaking it, or writing beyond a buffer. It also explains how safety and control differ across these languages.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when writing systems software, managing resources, choosing between Rust, C++, and C, or investigating memory problems.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/harmeet10000/skills/memory-safety-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Harmeet10000/skills --skill memory-safety-patterns
Clone the repo
git clone --depth 1 https://github.com/Harmeet10000/skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for memory-safety-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/harmeet10000/skills/memory-safety-patterns.svg)](https://agentmods.dev/skills/harmeet10000/skills/memory-safety-patterns)
Your own site
<a href="https://agentmods.dev/skills/harmeet10000/skills/memory-safety-patterns"><img src="https://agentmods.dev/badge/skills/harmeet10000/skills/memory-safety-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 45 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,441 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 86% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00045 $0.03441
Opus 5 $0.00023 $0.01721
Sonnet 5 $0.00009 $0.00688
Haiku 4.5 $0.00005 $0.00344

Measured 8d ago against content hash 8a0841f8e329, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

memory-safety-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

86% identical to memory-safety-patterns — 534 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

skills/architecture/memory-safety-patterns/SKILL.md · 607 lines

How it starts

The opening of the file, as written. The whole thing — 607 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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 control

Patterns by Language

Pattern 1: RAII in C++

// RAII: Resource Acquisition Is Initialization
// Resource lifetime tied to object lifetime

#include <memory>
#include <fstream>
#include <mutex>

// File handle with RAII
class FileHandle {
public:
    explicit FileHandle(const std::string& path)
        : file_(path) {
        if (!file_.is_open()) {
            throw std::runtime_error("Failed to open file");
        }
    }

    // Destructor automatically closes file
    ~FileHandle() = default; // fstream closes in its destructor

    // Delete copy (prevent double-close)
    FileHandle(const FileHandle&) = delete;
    FileHandle& operator=(const FileHandle&) = delete;

    // Allow move
    FileHandle(FileHandle&&) = default;
    FileHandle& operator=(FileHandle&&) = default;

    void write(const std::string& data) {
        file_ << data;
    }

private:
    std::fstream file_;
};

// Lock guard (RAII for mutexes)
class Database {
public:
    void update(const std::string& key, const std::string& value) {
        std::lock_guard<std::mutex> lock(mutex_); // Released on scope exit
        data_[key] = value;
    }

    std::string get(const std::string& key) {
        std::shared_lock<std::shared_mutex> lock(shared_mutex_);
        return data_[key];
    }

private:
    std::mutex mutex_;
    std::shared_mutex shared_mutex_;
    std::map<std::string, std::string> data_;
};

// Transaction with rollback (RAII)
template<typename T>
class Transaction {
public:
    explicit Transaction(T& target)
        : target_(target), backup_(target), committed_(false) {}

    ~Transaction() {
        if (!committed_) {
            target_ = backup_; // Rollback
        }
    }

    void commit() { committed_ = true; }

    T& get() { return target_; }

private:
    T& target_;
    T backup_;
    bool committed_;
};

Read the full file on GitHub · 607 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 607 lines · 45 tokens per session scan A 8a0841f8e329

Subscribe to this mod's changes

memory-safety-patterns is a skill published in the GitHub repository Harmeet10000/skills (7 stars, last pushed 4mo ago), licensed MIT. It adds 45 tokens to every session and 3,441 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 86% identical to memory-safety-patterns, differing in 534 lines, and is treated as a copy.

Related

Other skills, from other repositories

redos

Hunt ReDoS (CWE-1333, Catastrophic Backtracking) — identify regexes with nested quantifiers or overlapping alternation that cause super-linear matching time, trace tainted input paths to regex sinks, demonstrate timing PoC, and validate with response-time delta. Covers PCRE/RE2/V8/Python re engine differences.…

PurpleAILAB/Decepticon · 117 tokens

pattern-exhaustion

Systematic pattern exhaustion methodology. Load after finding any confirmed vulnerability to search for all instances of the same root cause pattern across the codebase.

PurpleAILAB/Decepticon · 33 tokens

aatmf-t04-memory-manipulation

AATMF T4 — Multi-Turn & Memory Manipulation. Persistent memory injection, conversation-state poisoning, cross-session contamination, ghost-context leak.

PurpleAILAB/Decepticon · 39 tokens

scanner-overview

Stage 1 broad-spectrum scanner playbook. Sharded sweep over very large codebases producing CANDIDATE nodes for the Detector to reason about. Load at scanner-agent startup.

PurpleAILAB/Decepticon · 40 tokens

patch-diff-research

Authorized patch-diff workflow for deriving and validating vulnerability variants from a known vulnerable-to-fixed source change.

PurpleAILAB/Decepticon · 26 tokens

browserwing-admin

Manage and operate BrowserWing — an intelligent browser automation platform. Install dependencies, configure LLM, create/manage/execute automation scripts, use AI-driven exploration to generate scripts, browse the script marketplace, and troubleshoot issues.

MemTensor/MemOS · 47 tokens