
Indeed, when virDomainCreate() < 0, virDispatchError() should be invoked, but since we do not check its return value, there is no absolute guarantee that the error message will always be set successfully. virDispatchError() contains the following code: virErrorPtr err = virLastErrorObject(); /* Can only happen on OOM. */ if (!err) return; The comment clearly indicates that virLastErrorObject() may return NULL in case of OOM. Moreover, even if the call err = g_new0(virError, 1); succeeds, this does not guarantee that virThreadLocalSet(&virLastErr, err) < 0 will always false. For example, for large values of l->key, an additional memory allocation may occur, and if that allocation fails, g_clear_pointer(&err, g_free) will be executed, causing virLastErrorObject() to return NULL. Although this situation is extremely unlikely, it is better to add an explicit NULL check.