[Asterisk-code-review] func_json: Fix memory leak. (asterisk[20])

N A asteriskteam at digium.com
Thu Nov 10 06:33:12 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19552 )


Change subject: func_json: Fix memory leak.
......................................................................

func_json: Fix memory leak.

A memory leak was present in func_json due to
using ast_json_free, which just calls ast_free,
as opposed to recursively freeing the JSON
object as needed. This is now fixed to use the
right free functions.

ASTERISK-30293 #close

Change-Id: I982324dde841dc9147c8d8ad35c8719daf418b49
---
M funcs/func_json.c
1 file changed, 19 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/52/19552/1

diff --git a/funcs/func_json.c b/funcs/func_json.c
index 1f64824..55a0343 100644
--- a/funcs/func_json.c
+++ b/funcs/func_json.c
@@ -115,7 +115,7 @@
 	jsonval = ast_json_object_get(json, args.key);
 	if (!jsonval) { /* no error or warning should be thrown */
 		ast_debug(1, "Could not find key '%s' in parsed JSON\n", args.key);
-		ast_json_free(json);
+		ast_json_unref(json);
 		return -1;
 	}
 	switch(ast_json_typeof(jsonval)) {
@@ -134,7 +134,7 @@
 			ast_json_free(result2);
 			break;
 	}
-	ast_json_free(json);
+	ast_json_unref(json);
 
 	return 0;
 }

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19552
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: I982324dde841dc9147c8d8ad35c8719daf418b49
Gerrit-Change-Number: 19552
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221110/a4ad85a1/attachment-0001.html>


More information about the asterisk-code-review mailing list