[gnutls-devel] libtasn1 | Fix memleaks in asn1_array2tree() (!29)

Development of GNU's TLS library gnutls-devel at lists.gnutls.org
Tue Jul 23 15:29:19 CEST 2019




Tim Rühsen commented on a discussion on lib/structure.c: https://gitlab.com/gnutls/libtasn1/merge_requests/29#note_194863727

>        if (*definitions == NULL)
>  	*definitions = p;
>  
> -      if (move == DOWN)
> +      if (move == DOWN) {
> +        if (p_last && p_last->down) {
> +	  _asn1_delete_node_from_list (e_list, p_last->down);
> +	  _asn1_remove_node (p_last->down, 0);
> +	}
>  	_asn1_set_down (p_last, p);
> -      else if (move == RIGHT)
> +      } else if (move == RIGHT) {
> +        if (p_last && p_last->right) {
> +	  _asn1_delete_node_from_list (e_list, p_last->right);
> +	  _asn1_remove_node (p_last->down, 0);

Looks like `container_of` needs global memory to store the information. Which then includes mutexes / pthread library and so on...

Interestingly, `asn1_array2tree()` has something similar for the error case. All allocated nodes are stored in a list (`list_type *e_list`). On error, a simple `_asn1_delete_list_and_nodes()` is called to free all memory (instead of traversing the tree via `asn1_delete_structure()`).

We could carry that list (or an array / vector) around and use that in `asn1_delete_structure()`. It needs a new API but very similar to `asn1_array2tree()`.

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/libtasn1/merge_requests/29#note_194863727
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/20190723/d90f364b/attachment.html>


More information about the Gnutls-devel mailing list