{"id":37491,"date":"2021-11-18T08:00:46","date_gmt":"2021-11-18T15:00:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=37491"},"modified":"2021-11-19T08:49:51","modified_gmt":"2021-11-19T15:49:51","slug":"infer-v1-2-interprocedural-memory-safety-analysis-for-c","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/infer-v1-2-interprocedural-memory-safety-analysis-for-c\/","title":{"rendered":"Infer# v1.2: Interprocedural Memory Safety Analysis For C#"},"content":{"rendered":"<p>Last December, we announced the <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/infer-interprocedural-memory-safety-analysis-for-c\/\">public preview release of Infer#<\/a>, which brings the interprocedural static analysis of <a href=\"https:\/\/fbinfer.com\/\">Infer<\/a> to the .NET community. The project was <a href=\"https:\/\/github.com\/microsoft\/infersharp\">open sourced on GitHub<\/a> under an MIT license.<\/p>\n<h2>New Feature Highlights<\/h2>\n<p>Infer# 1.2 brings race condition detection, improves performance, provides more ways to use, and expands analysis coverage. The full list of improvements can be found on the <a href=\"https:\/\/github.com\/microsoft\/infersharp\/releases\">release page<\/a>.<\/p>\n<h3>Support for Infer# On Windows via WSL2 (Windows Subsystem for Linux)<\/h3>\n<p>As the first step in our initiative to provide Windows support for Infer#, you can now <a href=\"https:\/\/github.com\/microsoft\/infersharp\/blob\/main\/RUNNING_INFERSHARP_ON_WINDOWS.md\">run the analysis in WSL2<\/a>.<\/p>\n<h3>Azure Pipelines Integration<\/h3>\n<p>We now support <a href=\"https:\/\/github.com\/microsoft\/infersharp#azure-pipelines\">Infer# as an Azure Pipelines plugin<\/a>.<\/p>\n<h3>Race Condition<\/h3>\n<p>Infer# now supports race condition detection via Infer&#8217;s <a href=\"https:\/\/fbinfer.com\/docs\/all-issue-types\/#thread_safety_violation\">RacerD<\/a> analyzer.<\/p>\n<pre><code class=\"language-csharp\">public class RaceCondition\r\n{\r\n    private readonly object _object = new object();\r\n\r\n    public void TestMethod()\r\n    {\r\n        int FirstLocal;\r\n        FirstLocal = TestClass.StaticIntegerField;\r\n    }\r\n\r\n    public void FieldWrite()\r\n    {\r\n        lock (_object)\r\n        {\r\n            {\r\n                TestClass.StaticIntegerField = 1;\r\n            }\r\n        }\r\n    }\r\n}<\/code><\/pre>\n<pre><code class=\"language-text\">Assets\/RaceCondition.cs:12: warning: Thread Safety Violation\r\n  Read\/Write race. Non-private method `RaceCondition.TestMethod()` reads without synchronization from `Assets.TestClass.Cilsil.Test.Assets.TestClass.StaticIntegerField`. Potentially races with write in method `RaceCondition.FieldWrite()`.\r\n Reporting because another access to the same memory occurs on a background thread, although this access may not.<\/code><\/pre>\n<h3>Exception Code Coverage<\/h3>\n<p>Infer# now reports warnings on methods with exception-handling constructs (for example, try-catch-finally, and lock).<\/p>\n<pre><code class=\"language-csharp\">public void ResourceLeakExcepHandlingBad() {\r\n    StreamWriter stream = AllocateStreamWriter();\r\n    try\r\n    {\r\n        stream.WriteLine(12);\r\n    }\r\n    catch\r\n    {\r\n        Console.WriteLine(\"Fail to write\");\r\n    }\r\n    finally\r\n    {\r\n        \/\/ FIXME: should close the stream by calling stream.Close().\r\n    }\r\n}<\/code><\/pre>\n<pre><code class=\"language-text\">\/...\/Examples\/Program.cs:39: error: Dotnet Resource Leak\r\n  Leaked { %0 -&gt; 1 } resource(s) at type(s) System.IO.StreamWriter.<\/code><\/pre>\n<h2>Using Infer#<\/h2>\n<p>You can find the instructions for all supported scenarios on our <a href=\"https:\/\/github.com\/microsoft\/infersharp#infersharp\">GitHub landing page<\/a>.<\/p>\n<p>Please submit your feedback and feature requests to our <a href=\"https:\/\/github.com\/microsoft\/infersharp\/issues\">GitHub repository<\/a>. We&#8217;re looking at all feature requests from the community and will prioritize next steps based on popularity.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Infer# v1.2 brings the first interprocedural race condition detection to .NET. Use it today locally in Windows via WSL2 or directly in continuous integration via Azure Pipelines or GitHub Actions.<\/p>\n","protected":false},"author":45721,"featured_media":37492,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,196,7219],"tags":[],"class_list":["post-37491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-dotnet-core","category-static-analysis"],"acf":[],"blog_post_summary":"<p>Infer# v1.2 brings the first interprocedural race condition detection to .NET. Use it today locally in Windows via WSL2 or directly in continuous integration via Azure Pipelines or GitHub Actions.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/37491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/45721"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=37491"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/37491\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/37492"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=37491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=37491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=37491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}