Fix memory corruption issues

Uncovered by: Electric Fence

sudo apt-get install electric-fence
cc -g -O sgsh-tee.c -o sgsh-tee  -lefence

rm -f try try2
mkfifo try try2
perl -e 'for ($i = 0; $i < 500; $i++) { print "x" x 500, "\n"}' >lines
cat try2 >try2.out &
{ read x ; echo $x ; sleep 1 ; cat ; } < try > try.out &
EF_PROTECT_FREE=1 gdb --args ./sgsh-tee -f -b 512 -m 2k -o try -o try2 -i lines