diff --git a/include/re_main.h b/include/re_main.h index 23b664fa0..c7342afda 100644 --- a/include/re_main.h +++ b/include/re_main.h @@ -42,6 +42,7 @@ struct re_fhs *fd_close(struct re_fhs *fhs); int fd_setsize(int maxfds); int libre_init(void); +void libre_cleanup(void); void libre_close(void); void libre_exception_btrace(bool enable); diff --git a/src/main/init.c b/src/main/init.c index b84012979..04f8ff4a4 100644 --- a/src/main/init.c +++ b/src/main/init.c @@ -168,25 +168,37 @@ int libre_init(void) return err; } + err = re_thread_init(); + if (err) + return err; + #ifdef RE_TRACE_ENABLED - re_trace_init("re_trace.json"); + err = re_trace_init("re_trace.json"); + if (err) + return err; #endif - err = re_thread_init(); - - return err; + return 0; } /** - * Close library and free up all resources + * Cleanup libre resources (call before libre_close() and tmr_debug()) */ -void libre_close(void) +void libre_cleanup(void) { - + re_thread_async_close(); #ifdef RE_TRACE_ENABLED re_trace_close(); #endif +} + + +/** + * Close library and free up all resources + */ +void libre_close(void) +{ (void)fd_setsize(0); net_sock_close(); re_thread_close(); diff --git a/test/main.c b/test/main.c index 62ff47fa4..f9636548a 100644 --- a/test/main.c +++ b/test/main.c @@ -259,7 +259,8 @@ int main(int argc, char *argv[]) } out: - re_thread_async_close(); + + libre_cleanup(); /* Check for open timers */ tmr_debug();