Ignoring your problems with malloc(), you're reading to the end of the file, and then reading some more.