diff mbox series

refactor: parser: use stack allocated memory

Message ID 20230119143511.1186758-1-michael.adler@siemens.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series refactor: parser: use stack allocated memory | expand

Commit Message

Michael Adler Jan. 19, 2023, 2:35 p.m. UTC
This is the only location where we allocate `nodes` on the heap;
all the other callers of find_node_and_path() already use
stack-allocated memory. Also, there is no need to zero the memory since
this is done by find_node_and_path.

Signed-off-by: Michael Adler <michael.adler@siemens.com>
Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 parser/parser.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Stefano Babic Jan. 22, 2023, 5:53 p.m. UTC | #1
> This is the only location where we allocate `nodes` on the heap;
> all the other callers of find_node_and_path() already use
> stack-allocated memory. Also, there is no need to zero the memory since
> this is done by find_node_and_path.
> Signed-off-by: Michael Adler <michael.adler@siemens.com>
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
Applied to swupdate, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/parser/parser.c b/parser/parser.c
index 5607031..98f98e7 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -162,18 +162,13 @@  static int parser_follow_link(parsertype p, void *cfg, void *elem,
 static void *find_node(parsertype p, void *root, const char *field,
 			struct swupdate_cfg *swcfg)
 {
-	const char **nodes;
+	const char *nodes[MAX_PARSED_NODES];
 	void *node = NULL;
 
 	if (!field)
 		return NULL;
 
-	nodes = (const char **)calloc(MAX_PARSED_NODES, sizeof(*nodes));
-	if (!nodes)
-		return NULL;
-
 	node = find_node_and_path(p, root, field, swcfg, nodes);
-	free(nodes);
 
 	return node;
 }