BIO_NEW(3SSL)
π BIO_NEW(3SSL) β okay bestie, let's talk BIO allocation π
Hi hi!! So this is the BIO_NEW(3SSL) page from the OpenSSL fam, and it's literally all about making BIOs and β¨letting them goβ¨. Allocation and freeing, the whole circle of life. Grab a snack, we're doing this.
πΈ NAME πΈ
BIO_new_ex, BIO_new, BIO_up_ref, BIO_free, BIO_vfree, BIO_free_all β the BIO allocation and freeing girlies. Making them, keeping them alive, and saying goodbye.
π 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 β¨
BIO_new_ex() hands you a brand new BIO using method type, associated with the library context libctx (peep OSSL_LIB_CTX(3) for the tea on that). You can pass NULL for the library context if you want to mean the default library context. But type? type MUST NOT be NULL. Like, don't even try it bestie.
BIO_new() is the exact same thing as BIO_new_ex() except it always uses the default library context. Periodt. π
BIO_up_ref() bumps the reference count on the BIO object. Keeping it alive, keeping it iconic. π
BIO_free() frees up a single BIO. BIO_vfree() also frees up a single BIO, it's just built different β it doesn't return a value. If a is NULL, nothing happens, no drama. Heads up though: calling BIO_free() might also have some effect on the underlying I/O structure β it could, under certain circumstances, close the file being referred to. For the full breakdown, go read the individual BIO_METHOD descriptions. π¦
BIO_free_all() frees up an entire BIO chain. And here's the thing β it does not halt if an error occurs freeing up an individual BIO in the chain. It just keeps going. Also: 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 failure.BIO_free_all()andBIO_vfree()do not return values. They're void, they said no to giving you answers.
π₯ NOTES π₯
If BIO_free() is called on a BIO chain it will only free one BIO β resulting in a memory leak. Not cute. Not slay. Please be careful.
Calling BIO_free_all() on a single BIO has the same effect as calling BIO_free() on it, the only difference being the discarded return value.
π HISTORY π
BIO_set() was removed in OpenSSL 1.1.0 because BIO type is now opaque. RIP to a real one. π
BIO_new_ex() was added in OpenSSL 3.0. New girl on the block, and she ate. β
π EXAMPLES π
Create a memory BIO:
BIO *mem = BIO_new(BIO_s_mem());
π 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 diva was served to you as version 4.0.3, dated 2026-09-29, and yes she is still BIO_NEW(3SSL) at heart π go free your BIOs responsibly!! bye mwah π
π
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms