Want to detect reliability and security bugs before they ship? Matthew Jin and Xiaoyu Liu show Infer#, a static analysis tool you can use to validate the correctness of source code without needing to execute it.
That "resource leak" example is NOT a resource leak. Yes, you should have disposed of the stream object, but as written, after the method is finished the GC is free to collect and finalize that object at any point. In a GC language a resource leak only occurs when a reference to an object is held (possibly indirectly) longer than intended, such as with a static reference.