diff --git a/src/qvi-hwpool.cc b/src/qvi-hwpool.cc index 5b09b969..c95914e0 100644 --- a/src/qvi-hwpool.cc +++ b/src/qvi-hwpool.cc @@ -130,13 +130,7 @@ int qvi_hwpool_new( qvi_hwpool_t **rpool ) { - qvi_hwpool_t *irpool = qvi_new qvi_hwpool_t(); - int rc = qvi_new_rc(irpool); - if (rc != QV_SUCCESS) { - qvi_hwpool_free(&irpool); - } - *rpool = irpool; - return rc; + return qvi_new_rc(rpool); } int diff --git a/src/qvi-utils.h b/src/qvi-utils.h index 2d240f04..a9be015b 100644 --- a/src/qvi-utils.h +++ b/src/qvi-utils.h @@ -53,17 +53,23 @@ qvi_construct_rc( } /** - * Similar to qvi_construct_rc(), but is used also to check the value returned - * by qvi_new. + * Constructs a new object of a given type. *t will be valid if successful, + * nullptr otherwise. Returns QV_SUCCESS if successful. */ template int qvi_new_rc( - const T *const t + T **t ) { - // qvi_new must have returned nullptr. - if (!t) return QV_ERR_OOR; - return t->qvim_rc; + T *it = qvi_new T(); + if (!it) return QV_ERR_OOR; + + const int rc = qvi_construct_rc(*it); + if (rc != QV_SUCCESS) { + qvi_delete(&it); + } + *t = it; + return rc; } #endif