BIO_NEW(3ossl)
π 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()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 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 π
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
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms