Change in libosmocore[master]: vty/talloc_ctx_vty.c: allocate walk_cb_params on stack, not heap

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Apr 11 00:24:56 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/13534 )

Change subject: vty/talloc_ctx_vty.c: allocate walk_cb_params on stack, not heap
......................................................................

vty/talloc_ctx_vty.c: allocate walk_cb_params on stack, not heap

There is no need to allocate struct 'walk_cb_params' dynamically.

Change-Id: I96f25f1ddb36b19b12055deaeeb6f58e59180e72
---
M src/vty/talloc_ctx_vty.c
1 file changed, 15 insertions(+), 43 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/vty/talloc_ctx_vty.c b/src/vty/talloc_ctx_vty.c
index e7fe675..c4d5a88 100644
--- a/src/vty/talloc_ctx_vty.c
+++ b/src/vty/talloc_ctx_vty.c
@@ -180,22 +180,13 @@
 DEFUN(show_talloc_ctx, show_talloc_ctx_cmd,
 	BASE_CMD_STR, BASE_CMD_DESCR)
 {
-	struct walk_cb_params *params;
-
-	/* Allocate memory */
-	params = talloc_zero(tall_vty_ctx, struct walk_cb_params);
-	if (!params)
-		return CMD_WARNING;
+	struct walk_cb_params params = { 0 };
 
 	/* Set up callback parameters */
-	params->filter = WALK_FILTER_NONE;
-	params->vty = vty;
+	params.filter = WALK_FILTER_NONE;
+	params.vty = vty;
 
-	talloc_ctx_walk(argv[0], argv[1], params);
-
-	/* Free memory */
-	talloc_free(params);
-
+	talloc_ctx_walk(argv[0], argv[1], &params);
 	return CMD_SUCCESS;
 }
 
@@ -204,31 +195,22 @@
 	"Filter chunks using regular expression\n"
 	"Regular expression\n")
 {
-	struct walk_cb_params *params;
+	struct walk_cb_params params = { 0 };
 	int rc;
 
-	/* Allocate memory */
-	params = talloc_zero(tall_vty_ctx, struct walk_cb_params);
-	if (!params)
-		return CMD_WARNING;
-
 	/* Attempt to compile a regular expression */
-	rc = regcomp(&params->regexp, argv[2], 0);
+	rc = regcomp(&params.regexp, argv[2], 0);
 	if (rc) {
 		vty_out(vty, "Invalid expression%s", VTY_NEWLINE);
-		talloc_free(params);
 		return CMD_WARNING;
 	}
 
 	/* Set up callback parameters */
-	params->filter = WALK_FILTER_REGEXP;
-	params->vty = vty;
+	params.filter = WALK_FILTER_REGEXP;
+	params.vty = vty;
 
-	talloc_ctx_walk(argv[0], argv[1], params);
-
-	/* Free memory */
-	regfree(&params->regexp);
-	talloc_free(params);
+	talloc_ctx_walk(argv[0], argv[1], &params);
+	regfree(&params.regexp);
 
 	return CMD_SUCCESS;
 }
@@ -238,31 +220,21 @@
 	"Display only a specific memory chunk\n"
 	"Chunk address (e.g. 0xdeadbeef)\n")
 {
-	struct walk_cb_params *params;
+	struct walk_cb_params params = { 0 };
 	int rc;
 
-	/* Allocate memory */
-	params = talloc_zero(tall_vty_ctx, struct walk_cb_params);
-	if (!params)
-		return CMD_WARNING;
-
 	/* Attempt to parse an address */
-	rc = sscanf(argv[2], "%p", &params->chunk_ptr);
+	rc = sscanf(argv[2], "%p", &params.chunk_ptr);
 	if (rc != 1) {
 		vty_out(vty, "Invalid chunk address%s", VTY_NEWLINE);
-		talloc_free(params);
 		return CMD_WARNING;
 	}
 
 	/* Set up callback parameters */
-	params->filter = WALK_FILTER_TREE;
-	params->vty = vty;
+	params.filter = WALK_FILTER_TREE;
+	params.vty = vty;
 
-	talloc_ctx_walk(argv[0], argv[1], params);
-
-	/* Free memory */
-	talloc_free(params);
-
+	talloc_ctx_walk(argv[0], argv[1], &params);
 	return CMD_SUCCESS;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/13534
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I96f25f1ddb36b19b12055deaeeb6f58e59180e72
Gerrit-Change-Number: 13534
Gerrit-PatchSet: 3
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190411/3345a37d/attachment.html>


More information about the gerrit-log mailing list