Fix Use After Free.
Ported from 1.5.x: 690d68e9789f33024514504279496f019f48d322

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