[Asterisk-code-review] manager.c: Fix potential memory leak and corruption. (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Thu Feb 1 12:31:01 CST 2018


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/8131


Change subject: manager.c: Fix potential memory leak and corruption.
......................................................................

manager.c: Fix potential memory leak and corruption.

ast_str_append_event_header() could potentially leak and corrupt memory if
the ast_str needed to expand to add the AMI event header.

Change-Id: I92f36b855540743b208d76e274152ee2d758176d
---
M main/manager.c
1 file changed, 5 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/31/8131/1

diff --git a/main/manager.c b/main/manager.c
index 3aa9105..9578200 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -9497,19 +9497,16 @@
 }
 
 int ast_str_append_event_header(struct ast_str **fields_string,
-					const char *header, const char *value)
+	const char *header, const char *value)
 {
-	struct ast_str *working_str = *fields_string;
-
-	if (!working_str) {
-		working_str = ast_str_create(128);
-		if (!working_str) {
+	if (!*fields_string) {
+		*fields_string = ast_str_create(128);
+		if (!*fields_string) {
 			return -1;
 		}
-		*fields_string = working_str;
 	}
 
-	ast_str_append(&working_str, 0,
+	ast_str_append(fields_string, 0,
 		"%s: %s\r\n",
 		header, value);
 

-- 
To view, visit https://gerrit.asterisk.org/8131
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I92f36b855540743b208d76e274152ee2d758176d
Gerrit-Change-Number: 8131
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180201/ece7ec10/attachment.html>


More information about the asterisk-code-review mailing list