我使用HttpContext檢索即將到來的HTTP請求的當前用戶名,但是在運行覆蓋率分析時,它會報告資源泄漏。獲取HttpContext.Current.User.Identity.Name時發生資源泄漏
public class UsersController:ApiController
{
private string userName;
public UsersController()
{
if (HttpContext.Current != null)
{
userName = HttpContext.Current.User.Identity.Name;
}
}
//I defined customized identity
public class MyIdentity : IIdentity
{
private string name;
public string AuthenticationType
{
get { return "Custom"; }
}
public bool IsAuthenticated
{
get { return true; }
}
public string Name { get; set; }
}
在Coverity的報告,它說 2. alloc_fn:一個新的資源是從分配方法Identity.get返回。 (虛擬呼叫解析爲System.Security.Claims.ClaimsPrincipal.Identity.get。) 3. noescape:資源System.Web.HttpContext.Current.User.Identity未關閉或保存在Name.get中。 (虛擬呼叫解析爲Org.Abc.HttpModules.MyIdentity.Name.get。)
CID 51307:資源泄漏(RESOURCE_LEAK) 4. leaked_resource:未能保存或通過System.Web.HttpContext創建密切資源。 Current.User.Identity泄漏它。
您是否找到解決該問題的解決方案? –
@AbdulAhadMonty我直接聯繫覆蓋支持,他們認爲它是誤報,所以沒有錯誤,我的執行:) – Bargitta
謝謝@Bargitta –