fixed a memory free bug due to uninitialised values