---
name: "libressl-SSL_SESSION_free"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SSL_SESSION_free"
---

# libressl-SSL\_SESSION\_free(3)

SSL\_SESSION reference counting

## NAME

**SSL\_SESSION\_up\_ref**, **SSL\_SESSION\_free** – SSL\_SESSION reference counting

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

**#include \<openssl/ssl.h\>**

*int*\

**SSL\_SESSION\_up\_ref**(*SSL\_SESSION \*session*);

*void*\

**SSL\_SESSION\_free**(*SSL\_SESSION \*session*);

## DESCRIPTION

**SSL\_SESSION\_up\_ref**() increments the reference count of the given *session* by 1.

**SSL\_SESSION\_free**() decrements the reference count of the given *session* by 1. If the reference count reaches 0, it frees the memory used by the *session*. If *session* is a NULL pointer, no action occurs.

*SSL\_SESSION* objects are allocated when a TLS/SSL handshake operation is successfully completed. Depending on the settings, see SSL\_CTX\_set\_session\_cache\_mode(3), the *SSL\_SESSION* objects are internally referenced by the *SSL\_CTX* and linked into its session cache. *SSL* objects may be using the *SSL\_SESSION* object; as a session may be reused, several *SSL* objects may be using one *SSL\_SESSION* object at the same time. It is therefore crucial to keep the reference count (usage information) correct and not delete a *SSL\_SESSION* object that is still used, as this may lead to program failures due to dangling pointers. These failures may also appear delayed, e.g., when an *SSL\_SESSION* object is completely freed as the reference count incorrectly becomes 0, but it is still referenced in the internal session cache and the cache list is processed during a SSL\_CTX\_flush\_sessions(3) operation.

**SSL\_SESSION\_free**() must only be called for *SSL\_SESSION* objects, for which the reference count was explicitly incremented (e.g., by calling SSL\_get1\_session(3); see SSL\_get\_session(3)) or when the *SSL\_SESSION* object was generated outside a TLS handshake operation, e.g., by using d2i\_SSL\_SESSION(3). It must not be called on other *SSL\_SESSION* objects, as this would cause incorrect reference counts and therefore program failures.

## RETURN VALUES

**SSL\_SESSION\_up\_ref**() returns 1 on success or 0 on error.

## SEE ALSO

d2i\_SSL\_SESSION(3), [ssl(3)](/ssl/3.md), SSL\_CTX\_flush\_sessions(3), SSL\_CTX\_set\_session\_cache\_mode(3), SSL\_get\_session(3), SSL\_SESSION\_new(3)

## HISTORY

**SSL\_SESSION\_free**() first appeared in SSLeay 0.5.2 and has been available since OpenBSD 2.4.

**SSL\_SESSION\_up\_ref**() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 6.3.
