title: Memory leak after using calloc and free?
body: <p>I tested my software with "valgrind --leak-check=full", and it shows:</p>
  
  <pre><code>==90862== 7,627 bytes in 4 blocks are definitely lost in loss record 858 of 897
  ==90862==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==90862==    by 0xD64991C: concat(int, ...) (Client.cpp:150)
  </code></pre>
  
  <p>I can't understand why, because I use free() after calloc.
  Here's my code:</p>
  
  <pre><code>char* p = concat(2, buffOld, buff);
  char *x;
      while(true) {
          x = p;
          p = strstr(p,"\\final\\");
          if(p == NULL) { break; }
          *p = 0;
          p+=7;
          parseIncoming((char *)x,strlen(x));
      }
  free(p);
  </code></pre>
  
  <p>And the "concat" function:</p>
  
  <pre><code>char* concat(int count, ...)
  {
      va_list ap;
      int i;
  
      // Find required length to store merged string
      int len = 1; // room for NULL
      va_start(ap, count);
      for(i=0 ; i&lt;count ; i++)
          len += strlen(va_arg(ap, char*));
      va_end(ap);
  
      // Allocate memory to concat strings
      char *merged = (char*)calloc(sizeof(char),len);
      int null_pos = 0;
  
      // Actually concatenate strings
      va_start(ap, count);
      for(i=0 ; i&lt;count ; i++)
      {
          char *s = va_arg(ap, char*);
          strcpy(merged+null_pos, s);
          null_pos += strlen(s);
      }
      va_end(ap);
  
      return merged;
  }
  </code></pre>
  
  <p>What I do wrong?</p>