다음을 통해 공유


PREfast Warning 211 (Windows CE 5.0)

Send Feedback

211 - Leaking memory <pointer> due to an exception.
Question: Is a local catch block needed to clean up memory?

This warning indicates that allocated memory is not being freed when an exception is thrown. The statement at the end of the path could potentially throw an exception.

Example

Defective Source

char *p1 = new char[10];
char *p2 = new char[10];

delete[] p2;
delete[] p1;

Corrected Source

char *p1 = new char[10];
char *p2;

try {
    p2 = new char[10];
} catch (std::bad_alloc *e) {
    // just handle the throw.
    ;
}

delete[] p2;
delete[] p1;

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.