一键导入
check-memory-safety
Check Mojo code for memory safety issues (ownership violations, use-after-free, etc.). Use to catch memory bugs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Check Mojo code for memory safety issues (ownership violations, use-after-free, etc.). Use to catch memory bugs.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run section orchestrators to coordinate multi-component workflows. Use when starting work on a section.
Validate agent YAML frontmatter and configuration. Use before committing agent changes or in CI.
Reply to PR review comments using the correct GitHub API endpoint. Use when responding to inline code review feedback (not gh pr comment).
Run Mojo tests using mojo test command. Use when executing tests or verifying test coverage.
Track implementation progress against plan. Use to monitor component delivery and identify blockers.
Check agent configuration coverage across hierarchy levels and phases. Use to ensure complete agent system coverage.
| name | check-memory-safety |
| description | Check Mojo code for memory safety issues (ownership violations, use-after-free, etc.). Use to catch memory bugs. |
| category | mojo |
| mcp_fallback | none |
Validate Mojo code for memory safety violations and ownership issues.
# Find potential use-after-free patterns
grep -n "var .* = .*\^" *.mojo | head -20
# Check for uninitialized access
grep -n "List\[.*\]()" *.mojo | grep -A 2 "\..*\["
# Verify ownership transfer
grep -n "owned\|var.*=" *.mojo | sort
# Check pointer operations
grep -n "DTypePointer\|alloc\|free\|__del__" *.mojo
# Find scope issues
grep -n "{" *.mojo | wc -l # Check nesting depth
Safe Ownership Transfer:
fn take(var data: List[Int]) - Caller loses accessreturn self.data^ - Transfer from struct fieldvar copy = data^ - Move to new variablefn take(data: List[Int]) - Ambiguous, use varreturn self.data - Missing transfer operatorSafe Initialization:
var shape = List[Int]() then shape.append(dim)var data = DTypePointer[DType.float32].alloc(size)size > 0 before allocationvar list = List[Int]() then list[0] = value (uninitialized)alloc(0) or alloc(negative) (invalid size)Safe Pointer Usage:
alloc(size)Safe Scope Management:
Report memory safety issues with:
Uninitialized List Access:
var list = List[Int](); list[0] = 5list.append(5) insteadUse After Move:
var a = list^; print(list) (list moved, now invalid)Missing Bounds Check:
tensor._data[index] without size checkassert index < size or check in loopPointer Without Size:
var ptr = alloc(size) but size not trackedDouble-Free:
free() called twice on same pointer| Problem | Solution |
|---|---|
| Compiler not available | Build with mojo build to get errors |
| Complex ownership | Trace step-by-step through ownership chain |
| Generic code | Check all type instantiations |
| External code | Verify contract assumptions |
| False positives | Verify with test execution |
Before committing Mojo code:
^