Fix leak of fd on read error
Module mem