diff --git a/src/qvi-hwpool.cc b/src/qvi-hwpool.cc index 36fe1819..5b09b969 100644 --- a/src/qvi-hwpool.cc +++ b/src/qvi-hwpool.cc @@ -239,12 +239,7 @@ void qvi_hwpool_free( qvi_hwpool_t **rpool ) { - if (!rpool) return; - qvi_hwpool_t *irpool = *rpool; - if (!irpool) goto out; - delete irpool; -out: - *rpool = nullptr; + qvi_delete(rpool); } int diff --git a/src/qvi-utils.h b/src/qvi-utils.h index fb618313..2d240f04 100644 --- a/src/qvi-utils.h +++ b/src/qvi-utils.h @@ -21,6 +21,22 @@ #ifdef __cplusplus +/** + * Simple wrapper around delete that also nullifies the input pointer. + */ +template +void +qvi_delete( + T **t +) { + if (!t) return; + T *it = *t; + if (!it) goto out; + delete it; +out: + *t = nullptr; +} + /** * Returns the code captured by a constructor. Since we are trying to avoid the * use of exceptions, we instead use this method for checking the state of an