Fix Use after free

Signed-off-by: Srikrishan Malik <srimalik@in.ibm.com>