Avoid possible memory leaks in case of exceptions

Change-Id: Iaf672463cf51d596148822d9b5effe5ab40f70d4
Avoid possible memory leaks in case of exceptions

Change-Id: Ia8bc0e24a76dd953000b73806ac21f21db4c4ca3