C28198

警告 C28198: 因例外狀況而造成遺漏的記憶體 <pointer>。

這項警告表示在擲回例外狀況時,並未釋放已配置的記憶體。 在路徑結尾的陳述式 (Statement) 可能會引發例外狀況。 記憶體被傳遞至可能之後要釋放已儲存複本的函式。

這個警告非常類似 C28197警告。 建議與警告的附註 C28197 也可以使用在這裡。

範例

下列範例程式碼會產生這則警告:

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

test(p1);   // does not save a copy of p

delete[] p2;
delete[] p1;

下列程式碼範例可以避免這則警告:

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

test(p1);   // does not save a copy of p
try {
    p2 = new char[10];
} catch (std::bad_alloc *e) {
    // just handle the throw
    ;
}