DeleteSecurityContext function (sspi.h)

The DeleteSecurityContext function deletes the local data structures associated with the specified security context initiated by a previous call to the InitializeSecurityContext (General) function or the AcceptSecurityContext (General) function.


  [in] PCtxtHandle phContext


[in] phContext

Handle of the security context to delete.


Do not use the same context handle in concurrent calls to DeleteSecurityContext. The API implementation in the security service providers is not thread-safe.

Return value

If the function succeeds or the handle has already been deleted, the return value is SEC_E_OK.

If the function fails, the return value can be the following error code:

Return code Description
SEC_E_INVALID_HANDLE The handle passed to the function is not valid.


The DeleteSecurityContext function terminates a security context and frees associated resources.

The caller must call this function for a security context when that security context is no longer needed. This is true if the security context is partial, incomplete, rejected, or failed. After the security context is successfully deleted, further use of that security context is not permitted and the handle is no longer valid.


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header sspi.h (include Security.h)
Library Secur32.lib
DLL Secur32.dll

See also

AcceptSecurityContext (General)

InitializeSecurityContext (General)

SSPI Functions