Updated patch (see commits) addresses the reported bug without crashes.