[PATCH uci] uci: decrease the n_section when section is freed

Jeff Shiu waherob42858 at gmail.com
Tue Aug 29 04:58:46 PDT 2023


The package n_section counter increases when a section is allocated
but does not decrease when a section is freed.

Since the anonymous section name is comprised of the section counter,
if the package is not reloaded, an incorrect count will result in
operating on the wrong section.

Signed-off-by: Jeff Shiu <waherob42858 at gmail.com>
---
 list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/list.c b/list.c
index 304c9e1..6545ba5 100644
--- a/list.c
+++ b/list.c
@@ -228,6 +228,7 @@ uci_free_section(struct uci_section *s)
 	if ((s->type != uci_dataptr(s)) &&
 		(s->type != NULL))
 		free(s->type);
+	s->package->n_section--;
 	uci_free_element(&s->e);
 }
 
@@ -734,7 +735,6 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
 			if (ptr->section == old->e.name)
 				ptr->section = ptr->s->e.name;
 			uci_free_section(old);
-			ptr->s->package->n_section--;
 		}
 	} else {
 		UCI_THROW(ctx, UCI_ERR_INVAL);
-- 
2.39.2




More information about the openwrt-devel mailing list