BIO_NEW(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… BIO_NEW πŸ’…

okay bestie, so this is the OpenSSL 3ossl page for BIO_new_ex, BIO_new, BIO_up_ref, BIO_free, BIO_vfree and BIO_free_all β€” literally all the BIO allocation and freeing functions, together, in one page. 🫢


✨ NAME ✨

BIO_new_ex, BIO_new, BIO_up_ref, BIO_free, BIO_vfree, BIO_free_all β€” the BIO allocation and freeing functions. that's the whole vibe: making BIOs, keeping them alive, and letting them go πŸ˜­πŸ’œ


🌸 SYNOPSIS 🌸

#include <openssl/bio.h>

BIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *type);
BIO *BIO_new(const BIO_METHOD *type);
int BIO_up_ref(BIO *a);
int BIO_free(BIO *a);
void BIO_vfree(BIO *a);
void BIO_free_all(BIO *a);

πŸ¦‹ DESCRIPTION πŸ¦‹

so BIO_new_ex() hands you a brand new BIO using the method type, and it's tied to the library context libctx (go peek at OSSL_LIB_CTX(3) for the deets). you can pass NULL for the library context and it'll just mean the default library context, no biggie. but type? MUST NOT be NULL, like ever, that's a hard no πŸ™…β€β™€οΈ

BIO_new() is literally the same thing as BIO_new_ex() except the default library context is always used. that's it, that's the difference. slay ✨

BIO_up_ref() bumps up the reference count on the BIO object β€” keeping it alive longer, main character energy πŸ‘‘

BIO_free() frees up a single BIO, and BIO_vfree() also frees up a single BIO but it doesn't return a value (it's the quiet one 🀫). if a is NULL, nothing happens, no drama. also lowkey important: calling BIO_free() may have some effect on the underlying I/O structure too β€” for example, under certain circumstances it may close the file being referred to 😳 for more details, go read the individual BIO_METHOD descriptions, iykyk.

BIO_free_all() frees up an entire BIO chain, and it does not halt if an error occurs while freeing up an individual BIO in the chain β€” it just keeps going, unbothered, resilient queen πŸ’… if a is NULL, nothing is done.


πŸ’– RETURN VALUES πŸ’–

  • BIO_new_ex() and BIO_new() return a newly created BIO, or NULL if the call fails 😭
  • BIO_up_ref() and BIO_free() return 1 for success and 0 for failure βœ…
  • BIO_free_all() and BIO_vfree() do not return values, they're above that πŸŽ€

⚠️ NOTES ⚠️

bestie please listen: if you call BIO_free() on a BIO chain, it will only free one BIO, which results in a memory leak πŸ’€ don't do that to yourself.

calling BIO_free_all() on a single BIO has the same effect as calling BIO_free() on it β€” other than the discarded return value. same energy, different function 🫢


🌈 HISTORY 🌈

  • BIO_set() was removed in OpenSSL 1.1.0 because the BIO type is now opaque. gone, retired, iconic but over ✨
  • BIO_new_ex() was added in OpenSSL 3.0, our newer fave πŸŽ€

πŸ“ EXAMPLES πŸ“

create a memory BIO, easy:

BIO *mem = BIO_new(BIO_s_mem());

Copyright 2000-2021 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.6, dated 2026-04-07 β€” go forth and allocate responsibly πŸ’œπŸŒΈ

πŸ“¦ where this page comes from