SSL_CTX_FREE(3ossl)

πŸ’– SSL_CTX_FREE(3ossl) πŸ’–

okay bestie, welcome to the OpenSSL manual, page SSL_CTX_FREE(3ossl). yes that's the real name, we're not doing a rebrand, we're just making it cute. this one is about saying bye-bye to your SSL_CTX and not leaking memory like it's a broken water bottle in your tote bag πŸŽ€


✨ NAME ✨

SSL_CTX_free β€” free an allocated SSL_CTX object. that's it. that's the whole job. she's a closer πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

void SSL_CTX_free(SSL_CTX *ctx);

look at her. two lines. no return value. no drama. iconic behavior honestly πŸ¦‹


🫢 DESCRIPTION 🫢

so like, SSL_CTX_free() decrements the reference count of ctx, and if that reference count has hit 0, she removes the SSL_CTX object that ctx points to and frees up all that allocated memory. girl math: refcount goes down, memory gets released, we all move on ✨

and she's not just ghosting the main object either β€” she also calls the free()ing procedures for the indirectly affected items, if applicable. which means:

  • the session cache πŸ—‚οΈ
  • the list of ciphers πŸ”
  • the list of Client CAs πŸ‘‘
  • the certificates and keys πŸ—οΈ

all of them get their little goodbye moment. she's thorough. she does not leave things hanging, no cap.

and if ctx is NULL? nothing is done. zero. nada. she just looks at it and goes "ok bestie, noted" and moves on πŸ™ˆ


πŸ’€ WARNINGS πŸ’€

okay this is the part where we sit down and pay attention, fr fr.

If a session-remove callback is set β€” that's SSL_CTX_sess_set_remove_cb() β€” then that callback will be called for each session being freed from ctx's session cache.

which implies... (and I need you to hear me on this) all corresponding sessions from an external session cache are removed as well. 😭 like, the whole friend group gets kicked out of the group chat, not just the one who started the drama.

If that is not what you want, the user should explicitly unset the callback by calling:

SSL_CTX_sess_set_remove_cb(ctx, NULL)

prior to calling SSL_CTX_free(). order matters, babe. unset first, then free. do not do it backwards, I am begging 🫢

lowkey this is the main character twist of the whole page. read it twice. πŸ”₯

⭐ RETURN VALUES ⭐

SSL_CTX_free() does not provide diagnostic information.

that's a fancy way of saying she returns nothing and tells you nothing. void. silent. mysterious. she's giving ✨enigmatic✨. don't go looking for an error code, there isn't one, and that's by design πŸ’…


🌈 SEE ALSO 🌈

go read SSL_CTX_new(3) next if you wanna know how she got here in the first place. it's giving prequel energy πŸ‘‘


Copyright 2000-2016 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 πŸŽ€ this was OpenSSL 3.5.9, dated 2026-09-29, and she ate. free your SSL_CTXs, unset your callbacks first, and hydrate πŸ’œπŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from