Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.02 KB

File metadata and controls

40 lines (30 loc) · 1.02 KB
description Learn more about: Warning C26404 DONT_DELETE_INVALID
title Warning C26404
ms.date 07/21/2017
f1_keywords
C26404
DONT_DELETE_INVALID
helpviewer_keywords
C26404
ms.assetid 94afb700-3f3b-40db-8afc-2481935360c2

Warning C26404

Do not delete an owner<T> which may be in invalid state (r.3)

Remarks

Once an owner pointer releases or transfers its resource, it gets into an "invalid" state. Deleting such a pointer may lead to immediate memory corruption due to double delete, or to an access violation when the deleted resource is accessed from another owner pointer.

Code analysis name: DONT_DELETE_INVALID

Example 1

Deleting an owner after transferring its value:

gsl::owner<State*> validState = nullptr;
gsl::owner<State*> state = ReadState();
validState = state;
if (!IsValid(state))
    delete state;   // C26404

Example 2

Deleting an uninitialized owner:

gsl::owner<Message*> message;
if (popLast)
    message = ReleaseMessage();
delete message; // C26404