[gnutls-devel] GnuTLS | _gnutls_rnd_init allocates memory per thread but does not seem to deallocate it (#1401)

Read-only notification of GnuTLS library development activities gnutls-devel at lists.gnutls.org
Fri Sep 23 12:45:25 CEST 2022




Pedro Marzo commented:


pthread_key_delete must be called on `_gnutls_rnd_deinit`, that is a bug of the patch.

But that will free the key, not the context as specified on the doc it does not execute the destructors.
https://pubs.opengroup.org/onlinepubs/009695299/functions/pthread_key_delete.html

I guess the safest aproach is to call pthread_key_delete and free the context on _gnutls_rnd_deinit


```
void _gnutls_rnd_deinit(void)
{
	void *gnutls_rnd_ctx = pthread_getspecific(ctxkey);

	rnd_initialized = 0;

	/**
	 * Remove the key and free the context. 
	 * Context is not freed from the main thread unless it exists
	 * with pthread_exit which is not guaranteed. 
	 * So we delete the key and remove the context
	*/
	pthread_key_delete(ctxkey);
	freectx(gnutls_rnd_ctx);
	_rnd_system_entropy_deinit();
}

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/-/issues/1401#note_1112075188
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20220923/f96b4826/attachment-0001.html>


More information about the Gnutls-devel mailing list