From 437e26781c6b166f7be71bffaf27d98ae3e6b141 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Tue, 1 Jul 2014 16:38:41 +0100 Subject: [PATCH] mraa: add deinit function for valgrind testing Signed-off-by: Brendan Le Foll --- api/mraa/common.h | 8 ++++++++ examples/hellomraa.c | 1 + src/mraa.c | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/api/mraa/common.h b/api/mraa/common.h index 9f32c13..1e296d8 100644 --- a/api/mraa/common.h +++ b/api/mraa/common.h @@ -186,6 +186,14 @@ mraa_result_t mraa_init() __attribute__((constructor)); mraa_result_t mraa_init(); #endif +/** + * De-Initilise MRAA + * + * This is not a strict requirement but useful to test memory leaks and for + * people who like super clean code. + */ +void mraa_deinit(); + /** * Checks if a pin is able to use the passed in mode. * diff --git a/examples/hellomraa.c b/examples/hellomraa.c index d6748d2..70fff49 100644 --- a/examples/hellomraa.c +++ b/examples/hellomraa.c @@ -30,6 +30,7 @@ int main(int argc, char **argv) { fprintf(stdout, "hello mraa\n Version: %s\n", mraa_get_version()); + mraa_deinit(); return 0; } //! [Interesting] diff --git a/src/mraa.c b/src/mraa.c index 09f3c65..2da9c47 100644 --- a/src/mraa.c +++ b/src/mraa.c @@ -98,6 +98,13 @@ mraa_init() return MRAA_SUCCESS; } +void +mraa_deinit() +{ + free(plat->pins); + free(plat); +} + int mraa_set_priority(const unsigned int priority) {