<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>


<style>img {
max-width: 100%; height: auto;
}
body {
font-size: 0.875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,0.01) 0 0 1px;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,0.01) 0 0 1px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";'>
<div class="content">

<p style="color: #777777;">
<a href="https://gitlab.com/dueno" style="color: #1068bf;">Daiki Ueno</a>
commented on a
discussion on <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1647#note_1115177278" style="color: #1068bf;">lib/random.c</a>:
</p>
<table class="code gl-mb-5" style="border-spacing: 0; margin-bottom: 1rem; border-collapse: collapse; width: auto; font-family: monospace; font-size: 90%;" bgcolor="#fff" width="100%" cellpadding="0" cellspacing="0">
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="37" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fafafa">
37
</td>
<td class="new_line diff-line-num" data-linenumber="38" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fafafa">
38
</td>
<td class="line_content" style="padding: inherit;"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'> <span id="LC38" class="line" lang="c"></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="38" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fafafa">
38
</td>
<td class="new_line diff-line-num" data-linenumber="39" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fafafa">
39
</td>
<td class="line_content" style="padding: inherit;"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'> <span id="LC39" class="line" lang="c"><span class="cm" style="color: #998; font-style: italic;">/* Per thread context of random generator, and a flag to indicate initialization */</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="39" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
39
</td>
<td class="new_line diff-line-num old" data-linenumber="40" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC39" class="line" lang="c"><span class="k" style="font-weight: 600;"><span class="idiff left deletion" style="background-color: #fac5cd;">static</span></span><span class="idiff deletion" style="background-color: #fac5cd;"> </span><span class="k" style="font-weight: 600;"><span class="idiff deletion" style="background-color: #fac5cd;">_Thread_local</span></span><span class="idiff deletion" style="background-color: #fac5cd;"> </span><span class="kt" style="color: #458; font-weight: 600;"><span class="idiff deletion" style="background-color: #fac5cd;">void</span></span><span class="idiff deletion" style="background-color: #fac5cd;"> </span><span class="o" style="font-weight: 600;"><span class="idiff deletion" style="background-color: #fac5cd;">*</span></span><span class="n" style="color: #333;"><span class="idiff right deletion" style="background-color: #fac5cd;">gnutls_rnd_ctx</span></span><span class="p">;</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="40" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
40
</td>
<td class="new_line diff-line-num old" data-linenumber="40" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC40" class="line" lang="c"><span class="k" style="font-weight: 600;"><span class="idiff left deletion" style="background-color: #fac5cd;">static</span></span><span class="idiff right deletion" style="background-color: #fac5cd;"> </span><span class="k" style="font-weight: 600;">_Thread_local</span> <span class="kt" style="color: #458; font-weight: 600;">unsigned</span> <span class="n" style="color: #333;">rnd_initialized</span> <span class="o" style="font-weight: 600;">=</span> <span class="mi" style="color: #099;">0</span><span class="p">;</span></span>
</pre></td>
</tr>
<tr class="line_holder new" style="line-height: 1.6;">
<td class="old_line diff-line-num new" data-linenumber="41" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: inherit;" align="right" bgcolor="#ddfbe6">
 
</td>
<td class="new_line diff-line-num new" data-linenumber="40" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: inherit;" align="right" bgcolor="#ddfbe6">
40
</td>
<td class="line_content new" style="padding: inherit;" bgcolor="#ecfdf0"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>+<span id="LC40" class="line" lang="c"><span class="n" style="color: #333;"><span class="idiff left addition" style="background-color: #c7f0d2;">gl_tls_key_t</span></span><span class="idiff addition" style="background-color: #c7f0d2;"> </span><span class="n" style="color: #333;"><span class="idiff right addition" style="background-color: #c7f0d2;">ctx_key</span></span><span class="p">;</span></span>
</pre></td>
</tr>
<tr class="line_holder new" style="line-height: 1.6;">
<td class="old_line diff-line-num new" data-linenumber="41" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: inherit;" align="right" bgcolor="#ddfbe6">
 
