void print( unsigned char *buffer, int bytes ) { int i; unsigned char *toSend = malloc( 3*bytes ); for( i = 0; i < bytes; i++ ) sprintf(toSend+3*i,"%02X ", buffer[i]); toSend[3*i-1] = '\0'; post_webservice( toSend, hname ); free( toSend ); return; } Here's what valgrind sais: Invalid write of size 1 ==31227== at 0x408F4DB: _IO_default_xsputn (in /lib/tls/i686/cmov/libc-2.3.6.so) ==31227== by 0x406AA76: vfprintf (in /lib/tls/i686/cmov/libc-2.3.6.so) ==31227== by 0x408541A: vsprintf (in /lib/tls/i686/cmov/libc-2.3.6.so) ==31227== by 0x407276A: sprintf (in /lib/tls/i686/cmov/libc-2.3.6.so) ==31227== by 0x80489D9: print (in /home/xarcson/wetter/a.out) ==31227== by 0x8048BD3: parseBuffer (in /home/xarcson/wetter/a.out) ==31227== by 0x8048BFB: processBuffer (in /home/xarcson/wetter/a.out) ==31227== by 0x8048D76: main (in /home/xarcson/wetter/a.out) ==31227== Address 0x41618A7 is 1 bytes after a block of size 46 alloc'd ==31227== at 0x401C422: malloc (vg_replace_malloc.c:149) ==31227== by 0x80489A1: print (in /home/xarcson/wetter/a.out) ==31227== by 0x8048BD3: parseBuffer (in /home/xarcson/wetter/a.out) ==31227== by 0x8048BFB: processBuffer (in /home/xarcson/wetter/a.out) ==31227== by 0x8048D76: main (in /home/xarcson/wetter/a.out)