title: Free dynamically alloted memory to struct array containing pointer
body: <p>I have three files</p>
  <pre><code>struct.h  struct.c main.c
  </code></pre>
  <p>struct.h contains declaration of structs and some functions<br />
  struct.c contains global variable <code>bglobal</code> an instance of <code>struct b</code> and function implementations which use <code>bglobal</code>. It includes .h file<br />
  main.c call some of the functions declared in struct.h. It also includes .h file<br />
  struct.h contains two struct</p>
  <pre><code>struct a{
  int *s
  }
  struct b{
  struct a* arr
  }
  void init();
  void more();
  </code></pre>
  <p>struct.c file</p>
  <pre><code>#include&quot;struct.h&quot;
  struct b bglobal;
  void init(){
     bglobal.arr = malloc(sizeof(struct a)*5);
  }
  void more(){
     *bglobal.arr[0].name = 'I';
  }
  
  </code></pre>
  <p>main.c file</p>
  <pre><code>#include &quot;main.h&quot;
  int main(){
  init();
  more();
  }
  </code></pre>
  <p>I want that at end of program memory allocated to <code>bglobal.arr</code> get freed up.
  Using valgrind it says some bytes still reachable.
  How to achieve this?</p>