</td>
<td class="new_line diff-line-num new" data-linenumber="41" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #c7f0d2; border-right-style: solid; padding: inherit;" align="right" bgcolor="#ddfbe6">
41
</td>
<td class="line_content new" style="padding: inherit;" bgcolor="#ecfdf0"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>+<span id="LC41" class="line" lang="c"><span class="k" style="font-weight: 600;">_Thread_local</span> <span class="kt" style="color: #458; font-weight: 600;">unsigned</span> <span class="n" style="color: #333;">rnd_initialized</span> <span class="o" style="font-weight: 600;">=</span> <span class="mi" style="color: #099;">0</span><span class="p">;</span></span>
</pre></td>
</tr>
<tr class="line_holder" style="line-height: 1.6;">
<td class="old_line diff-line-num" data-linenumber="41" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fafafa">
41
</td>
<td class="new_line diff-line-num" data-linenumber="42" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: inherit;" align="right" bgcolor="#fafafa">
42
</td>
<td class="line_content" style="padding: inherit;"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'> <span id="LC42" class="line" lang="c"></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="42" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
42
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC42" class="line" lang="c"><span class="k" style="font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="p">{</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
43
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC43" class="line" lang="c">     <span class="kt" style="color: #458; font-weight: 600;">void</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">ctx</span><span class="p">;</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="44" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
44
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC44" class="line" lang="c">     <span class="k" style="font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">next</span><span class="p">;</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="45" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
45
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC45" class="line" lang="c"><span class="p">};</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="46" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
46
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC46" class="line" lang="c"></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="47" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
47
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC47" class="line" lang="c"><span class="cm" style="color: #998; font-style: italic;">/* A global list of all allocated contexts - to be</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="48" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
48
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC48" class="line" lang="c"><span class="cm" style="color: #998; font-style: italic;"> * used during deinitialization. */</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="49" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
49
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC49" class="line" lang="c"><span class="n" style="color: #333;">GNUTLS_STATIC_MUTEX</span><span class="p">(</span><span class="n" style="color: #333;">gnutls_rnd_ctx_list_mutex</span><span class="p">);</span></span>
</pre></td>
</tr>
<tr class="line_holder old" style="line-height: 1.6;">
<td class="old_line diff-line-num old" data-linenumber="50" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
50
</td>
<td class="new_line diff-line-num old" data-linenumber="43" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #fac5cd; border-right-style: solid; padding: inherit;" align="right" bgcolor="#f9d7dc">
 
</td>
<td class="line_content old" style="padding: inherit;" bgcolor="#fbe9eb"><pre style='display: block; font-size: 0.8125rem; color: #303030; position: relative; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; word-break: break-all; word-wrap: break-word; background-color: inherit; border-radius: 2px; margin: 0; padding: 0; border: inherit solid #dbdbdb;'>-<span id="LC50" class="line" lang="c"><span class="k" style="font-weight: 600;">static</span> <span class="k" style="font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">head</span> <span class="o" style="font-weight: 600;">=</span> <span class="nb" style="color: #0086b3;">NULL</span><span class="p">;</span></span>
</pre></td>
</tr>

</table>
<div class="md" style="color: #303030; word-wrap: break-word;">
<p dir="auto" style="color: #303030; margin: 0 0 16px;" align="initial">An alternative approach would be to make list entry object (<code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; margin-top: 0; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>struct rnd_ctx_list_st *head</code>) thread-local instead of the actual context (<code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>void *ctx</code>). In the TLS destructor, you could release <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>head->ctx</code> and set it to NULL. Then in the global destructor, you could traverse the list and release the elements, something like:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-c" lang="c" v-pre="true" style="display: block; font-size: 13px; color: #303030; line-height: 1.6em; overflow-x: auto; border-radius: 4px; position: relative; font-family: monospace; word-break: break-all; word-wrap: break-word; background-color: #fff; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%; margin: 0 0 16px; padding: 12px; border: 1px solid #dbdbdb;"><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: 4px; white-space: pre; margin-top: 0; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="c" style="margin-top: 0;"><span class="k" style="margin-top: 0; font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="p">{</span></span>
<span id="LC2" class="line" lang="c">       <span class="kt" style="margin-top: 0; color: #458; font-weight: 600;">void</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">ctx</span><span class="p">;</span></span>
<span id="LC3" class="line" lang="c">       <span class="k" style="margin-top: 0; font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">next</span><span class="p">;</span></span>
<span id="LC4" class="line" lang="c"><span class="p" style="margin-top: 0;">};</span></span>
<span id="LC5" class="line" lang="c"><span class="k" style="margin-top: 0; font-weight: 600;">static</span> <span class="k" style="font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">head</span> <span class="o" style="font-weight: 600;">=</span> <span class="nb" style="color: #0086b3;">NULL</span><span class="p">;</span></span>
<span id="LC6" class="line" lang="c"><span class="p" style="margin-top: 0;">...</span></span>
<span id="LC7" class="line" lang="c"><span class="k" style="margin-top: 0; font-weight: 600;">static</span> <span class="kt" style="color: #458; font-weight: 600;">void</span> <span class="o" style="font-weight: 600;">*</span></span>
<span id="LC8" class="line" lang="c"><span class="nf" style="margin-top: 0; color: #900; font-weight: 600;">rnd_ctx_list_destructor</span><span class="p">(</span><span class="kt" style="color: #458; font-weight: 600;">void</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">p</span><span class="p">)</span></span>
<span id="LC9" class="line" lang="c"><span class="p" style="margin-top: 0;">{</span></span>
<span id="LC10" class="line" lang="c">  <span class="k" style="margin-top: 0; font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">e</span> <span class="o" style="font-weight: 600;">=</span> <span class="n" style="color: #333;">p</span><span class="p">;</span></span>
<span id="LC11" class="line" lang="c">  <span class="n" style="margin-top: 0; color: #333;">free_ctx</span><span class="p">(</span><span class="n" style="color: #333;">e</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">ctx</span><span class="p">);</span></span>
<span id="LC12" class="line" lang="c">  <span class="n" style="margin-top: 0; color: #333;">e</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">ctx</span> <span class="o" style="font-weight: 600;">=</span> <span class="nb" style="color: #0086b3;">NULL</span><span class="p">;</span></span>
<span id="LC13" class="line" lang="c">  <span class="k" style="margin-top: 0; font-weight: 600;">return</span> <span class="nb" style="color: #0086b3;">NULL</span><span class="p">;</span></span>
<span id="LC14" class="line" lang="c"><span class="p" style="margin-top: 0;">}</span></span>
<span id="LC15" class="line" lang="c"><span class="p" style="margin-top: 0;">...</span></span>
<span id="LC16" class="line" lang="c"><span class="k" style="margin-top: 0; font-weight: 600;">static</span> <span class="kr" style="font-weight: 600;">inline</span> <span class="kt" style="color: #458; font-weight: 600;">int</span></span>
<span id="LC17" class="line" lang="c"><span class="nf" style="margin-top: 0; color: #900; font-weight: 600;">_gnutls_rnd_init</span><span class="p">(</span><span class="kt" style="color: #458; font-weight: 600;">void</span><span class="p">)</span></span>
<span id="LC18" class="line" lang="c"><span class="p" style="margin-top: 0;">{</span></span>
<span id="LC19" class="line" lang="c">  <span class="p" style="margin-top: 0;">...</span></span>
<span id="LC20" class="line" lang="c">  <span class="n" style="margin-top: 0; color: #333;">glthread_tls_key_init</span><span class="p">(</span><span class="o" style="font-weight: 600;">&</span><span class="n" style="color: #333;">ctx_key</span><span class="p">,</span> <span class="n" style="color: #333;">rnd_ctx_list_destructor</span><span class="p">);</span></span>
<span id="LC21" class="line" lang="c">  <span class="n" style="margin-top: 0; color: #333;">glthread_tls_set</span><span class="p">(</span><span class="o" style="font-weight: 600;">&</span><span class="n" style="color: #333;">ctx_key</span><span class="p">,</span> <span class="n" style="color: #333;">ctx</span><span class="p">);</span></span>
<span id="LC22" class="line" lang="c">  <span class="p" style="margin-top: 0;">...</span></span>
<span id="LC23" class="line" lang="c"><span class="p" style="margin-top: 0;">}</span></span>
<span id="LC24" class="line" lang="c"><span class="p" style="margin-top: 0;">...</span></span>
<span id="LC25" class="line" lang="c"><span class="kt" style="margin-top: 0; color: #458; font-weight: 600;">void</span></span>
<span id="LC26" class="line" lang="c"><span class="nf" style="margin-top: 0; color: #900; font-weight: 600;">_gnutls_rnd_deinit</span><span class="p">(</span><span class="kt" style="color: #458; font-weight: 600;">void</span><span class="p">)</span></span>
<span id="LC27" class="line" lang="c"><span class="p" style="margin-top: 0;">{</span></span>
<span id="LC28" class="line" lang="c">  <span class="k" style="margin-top: 0; font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">e</span> <span class="o" style="font-weight: 600;">=</span> <span class="n" style="color: #333;">head</span><span class="p">;</span></span>
<span id="LC29" class="line" lang="c">  <span class="k" style="margin-top: 0; font-weight: 600;">while</span> <span class="p">(</span><span class="n" style="color: #333;">e</span><span class="p">)</span> <span class="p">{</span></span>
<span id="LC30" class="line" lang="c">    <span class="k" style="margin-top: 0; font-weight: 600;">struct</span> <span class="n" style="color: #333;">rnd_ctx_list_st</span> <span class="o" style="font-weight: 600;">*</span><span class="n" style="color: #333;">next</span> <span class="o" style="font-weight: 600;">=</span> <span class="n" style="color: #333;">e</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">next</span><span class="p">;</span></span>
<span id="LC31" class="line" lang="c">    <span class="n" style="margin-top: 0; color: #333;">free_ctx</span><span class="p">(</span><span class="n" style="color: #333;">e</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">ctx</span><span class="p">);</span></span>
<span id="LC32" class="line" lang="c">    <span class="n" style="margin-top: 0; color: #333;">gnutls_free</span><span class="p">(</span><span class="n" style="color: #333;">e</span><span class="p">);</span></span>
<span id="LC33" class="line" lang="c">    <span class="n" style="margin-top: 0; color: #333;">e</span> <span class="o" style="font-weight: 600;">=</span> <span class="n" style="color: #333;">next</span><span class="p">;</span></span>
<span id="LC34" class="line" lang="c">  <span class="p" style="margin-top: 0;">}</span></span>
<span id="LC35" class="line" lang="c">  <span class="n" style="margin-top: 0; color: #333;">head</span> <span class="o" style="font-weight: 600;">=</span> <span class="nb" style="color: #0086b3;">NULL</span><span class="p">;</span></span>
<span id="LC36" class="line" lang="c"><span class="p" style="margin-top: 0;">}</span></span></code></pre>
<copy-code></copy-code>
</div>
<p dir="auto" style="color: #303030; margin: 0;" align="initial">One drawback with this approach is that if destructor is not called on some platforms, list entries will remain unreleased, though it's only until <code style='font-size: 90%; color: #1f1f1f; word-wrap: break-word; background-color: #f0f0f0; border-radius: 4px; margin-top: 0; font-weight: inherit; font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 2px 4px;'>_gnutls_rnd_deinit</code> is called.</p>
</div>


</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1647#note_1115177278" style="color: #1068bf;">view it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.com" style="color: #1068bf;">gitlab.com</a>. <a href="https://gitlab.com/-/sent_notifications/6b0325b328ccb1100b5f4f2ad194e23f/unsubscribe" target="_blank" rel="noopener noreferrer" style="color: #1068bf;">Unsubscribe</a> from this thread · <a href="https://gitlab.com/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link" style="color: #1068bf;">Manage all notifications</a> · <a href="https://gitlab.com/help" target="_blank" rel="noopener noreferrer" class="help-link" style="color: #1068bf;">Help</a>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.com/gnutls/gnutls/-/merge_requests/1647#note_1115177278"}}</script>


</p>
</div>
</body>
</html>