OSSL_ERR_STATE_SAVE(3ossl)

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

πŸ’… OSSL_ERR_STATE_SAVE β€” saving and restoring error state ✨

okay so bestie, this is the 3ossl manual page for the OpenSSL error-state save/restore girlies πŸŽ€. If you've ever wanted to scoop up your thread's error state, tuck it into a little preallocated ERR_STATE box, and put it back later β€” this is your moment. no cap. 🫢


🌸 SYNOPSIS 🌸

#include <openssl/err.h>

ERR_STATE *OSSL_ERR_STATE_new(void);
void OSSL_ERR_STATE_save(ERR_STATE *es);
void OSSL_ERR_STATE_save_to_mark(ERR_STATE *es);
void OSSL_ERR_STATE_restore(const ERR_STATE *es);
void OSSL_ERR_STATE_free(ERR_STATE *es);

✨ DESCRIPTION ✨

These functions save and restore the error state, moving it from the thread local error state into a preallocated error state structure πŸ’–. It's giving "pack up your emotional baggage and label it" energy. 🧳

  • OSSL_ERR_STATE_new() β€” allocates an empty error state structure, so you have somewhere cute to put things when you're saving and restoring thread error state. πŸŽ€
  • OSSL_ERR_STATE_save() β€” saves the thread error state into es. Then it clears the thread error state, like, immediately. Any state that was previously saved in es gets cleared first, before the new state goes in. out with the old, in with the new, periodt. πŸ’…
  • OSSL_ERR_STATE_save_to_mark() β€” same vibe as OSSL_ERR_STATE_save(), except it only saves ERR entries up to the most recent mark on the ERR stack ✨. Those entries get moved to es and removed from the thread error state. BUT β€” and this is the plot twist 😭 β€” the most recent marked ERR, plus any ERR state before it, stays part of the thread error state. it does not get moved to the ERR_STATE. And the mark is not cleared! you have to clear it explicitly after calling this function, using ERR_pop_to_mark(3) or ERR_clear_last_mark(3). and here's the fun part: since a call to OSSL_ERR_STATE_save_to_mark() leaves the marked ERR as the top error, either of those functions will have the exact same effect. iykyk. πŸ¦‹
also, if there's no marked ERR in the thread local error state, all ERR entries are copied and the effect is the same as a call to OSSL_ERR_STATE_save(). so, like, no drama either way. πŸ“
  • OSSL_ERR_STATE_restore() β€” adds all the error entries from the saved state es back into the thread error state 🌈. Existing entries in the thread error state are not affected, as long as there's enough space for all the added entries. Any allocated data in the saved error entries gets duplicated when it's added to the thread state. bespoke copies, no sharing. πŸ‘‘
  • OSSL_ERR_STATE_free() β€” frees the saved error state es πŸŽ€. If the argument is NULL, nothing happens. iconic minimalism, honestly. ✨

πŸ’– RETURN VALUES πŸ’–

  • OSSL_ERR_STATE_new() returns a pointer to the allocated ERR_STATE structure, or NULL on error 😭.
  • OSSL_ERR_STATE_save(), OSSL_ERR_STATE_save_to_mark(), OSSL_ERR_STATE_restore(), and OSSL_ERR_STATE_free() do not return any values. they simply are. πŸ’…

πŸ¦‹ NOTES πŸ¦‹

OSSL_ERR_STATE_save() and OSSL_ERR_STATE_save_to_mark() cannot fail, because they take over any allocated data from the thread error state. so, like, no failure arc here. ⭐

OSSL_ERR_STATE_restore() is a best effort function 🫢. The only failure that can happen during its operation is when memory allocation fails. Because it manipulates the thread error state, it avoids raising memory errors on such failure. At worst, the restored error entries will be missing the auxiliary error data. not the end of the world, bestie. πŸ’œ


🌈 SEE ALSO 🌈

ERR_raise(3), ERR_get_error(3), ERR_clear_error(3)


πŸ‘‘ HISTORY πŸ‘‘

All of these functions were added in OpenSSL 3.2 ✨. they're new-ish, they're fresh, they ate. πŸ”₯


Copyright 2023-2024 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>.


mwah πŸ’‹ this page is from OpenSSL 3.5.0, dated 2026-09-25. go save your error state, bestie β€” OSSL_ERR_STATE_SAVE(3ossl) out. πŸŒΈπŸ’…βœ¨
πŸ“¦ where this page comes from