OSSL_ERR_STATE_SAVE(3SSL)

πŸ’– OSSL_ERR_STATE_SAVE πŸ’–

okay bestie, this is the 3SSL manual page from OpenSSL, and it's all about saving and restoring error state. yes, saving your errors like they're little collectible stickers. no cap. πŸŽ€

✨ NAME ✨

OSSL_ERR_STATE_new, OSSL_ERR_STATE_save, OSSL_ERR_STATE_save_to_mark, OSSL_ERR_STATE_restore, OSSL_ERR_STATE_free β€” saving and restoring error state πŸ¦‹


🌸 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 πŸ’…

So basically, these functions take the error state from the thread local error state and stash it into a preallocated error state structure, or put it back. Save and restore. The way that works is so clean.

  • OSSL_ERR_STATE_new() β€” allocates an empty error state structure, the kind you'd use when saving and restoring thread error state. Fresh out the box, literally. ✨
  • OSSL_ERR_STATE_save() β€” saves the thread error state into es. And then it clears the thread error state, because we're moving out, bestie. Any previously saved state in es gets cleared before the new state gets saved in. Out with the old, in with the new. πŸ’–
  • OSSL_ERR_STATE_save_to_mark() β€” same vibe as OSSL_ERR_STATE_save() but it only saves the 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 important part) the most recent marked ERR and anything before it stays part of the thread error state and is not moved to the ERR_STATE. Also the mark is not cleared β€” you have to clear it explicitly yourself after calling this, using ERR_pop_to_mark(3) or ERR_clear_last_mark(3). (since calling OSSL_ERR_STATE_save_to_mark() leaves the marked ERR as the top error, either one of those functions does the same thing, so pick your fighter πŸ’€). If there's no marked ERR in the thread local error state, then all ERR entries get copied and it's exactly the same as calling OSSL_ERR_STATE_save(). periodt.
  • 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 inside the saved error entries gets duplicated when it's added to the thread state. duplicate slay. πŸ‘‘
  • OSSL_ERR_STATE_free() β€” frees the saved error state es. If the argument is NULL, nothing happens. Iconic behaviour honestly, it just minds its business. πŸ™ˆ

🌈 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 ✨ do the thing ✨.

🫢 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. no failure arc for them, they're booked and busy. πŸ”₯
  • OSSL_ERR_STATE_restore() is a best effort function. The only failure that can happen during its operation is when memory allocation fails. And because it's manipulating the thread error state, it avoids raising memory errors on such failure. So at worst? The restored error entries will be missing the auxiliary error data. that's the worst case, bestie, and it's honestly not even that bad. πŸ’œ

⭐ SEE ALSO ⭐

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


πŸŽ€ HISTORY πŸŽ€

All of these functions were added in OpenSSL 3.2. the origin story. main character debut. πŸ‘‘


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>.


that's the whole page bestie, every flag, every caveat, every NULL check accounted for. nothing skipped, nothing invented, and the mark-clearing warning is right there where it belongs. πŸ’–

OpenSSL version 4.0.3, dated 2026-09-29, manual page OSSL_ERR_STATE_SAVE(3SSL) β€” mwah, thanks for reading, ily, go clear your marks 🫢✨

πŸ“¦ where this page comes from