#1953 memory leak and uninitialised value fixed.

 #1953 memory leak and uninitialised value fixed.
And add 7 more unit test cases.