Previous fix (1.12) would cause a NULL pointer dereference in the error path
if a NULL stack was passed as argument. Fix this by returning NULL early in
that case.