SSL_FREE(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸŽ€ SSL_FREE(3) πŸŽ€

okay so this is a page from the Library Functions Manual bestie, and it's literally all about SSL_free β€” the little cleanup queen of libssl. she's iconic, she's necessary, and if you ignore her you WILL leak memory. iykyk πŸ’…


✨ NAME ✨

SSL_free β€” free an allocated SSL structure πŸ¦‹ (yes that's it, that's the whole job, and she does it flawlessly)


✨ SYNOPSIS ✨

so you're gonna need libssl and libcrypto, and you include this:

#include <openssl/ssl.h>

void
SSL_free(SSL *ssl);

that's her. one function. one pointer. no cap. 🫢


πŸ’– DESCRIPTION πŸ’–

okay so here's the tea, bestie 🌸 β€” SSL_free() decrements the reference count of ssl, and then actually removes the SSL structure pointed to by ssl and frees up the allocated memory β€” but ONLY once the reference count has reached 0. like she's not gonna just nuke it while other people are still using it, that would be rude.

and if ssl is a NULL pointer? no action occurs. literally nothing. she just vibes. ✨

now here's the part where it gets kinda extra β€” SSL_free() ALSO calls the free(3)-ing procedures for all the indirectly affected items, if applicable πŸ‘‘:

  • the buffering BIO
  • the read and write BIOs
  • the cipher lists specially created for this ssl
  • the SSL_SESSION
⚠️ and this is the important bit, do NOT come for these, bestie β€” do not explicitly free these indirectly freed up items before or after calling SSL_free(). because trying to free things twice may lead to program failure. and not the cute kind of failure. the segfault kind. πŸ’€πŸ˜­

also, the ssl session has reference counts from two users, keep up πŸ”₯:

  1. the SSL object β€” for which the reference count is removed by SSL_free()
  2. the internal session cache

and here's a fun little rule: if the session is considered bad β€” because SSL_shutdown(3) was not called for the connection AND SSL_set_shutdown(3) was not used to set the SSL_SENT_SHUTDOWN state β€” then the session will also be removed from the session cache as required by RFC 2246. yes, RFC 2246. she read the docs so you don't have to. ⭐


🌈 SEE ALSO 🌈

go read those too, they're giving main character energy πŸ§šπŸ’œ


πŸŽ€ HISTORY πŸŽ€

SSL_free() appeared in SSLeay 0.4 or earlier and has been available since OpenBSD 2.4. she's been here since basically forever and she's still slaying. periodt. πŸ‘‘


and that's the whole page diva! πŸ“ this gem came from Debian, dated June 8, 2025 β€” mwah, go free your SSL structs responsibly πŸ’–βœ¨

πŸ“¦ where this page comes from