SSL_FREE(3SSL)

πŸ’– SSL_FREE β€” free an allocated SSL structure πŸ’–

okay bestie, welcome to SSL_free() from the OpenSSL fam β€” it's the 3SSL manual page, and today we're learning how to say goodbye to an SSL structure properly. no dramatic exits, no double-frees, just clean closure. πŸŽ€


✨ NAME ✨

SSL_free β€” free an allocated SSL structure


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

void SSL_free(SSL *ssl);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: SSL_free() decrements the reference count of ssl, and it removes the SSL structure pointed to by ssl and frees up the allocated memory if the reference count has reached 0. like, the structure only truly leaves the group chat when nobody's holding a ref anymore. πŸ’…

and if ssl is NULL? literally nothing happens. nothing is done. it's giving ghosting. πŸ‘»


πŸ’€ NOTES πŸ’€

not me dropping the most important part β€” SSL_free() is not just here for the main character. it also calls the free()ing procedures for indirectly affected items, if applicable:

  • the buffering BIO 🌈
  • the read and write BIOs πŸ“–βœοΈ
  • cipher lists specially created for this ssl πŸ”
  • the SSL_SESSION πŸ—‚οΈ
bestie PLEASE β€” do not explicitly free these indirectly freed up items before or after calling SSL_free(). trying to free things twice may lead to program failure. double-free is not cute, it is a crime scene. 😭

okay so bout the session β€” the ssl session has reference counts from two users: the SSL object, for which the reference count is removed by SSL_free(), and the internal session cache. and 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 RFC2246. the lore is documented, periodt. πŸ‘‘


🧚 QUIC stream tea (when you free a QUIC stream SSL object) 🧚

when you use SSL_free() to free a QUIC stream SSL object, the respective sending and receiving parts of the stream are reset unless those parts have already been concluded normally:

  • If the stream has a sending part (in other words, if it is bidirectional or a locally-initiated unidirectional stream) and that part has not been concluded via a call to SSL_stream_conclude(3) or SSL_stream_reset(3) on the QUIC stream SSL object, a call to SSL_free() automatically resets the sending part of the stream as though SSL_stream_reset(3) were called with a QUIC application error code of 0. bye felicia πŸ‘‹
  • If the stream has a receiving part (in other words, if it is bidirectional or a remotely-initiated unidirectional stream), and the peer has not yet concluded that part of the stream normally (such as via a call to SSL_stream_conclude(3) on its own end), a call to SSL_free() automatically requests the reset of the receiving part of the stream using a QUIC STOP_SENDING frame with a QUIC application error code of 0. Note that as per the QUIC protocol, this will automatically cause the peer to reset that part of the stream in turn (which is its sending part). the drama cascades, iykyk 🌊

A QUIC stream SSL object maintains a reference to a QUIC connection SSL object internally, therefore a QUIC stream SSL object and its parent QUIC connection SSL object can be freed in either order. no "you first", no "no you first" β€” both orders slay. 🫢


πŸ™ˆ RETURN VALUES πŸ™ˆ

SSL_free() does not provide diagnostic information. it's not gonna tell you how it went, it's not gonna text back, it just does the thing. silence is the vibe. πŸŽ€


🌟 SEE ALSO 🌟

SSL_new(3), SSL_clear(3), SSL_shutdown(3), SSL_set_shutdown(3), ssl(7)


Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page bestie, you ATE that documentation. this was OpenSSL 4.0.3, dated 2026-09-29, filed under SSL_FREE(3SSL) β€” now go free your pointers responsibly, mwah πŸ’‹πŸ’–βœ¨

πŸ“¦ where this page comes from