ARES_LIBRARY_CLEANUP(3)

πŸ“¦
version 1.34.9 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– ARES_LIBRARY_CLEANUP(3) πŸ’–

okay bestie, welcome to the Library Functions Manual, section 3, and today's main character is ares_library_cleanup β€” the goodbye-girl of the c-ares universe 🫢


✨ NAME ✨

ares_library_cleanup β€” c-ares library deinitialization. it's the breakup text, but for a library 🌸


✨ SYNOPSIS ✨

#include <ares.h>

void ares_library_cleanup(void)

like, that's it. no args, no return value, no drama (well… some drama, keep reading 😭)


✨ DESCRIPTION ✨

so the way that ares_library_cleanup works is: it uninitializes the c-ares library and frees all the resources that ares_library_init(3) grabbed earlier when the library got initialized β€” but ONLY if there was just one single previous call to ares_library_init(3). one and done, no cap πŸ’…

if there was more than one previous call to ares_library_init(3), then this function uninitializes the c-ares library only if it's the call matching the call to ares_library_init(3) which initialized the library (usually the very first call to ares_library_init(3), iykyk). other calls to ares_library_cleanup(3) have no effect other than decrementing an internal counter. literally just vibes and a number going down πŸ“‰

you must call this function when the program using c-ares will no longer need any c-ares function. once the program has called ares_library_cleanup(3) sufficiently often that the library is uninitialised, it shall not make any further call to any c-ares function. periodt. 🚫

bestie this one's important: this function does not cancel any pending c-ares lookups or requests you did earlier. the program must use ares_cancel(3) for that purpose. different job, different girlie πŸ’…

this function is not thread safe 😭 you have to call it once the program is about to terminate, but this call must be done once the program has terminated every single thread that it could have initiated. why?? to avoid potential race conditions in library deinitialization, and also because ares_library_cleanup(3) might call functions from other libraries that are thread unsafe, and could conflict with any other thread that is already using these other libraries. so like… everyone out of the pool first πŸŠβ™€οΈ

πŸ¦‹ Win32/64 alert: application DLLs shall not call ares_library_cleanup(3) from the DllMain function. doing so will produce deadlocks and other problems. not the cute kind of deadlock. πŸ’€

✨ AVAILABILITY ✨

this function was first introduced in c-ares version 1.7.0, along with the definition of preprocessor symbol CARES_HAVE_ARES_LIBRARY_CLEANUP as an indication of the availability of this function. iconic behavior honestly πŸ‘‘

reference counting in ares_library_init(3) and ares_library_cleanup(3) β€” which requires calls to the former function to match calls to the latter β€” is present since c-ares version 1.10.0. earlier versions would deinitialize the library on the first call to ares_library_cleanup(3). different era, different rules 🌈

since the introduction of this function, it is absolutely mandatory to call it for any Win32/64 program using c-ares. mandatory mandatory. like, no skipping 🫢

non-Win32/64 systems can still use c-ares version 1.7.0 without calling ares_library_cleanup(3), due to the fact that currently it is nearly a do-nothing function on non-Win32/64 platforms. so it's giving… decorative ✨


✨ SEE ALSO ✨

go read those too, they're the supporting cast and they ate πŸ’–


and that's the whole page bestie!! this little masterpiece is dated 19 May 2009, and it lives in the Library Functions Manual β€” go forth and clean up responsibly, mwah πŸŽ€πŸ’œ

πŸ“¦ where this page comes from