From 1c2ebcb6e2f30a6160d624099ad96dcf6ce375e5 Mon Sep 17 00:00:00 2001
From: Erik Karlsson <erik.karlsson@genexis.eu>
Date: Wed, 2 Mar 2022 23:52:35 +0100
Subject: [PATCH] Use uci_free_context to free UCI context

---
 src/config.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/config.c b/src/config.c
index 7c8f7cd66..9006844ae 100644
--- a/src/config.c
+++ b/src/config.c
@@ -163,7 +163,8 @@ struct uci_package *uci_load_pkg(struct uci_context **ctx, const char *config)
 	}
 
 	if (uci_load(*ctx, config, &pkg) != UCI_OK) {
-		free(*ctx);
+		uci_free_context(*ctx);
+		*ctx = NULL;
 		return NULL;
 	}
 
@@ -1563,9 +1564,12 @@ int config_update(const char *confname, struct agent_config *cfg,
 	struct uci_element *e;
 
 	ctx = uci_alloc_context();
-	if (ctx && uci_load(ctx, confname, &pkg) != UCI_OK) {
+	if (!ctx)
+		return -1;
+
+	if (uci_load(ctx, confname, &pkg) != UCI_OK) {
 		dbg("config file '%s' not found!\n", confname);
-		free(ctx);
+		uci_free_context(ctx);
 		return -1;
 	}
 
@@ -1629,9 +1633,12 @@ int config_update2(const char *confname, struct agent_config *cfg,
 	struct uci_element *e;
 
 	ctx = uci_alloc_context();
-	if (ctx && uci_load(ctx, confname, &pkg) != UCI_OK) {
+	if (!ctx)
+		return -1;
+
+	if (uci_load(ctx, confname, &pkg) != UCI_OK) {
 		dbg("config file '%s' not found!\n", confname);
-		free(ctx);
+		uci_free_context(ctx);
 		return -1;
 	}
 
-- 
GitLab