BIO_NEW(3ossl)
π BIO_NEW β the one where we make and destroy BIOs (3ossl, bestie)
okay so this is the OpenSSL page for BIO_new_ex, BIO_new, BIO_up_ref, BIO_free, BIO_vfree, and BIO_free_all β literally the whole "allocate it and then free it" saga. it's giving birth-and-death cycle but for BIO objects π
β¨ 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);
bestie look at that signature block, it's so clean ππ«Ά
πΈ DESCRIPTION πΈ
the new ones π
BIO_new_ex() hands you a shiny new BIO built with method type, and it's tied to the library context libctx (peep OSSL_LIB_CTX(3) for that whole situation). libctx can be NULL and that just means "default library context, babe, no worries". but type β and I cannot stress this enough β MUST NOT be NULL. no cap. π«
BIO_new() is literally the same thing as BIO_new_ex(), except the default library context is always used. always always. that's the entire diff, iconic behaviour honestly β¨
the refcount one π§
BIO_up_ref() bumps up the reference count hanging out with the BIO object. one more friend in the group chat π―ββοΈ
the free ones π
BIO_free() frees up a single BIO. BIO_vfree() also frees up a single BIO but it doesn't give you a return value back β it's the silent type π. if a is NULL, nothing happens at all, we just move on with our lives.
β οΈ heads up: callingBIO_free()can also do stuff to the underlying I/O structure β like, under certain circumstances it may close the file being referred to π³. for the full tea, check out the individualBIO_METHODdescriptions.
BIO_free_all() frees up a whole entire BIO chain, and it does not halt if an error happens while freeing up an individual BIO in the chain. it keeps going, main character energy, nothing stops her π
. if a is NULL, nothing is done.
β RETURN VALUES β
BIO_new_ex()andBIO_new()β return a newly created BIO, orNULLif the call fails πBIO_up_ref()andBIO_free()β return1for success and0for failureBIO_free_all()andBIO_vfree()β don't return values, they simply do not participate in the return-value economy π ββοΈ
π¦ NOTES π¦
- if you call
BIO_free()on a BIO chain, it will only free one BIO, which results in a memory leak π¬ bestie don't do it, that's the leaky behaviour. - calling
BIO_free_all()on a single BIO has the same effect as callingBIO_free()on it β except the return value gets yeeted into the void.
π HISTORY π
BIO_set()was removed in OpenSSL 1.1.0, because the BIO type is opaque now. gone, girl, gone.BIO_new_ex()was added in OpenSSL 3.0 β the new kid on the block, and we love her π
π₯ EXAMPLES π₯
so like, if you wanna create a memory BIO, it's literally this:
BIO *mem = BIO_new(BIO_s_mem());
that's it. that's the whole vibe. go off β¨
π COPYRIGHT π
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 BIO_NEW(3ossl) from OpenSSL 3.5.0, dated 2026-09-25. mwah, go free your BIOs responsibly ππ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms