Skip to content
Back to skills

Cpp Pitfalls

ASecurity

Mistakes in C++ that compile and pass review, and freeze or crash only on an error path or at exit. Use when writing or reviewing C++.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 18, 2026
developmentgoc++api

Works with

  • api

Security analysis

A100/100

Scanned November 18, 2026

npx -y skills add eduardoghi/dev-skills --skill cpp-pitfalls --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cpp Pitfalls?

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

Security grade badge for Cpp Pitfalls
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/eduardoghi-cpp-pitfalls/badge)](https://www.skillsdirectory.com/skills/eduardoghi-cpp-pitfalls)

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: cpp-pitfalls
description: Mistakes in C++ that compile and pass review, and freeze or crash only on an error path or at exit. Use when writing or reviewing C++.
paths:
  - "**/*.cpp"
  - "**/*.cc"
  - "**/*.cxx"
  - "**/*.h"
  - "**/*.hpp"
---

# C++ pitfalls

## An early return after taking a lock

A function takes a lock that other threads share, such as the device lock of a Direct3D 11 or
GStreamer decoder, and a check further down returns early before the matching unlock. The lock
stays held for good, and every thread waiting on it stops, which looks like frozen video rather
than an error. It happens most when an early return is added later to a function that had one
exit.

Do the checks that can leave before taking the lock, or hold it through an RAII guard that
releases it on every return:

```cpp
std::lock_guard lock(mutex);
```

When the lock comes from a C API with separate lock and unlock calls, a small guard struct with
the unlock in its destructor does the same.

## Threads still using a driver when the process ends

`exit`, including the return from `main`, runs the cleanup that libraries registered, the
graphics driver's among them. A worker thread that is still releasing something on that driver
races the cleanup, and the process aborts with a double free on the way out. Telling the threads
to stop isn't enough. Wait for them with a deadline before returning, and past the deadline end
with `_exit`, which skips the cleanup, after anything that has to persist was saved.

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.

View all in development →

Comments

Loading comments…

Newsletter

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