Fixed leak when reading function