it looks like you should be doing a close on fp before you return in the error condition.
Also cppcheck noted: [./util.c:436]: (style) Redundant condition. It is safe to deallocate a NULL pointer [./xmalloc.c:87]: (style) Redundant condition. It is safe to deallocate a NULL pointer
These aren't really bugs but just thought I would mention it.