Skip to main content

SKY-D437 · Security in code

Local pointer used after free

Skylos reports a direct dereference, array access or member access after a known local C allocation was freed in the same straight-line C++ block. The finding points to the evaluated access.

Languages
C++
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Freed storage no longer belongs to the program's pointer. Reading or writing through it is undefined behavior even when the old bytes are still present.

What Skylos flags

sample.cpp · C++Reported on line 6
#include <cstdlib> int sample() {    auto *ptr = static_cast<char *>(std::calloc(1, 8));    std::free(ptr);    return ptr[0];}

What Skylos leaves alone

sample.cpp · C++
#include <cstdlib> int sample() {    auto *ptr = static_cast<char *>(std::calloc(1, 8));    if (!ptr) return 0;    int value = ptr[0];    std::free(ptr);    return value;}

Why Skylos leaves it alone

The evaluated access occurs before free, and the function returns a copied value.

How Skylos decides

  1. Tracks known local malloc and calloc allocations and simple aliases within one straight-line block.
  2. Reports evaluated accesses through a freed pointer. Unevaluated operands such as sizeof are separate from actual reads.

How to fix it

Complete all uses before releasing the allocation. Use an owning container or an RAII wrapper where possible.

When it can be wrong

  • The check covers local operations with a visible allocation and free. Lifetime across functions, branches, or ownership transfers needs separate review.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark the reviewed line with a rule-scoped Skylos ignore for SKY-D437. Record the evidence that justifies the exception.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.