title: SIGABRT in malloc.c, what just happened?
body: <p>I wrote this innocent piece of code, and results in such an evil error:</p>
  
  <pre><code>static char * prefixed( char * pref, char *str ) {
      size_t newalloc_size = sizeof(char) * (strlen(pref) + strlen(str));
      char * result = (char*) malloc( newalloc_size );
      [...]
  </code></pre>
  
  <p>output from debug (cgdb):</p>
  
  <pre><code>Breakpoint 1, prefixed (pref=0x401345 "Env: ", str=0x4012b5 "Home") at ./src/backend/os/env.c:77
  (gdb) s
  (gdb) p newalloc_size 
  $1 = 9
  (gdb) s
  envtest: malloc.c:2368: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &amp;((av)-&gt;bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &amp;&amp; old_size == 0) || ((unsigned long) (old_size) &gt;=
  (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) &amp; ~((2 * (sizeof(size_t))) - 1))) &amp;&amp; ((old_top)-&gt;size &amp; 0x1) &amp;&amp; ((unsigned long)old_end &amp; pagemask) == 0)'
  failed.
  
  Program received signal SIGABRT, Aborted.
  0x00007ffff7a68fd5 in raise () from /usr/lib/libc.so.6
  (gdb)  
  </code></pre>
  
  <p>I checked the passed arguments, too. They where just as they are supposed to be:</p>
  
  <pre><code>Breakpoint 1, prefixed (pref=0x401345 "Env: ", str=0x4012b5 "Home") at ./src/backend/os/env.c:77
  (gdb) p pref
  $2 = 0x401345 "Env: "
  (gdb) p strlen(pref)
  $3 = 5
  (gdb) p str
  $4 = 0x4012b5 "Home"
  (gdb) p strlen(str)
  $5 = 4
  (gdb) 
  </code></pre>
  
  <p>can anybody imagine, what goes wrong here? I know there are functions to cat two strings together, but I want to do it on my own!</p>
  
  <p>kind regards.</p>