ערוך

שתף באמצעות


Warning C26405

Do not assign to an owner<T> which may be in valid state (r.3)

Remarks

If an owner pointer already points to a valid memory buffer, it must not be assigned to another value without releasing its current resource first. Such assignment may lead to a resource leak even if the resource address is copied into some raw pointer (because raw pointers shouldn't release resources). For more information, see the C++ Core Guidelines.

Code analysis name: DONT_ASSIGN_TO_VALID

Example 1

Overwriting an owner in a loop:

gsl::owner<Shape*> shape = nullptr;
while (shape = NextShape()) // C26405
    Process(shape) ? delete shape : 0;