The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at C28105.

Warning C28105: Leaking resource due to an exception

The specified resource is not freed when an exception is raised. The statement specified by the path can raise an exception. This warning is similar to warning C28103, except that in this case an exception is involved.

The following code example generates this warning:

res = KeSaveFloatingPointState(buffer);  
res = AllocateResource(Resource);  
char *p2 = new char[10]; // could throw  
delete[] p2;  

The following code example avoids this warning:

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