CVE-2026-33811: Go Defer Free Reassigned Pointer

Passing a pointer variable directly to a deferred free/deallocation call evaluates the argument at defer registration time. If the variable is reassigned or reallocated later, the deferred call will free the stale pointer, potentially causing a double-free (CWE-415). Wrap the deallocation in a closure: defer func() { C.free(unsafe.Pointer(buf)) }().

Provally CuratedPublic repositoryMediumMedium confidenceVerifiedApache-2.0Go
greprules fetch cve-2026-33811-go-defer-free-reassigned-pointer --engine opengrep

Description

Passing a pointer variable directly to a deferred free/deallocation call evaluates the argument at defer registration time. If the variable is reassigned or reallocated later, the deferred call will free the stale pointer, potentially causing a double-free (CWE-415). Wrap the deallocation in a closure: defer func() { C.free(unsafe.Pointer(buf)) }().