Skip to content
Back to skills

Detecting Unchecked Malloc

ASecurity

Detects unchecked return values of memory allocation functions like malloc, calloc, and realloc that can lead to null pointer dereferences. Use when analyzing memory allocation, error handling, or investigating null pointer risks.

  • 666 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added February 8, 2026
businessc++security

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill detecting-unchecked-malloc --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Detecting Unchecked Malloc?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Detecting Unchecked Malloc
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-detecting-unchecked-malloc/badge)](https://www.skillsdirectory.com/skills/majiayu000-detecting-unchecked-malloc)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: detecting-unchecked-malloc
description: Detects unchecked return values of memory allocation functions like malloc, calloc, and realloc that can lead to null pointer dereferences. Use when analyzing memory allocation, error handling, or investigating null pointer risks.
---

# Unchecked Return Value of Malloc Detection

## Detection Workflow

1. **Identify allocation operations**: Find all malloc() calls, locate calloc() calls, identify realloc() calls, map new/delete operations
2. **Trace return values**: Follow allocation result, identify first dereference, check for NULL validation, assess error handling
3. **Check error handling**: Verify NULL checks exist, assess error handling completeness, review fallback behavior, check for graceful degradation
4. **Assess impact**: Can allocation fail? What happens on failure? Is crash possible? What's the security impact?

## Key Patterns

- Unchecked malloc: malloc() return value not checked, direct use of malloc() result, no NULL check before dereference, assumption malloc never fails
- Unchecked calloc: calloc() return value not checked, direct use of calloc() result, no NULL check before dereference, assumption calloc never fails
- Unchecked realloc: realloc() return value not checked, direct assignment to original pointer, no NULL check before dereference, losing original pointer on failure
- Unchecked new (C++): new return value not checked, assuming new never throws, no exception handling, missing std::nothrow usage

## Output Format

Report with: id, type, subtype, severity, confidence, location, vulnerability, allocation_call, allocation_type, allocation_size, null_check, first_dereference, exploitable, attack_scenario, impact, mitigation.

## Severity Guidelines

- **HIGH**: Unchecked allocation in critical code
- **MEDIUM**: Unchecked allocation causing crashes
- **LOW**: Unchecked allocation with limited impact

## See Also

- `patterns.md` - Detailed detection patterns and exploitation scenarios
- `examples.md` - Example analysis cases and code samples
- `references.md` - CWE references and mitigation strategies

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.