Fix: possible use after free

Fixes coverity issue 1135328 and 1135329

Signed-off-by: David Goulet <dgoulet@efficios.com>