Mismatched C++ memory allocation and deallocation functions

ID

c.memory_management.mismatched_memory_management_cpp

Severity

low

Remediation Complexity

hard

Remediation Risk

high

Remediation Effort

medium

Resource

Memory Management

Language

C / C++

Description

The software attempts to return a memory resource to the system, but it calls a release function that is not compatible with the function that was originally used to allocate that resource. Matching is syntactic, so an allocation and its release cannot be paired across a function boundary: review the findings and tune the allocator and deallocator lists to the ones your codebase actually uses.

Rationale

The software attempts to return a memory resource to the system, but it calls a release function that is not compatible with the function that was originally used to allocate that resource. Matching is syntactic, so an allocation and its release cannot be paired across a function boundary: review the findings and tune the allocator and deallocator lists to the ones your codebase actually uses.

The following code illustrates a vulnerable pattern detected by this rule:

void bad1()
{
	BarObj *ptr = new BarObj()

		// VULNERABLE: Mismatched C++ memory allocation and deallocation functions
		free(ptr);
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved