xref: /freebsd/crypto/openssl/doc/man3/SSL_SESSION_free.pod (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1=pod
2
3=head1 NAME
4
5SSL_SESSION_new,
6SSL_SESSION_dup,
7SSL_SESSION_up_ref,
8SSL_SESSION_free - create, free and manage SSL_SESSION structures
9
10=head1 SYNOPSIS
11
12 #include <openssl/ssl.h>
13
14 SSL_SESSION *SSL_SESSION_new(void);
15 SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src);
16 int SSL_SESSION_up_ref(SSL_SESSION *ses);
17 void SSL_SESSION_free(SSL_SESSION *session);
18
19=head1 DESCRIPTION
20
21SSL_SESSION_new() creates a new SSL_SESSION structure and returns a pointer to
22it.
23
24SSL_SESSION_dup() creates a new SSL_SESSION structure that is a copy of B<src>.
25The copy is not owned by any cache that B<src> may have been in.
26
27SSL_SESSION_up_ref() increments the reference count on the given SSL_SESSION
28structure.
29
30SSL_SESSION_free() decrements the reference count of B<session> and removes
31the B<SSL_SESSION> structure pointed to by B<session> and frees up the allocated
32memory, if the reference count has reached 0.
33If B<session> is NULL nothing is done.
34
35=head1 NOTES
36
37SSL_SESSION objects are allocated, when a TLS/SSL handshake operation
38is successfully completed. Depending on the settings, see
39L<SSL_CTX_set_session_cache_mode(3)>,
40the SSL_SESSION objects are internally referenced by the SSL_CTX and
41linked into its session cache. SSL objects may be using the SSL_SESSION object;
42as a session may be reused, several SSL objects may be using one SSL_SESSION
43object at the same time. It is therefore crucial to keep the reference
44count (usage information) correct and not delete a SSL_SESSION object
45that is still used, as this may lead to program failures due to
46dangling pointers. These failures may also appear delayed, e.g.
47when an SSL_SESSION object was completely freed as the reference count
48incorrectly became 0, but it is still referenced in the internal
49session cache and the cache list is processed during a
50L<SSL_CTX_flush_sessions(3)> operation.
51
52SSL_SESSION_free() must only be called for SSL_SESSION objects, for
53which the reference count was explicitly incremented (e.g.
54by calling SSL_get1_session(), see L<SSL_get_session(3)>)
55or when the SSL_SESSION object was generated outside a TLS handshake
56operation, e.g. by using L<d2i_SSL_SESSION(3)>.
57It must not be called on other SSL_SESSION objects, as this would cause
58incorrect reference counts and therefore program failures.
59
60=head1 RETURN VALUES
61
62SSL_SESSION_new returns a pointer to the newly allocated SSL_SESSION structure
63or NULL on error.
64
65SSL_SESSION_dup returns a pointer to the new copy or NULL on error.
66
67SSL_SESSION_up_ref returns 1 on success or 0 on error.
68
69=head1 SEE ALSO
70
71L<ssl(7)>, L<SSL_get_session(3)>,
72L<SSL_CTX_set_session_cache_mode(3)>,
73L<SSL_CTX_flush_sessions(3)>,
74L<d2i_SSL_SESSION(3)>
75
76=head1 HISTORY
77
78The SSL_SESSION_dup() function was added in OpenSSL 1.1.1.
79
80=head1 COPYRIGHT
81
82Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
83
84Licensed under the Apache License 2.0 (the "License").  You may not use
85this file except in compliance with the License.  You can obtain a copy
86in the file LICENSE in the source distribution or at
87L<https://www.openssl.org/source/license.html>.
88
89=cut
90