ptunit: destroy only initialized test fixtures
Do not call a fixture's destructor if initialization failed.
This avoids issues with destroying not-yet-initialized fields. We rather leak
already-initialized fields. The initializer is really expected to destroy those
before reporting the fail. But that doesn't really matter for our tests.
Change-Id: I5bb1af5e50a4f7a42576d7d1bf4a0af22ee1e885
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
diff --git a/ptunit/include/ptunit.h b/ptunit/include/ptunit.h
index 40994e3..7f0023d 100644
--- a/ptunit/include/ptunit.h
+++ b/ptunit/include/ptunit.h
@@ -356,14 +356,15 @@
if ((F)->init) \
*pr = (F)->init(F); \
\
- if (pr->type == ptur_passed) \
+ if (pr->type == ptur_passed) { \
*pr = (T)(__VA_ARGS__); \
\
- if ((F)->fini) { \
- if (pr->type == ptur_passed) \
- *pr = (F)->fini(F); \
- else \
- (void) (F)->fini(F); \
+ if ((F)->fini) { \
+ if (pr->type == ptur_passed) \
+ *pr = (F)->fini(F); \
+ else \
+ (void) (F)->fini(F); \
+ } \
} \
} while (0)