SSL_CTX_FREE(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… SSL_CTX_FREE (3ossl) β€” the cleanup era

okay so bestie, welcome to the 3ossl girlies' corner of the manual. today's main character is SSL_CTX_free, and yes she's the one who does the ✨cleanup✨ so your program doesn't leak memory like a sad little faucet. let's get into it 🫢


✨ NAME ✨

SSL_CTX_free β€” frees an allocated SSL_CTX object. literally her whole job. no cap. πŸŽ€

✨ SYNOPSIS ✨

#include <openssl/ssl.h>

void SSL_CTX_free(SSL_CTX *ctx);

✨ DESCRIPTION ✨

okay so here's the tea πŸ“: SSL_CTX_free() decrements the reference count of ctx, and then β€” if that reference count has reached 0 β€” it removes the SSL_CTX object that ctx points to and frees up all the allocated memory. it's giving "last one out turns off the lights" πŸ’‘πŸ’…

and she's thorough, bestie. she also calls the free-ing procedures for the indirectly affected items, if applicable:

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

oh and if ctx is NULL? nothing happens. she's like "k bye" and moves on πŸ™ˆ zero drama, we love that for her.

🚨 WARNINGS 🚨 (read this part fr fr)

so if a session-remove callback is set (hello, SSL_CTX_sess_set_remove_cb()), that callback will be called for each session being freed from ctx's session cache. which implies... yeah 😭 all the corresponding sessions from an external session cache get removed as well. the way that's lowkey a plot twist.

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

SSL_CTX_sess_set_remove_cb(ctx, NULL)

prior to calling SSL_CTX_free(). do it before, bestie. timing matters. β°πŸ’€

✨ RETURN VALUES ✨

SSL_CTX_free() does not provide diagnostic information. she returns nothing and she doesn't explain herself. mysterious. iconic. void energy. πŸ–€

πŸ‘€ SEE ALSO πŸ‘€

go read those too, iykyk πŸ’–

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 drop is from 3.5.0, dated 2026-09-25, and it's the SSL_CTX_FREE(3ossl) manual β€” now go free that context and live your best leak-free life πŸ¦‹πŸ’œβœ¨

πŸ“¦ where this page comes from