title: Want to Know About Different Scenario of Memory Leaks
body: <p>I am just curious about how memory leaks happens when you write a C program.</p>
  
  <p>Are the following are examples of memory leaks?</p>
  
  <ol>
  <li>Trying to access the part of the memory whose access is not given to your program or when you are trying to access the location of the array which is not there.</li>
  </ol>
  
  <hr>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
       int num[5];
  
       int i;
  
        for(i=0;i&lt;5;i++)
             scanf("%d", (num+i));
  
     printf("%d\n", num[5]); //printing the data stored at loc num[5] which is not present.
  
        return 0;
  }
  </code></pre>
  
  <ol start="2">
  <li><p>Printing the value stored in an un-initialized variables.</p></li>
  <li><p>Use of <code>void*memcpy(const*dst,void const*src,size_t n)</code> function memory leak occurs when <code>src</code> and <code>dst</code> pointers points to the same memory address or function is undefined when addresses overlaps.</p></li>
  <li><p>Use of <code>free()</code> more than once on the same pointers which has been freed already. For Example:</p></li>
  </ol>
  
  <hr>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
  
      int*num = NULL;
  
      int i;
  
      num = (int*) calloc(sizeof(int), 5);
  
      for (i = 0; i &lt; 5; i++)
          scanf("%d", (num + i));
  
      free(num);
      free(num);
      return 0;
  }
  </code></pre>