title: How to find memory leaks with Clang
body: <p>I have installed Clang in my machine (ubuntu) in order to find memory leaks in my C code. I wrote a sample code in order to check the working of it which is as follows:</p>
  
  <pre><code>/* File: hello.c for leak detection */
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void *x;
  
  int main() {
    x = malloc(2);
    x = 0; // Memory leak
    return 0;
  }
  </code></pre>
  
  <p>I found some options in internet to compile like</p>
  
  <pre><code>$ scan-build clang --analyze hello.c
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$ scan-build clang -fsanitize=address hello.c
  </code></pre>
  
  <p>But none of them are showing any signs of memory leak.</p>
  
  <blockquote>
    <p>scan-build: Using '/usr/bin/clang' for static analysis<br> scan-build:
    Removing directory '/tmp/scan-build-2015-07-02-122717-16928-1' because
    it contains no reports.<br> scan-build: No bugs found.</p>
  </blockquote>
  
  <p>Can anyone kindly tell how to correctly use Clang for Memory leak detection.</p>