fix fread buffer has no terminating null string

do not allocate memory where it is not needed

Change-Id: I8ab4f7d36173c59aa74a590581a0f7027b7d8a69