fix bug in template.c
change malloc to calloc
fix bug in malloc