title: clang vs gcc behavioral difference with AddressSanitizer
body: <p>I have a sample code with memory leaks. Though clang displays the leak correctly, I am unable to achieve the same with gcc. gcc version I am using is 4.8.5-39</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  void *p;
  int main() {
    p = malloc(7);
    p = 0; // The memory is leaked here.
    return 0;
  }
  </code></pre>
  
  <p>CLANG:</p>
  
  <pre><code>clang -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
  
  =================================================================
  ==15543==ERROR: LeakSanitizer: detected memory leaks
  
  Direct leak of 7 byte(s) in 1 object(s) allocated from:
      #0 0x465289 in __interceptor_malloc (/u/optest/a.out+0x465289)
      #1 0x47b549 in main /u/optest/memory-leak.c:4
      #2 0x7f773fe14544 in __libc_start_main /usr/src/debug/glibc-2.17-c758a686/csu/../csu/libc-start.c:266
  
  SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).
  </code></pre>
  
  <p>GCC:</p>
  
  <pre><code>gcc -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
  
  </code></pre>
  
  <p>I need to use gcc. Can someone help me understand why gcc isn't behaving like clang and what should I do to make it work.</p>