Re: [PATCH v3 1/4] srcpos: Define srcpos_free

David Gibson <[email protected]>
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <aEbWD5VSvX7X3_OK@zatzit>
On Thu, Jun 05, 2025 at 04:18:06PM +0530, Ayush Singh wrote:
> srcpos can be chained together using srcpos_extend. However, in such
> cases, we need to free all the chained nodes.
> 
> srcpos_free is a helper to recursively free all the linked srcpos.
> 
> Signed-off-by: Ayush Singh <[email protected]>

Merged, thanks.

> ---
>  livetree.c |  2 +-
>  srcpos.c   | 11 +++++++++++
>  srcpos.h   |  1 +
>  3 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/livetree.c b/livetree.c
> index 93c77d95a320ec05aa355e12920cef9e1c91c26a..d51d05830b181476ddbab878ef8b556230b58e2b 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -174,7 +174,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
>  
>  				old_prop->val = new_prop->val;
>  				old_prop->deleted = 0;
> -				free(old_prop->srcpos);
> +				srcpos_free(old_prop->srcpos);
>  				old_prop->srcpos = new_prop->srcpos;
>  				free(new_prop);
>  				new_prop = NULL;
> diff --git a/srcpos.c b/srcpos.c
> index 5e2f7dd299184ff86b00b280dc31498cb9830e28..5bb57bf6856c6ff6b8eb993aff5d216c63bf5ecb 100644
> --- a/srcpos.c
> +++ b/srcpos.c
> @@ -287,6 +287,17 @@ struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
>  	return pos;
>  }
>  
> +void srcpos_free(struct srcpos *pos)
> +{
> +	struct srcpos *p_next;
> +
> +	while (pos) {
> +		p_next = pos->next;
> +		free(pos);
> +		pos = p_next;
> +	}
> +}
> +
>  char *
>  srcpos_string(struct srcpos *pos)
>  {
> diff --git a/srcpos.h b/srcpos.h
> index 4318d7ad34d91d2ada1a5d7f92d2c84148fec366..4d60b50e31197c2da6a7fa8851c5e5a6717d78a6 100644
> --- a/srcpos.h
> +++ b/srcpos.h
> @@ -88,6 +88,7 @@ extern void srcpos_update(struct srcpos *pos, const char *text, int len);
>  extern struct srcpos *srcpos_copy(struct srcpos *pos);
>  extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
>  				    struct srcpos *old_srcpos);
> +extern void srcpos_free(struct srcpos *pos);
>  extern char *srcpos_string(struct srcpos *pos);
>  extern char *srcpos_string_first(struct srcpos *pos, int level);
>  extern char *srcpos_string_last(struct srcpos *pos, int level);
> 

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmhG1gIACgkQzQJF27ox
2Ge7EA//ZNZLSUJL9nDNMgk8AqneoA12Yv7Ed9t1Sg0ITfmLU8dhEoKx4n9crBoq
81Tt7xzFKhTnUN/0uIuHvmyGIrrkqGm1JYpUKgU0OA8u1kHYAR9nlswcWR7a+Z+T
LOl2Nij4MMISdPZ4MUHlxJvjouqFBIKZQzTXnrLqcurOlxl6ehRVp6RLO/3pmZJf
TPfOw/KKYUkyNCtF3h38UM9sjbKfrJJJtfW8yrW5zoguRoHQFmzGoHC4cYoccKDg
IfZjCQC/4ZRTgpljBvdY5vpydVOcCdFlcrhdyhWR939eUM73X+YuaR5riY44K1Fq
RxRr8UZkdDI+T2g/si5ZjBSzLNgCEmKGvz9EZTH/Lzjs8EW5FKZBjmx0BdZF1BBT
6Zq3i0XhSVHLxAuV2Er7pgTYu13vxRAiQ3KXMLtLrWL1xeHW1FrpUmoXq7enKDrq
b2xx+bB9nXlEd0viX8FaIRdhYCB9rf3uP7wtgwLReyoOaQA1hjzmcmKIppWNHbg0
54j3Do5kxzrER1+oM1yNnNvX6C8uas29SlYYs4hqUBFySMaisiqmH5RjPPAzHkWQ
ROvZXSjhGn+Zag78UWOyJWqRDo8AVnTAtKiZAkIw0L2X+4yQW/vkYHaBeQe3zvA/
kUdBpfuwYtnSoXrXCD+55s1YMdKELUYIGhnbzS5/6Y2zUAXmQuA=
=FFR9
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.