From 815926bb8a8c206ce64be33de5c24be6ddcbe6f7 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 21 Jun 2017 14:59:11 -0700 Subject: Expose a library finalizer suitable for atexit(). --- src/nng.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nng.h') diff --git a/src/nng.h b/src/nng.h index 5c1a2322..875bf995 100644 --- a/src/nng.h +++ b/src/nng.h @@ -55,6 +55,16 @@ typedef struct nng_stat nng_stat; // mode. NNG_DECL int nng_open(nng_socket *, uint16_t proto); +// nng_fini is used to terminate the library, freeing certain global resources. +// Its a good idea to call this with atexit() or during application shutdown. +// For most cases, this call is optional, but failure to do so may cause +// memory checkers like valgrind to incorrectly flag memory leaks. Note that +// this particular API is NOT THREADSAFE, and MUST NOT BE CALLED WHILE ANY +// OTHER APIS ARE IN USE. (It is safe however to call other functions such +// as nng_open *after* this function returns, provided that the functions do +// not run concurrently!) +NNG_DECL void nng_fini(void); + // nng_close closes the socket, terminating all activity and // closing any underlying connections and releasing any associated // resources. Memory associated with the socket is freed, so it is an -- cgit v1.2.3-70-g09d2