Skip to content

Commit

Permalink
Add qvi_delete(). (#87)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Mar 14, 2024
1 parent 2881434 commit a2906fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/qvi-hwpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/qvi-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@

#ifdef __cplusplus

/**
* Simple wrapper around delete that also nullifies the input pointer.
*/
template <class T>
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
Expand Down

0 comments on commit a2906fe

Please sign in to comment.