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) {