Skip to content

Commit a2906fe

Browse files
Add qvi_delete(). (#87)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 2881434 commit a2906fe

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/qvi-hwpool.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,7 @@ void
239239
qvi_hwpool_free(
240240
qvi_hwpool_t **rpool
241241
) {
242-
if (!rpool) return;
243-
qvi_hwpool_t *irpool = *rpool;
244-
if (!irpool) goto out;
245-
delete irpool;
246-
out:
247-
*rpool = nullptr;
242+
qvi_delete(rpool);
248243
}
249244

250245
int

src/qvi-utils.h

+16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121

2222
#ifdef __cplusplus
2323

24+
/**
25+
* Simple wrapper around delete that also nullifies the input pointer.
26+
*/
27+
template <class T>
28+
void
29+
qvi_delete(
30+
T **t
31+
) {
32+
if (!t) return;
33+
T *it = *t;
34+
if (!it) goto out;
35+
delete it;
36+
out:
37+
*t = nullptr;
38+
}
39+
2440
/**
2541
* Returns the code captured by a constructor. Since we are trying to avoid the
2642
* use of exceptions, we instead use this method for checking the state of an

0 commit comments

Comments
 (0)