[Asterisk-code-review] res http websocket: Don't leak memory on read failure (asterisk[15])

Sean Bright asteriskteam at digium.com
Sun Feb 18 12:03:06 CST 2018


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/8254


Change subject: res_http_websocket: Don't leak memory on read failure
......................................................................

res_http_websocket: Don't leak memory on read failure

Change-Id: Ic449ea832bc81a1671c0e910c5fbe8c683e3da89
---
M res/res_http_websocket.c
1 file changed, 4 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/8254/1

diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 86a1547..3d6b424 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -674,14 +674,14 @@
 		}
 	} else if (*opcode == AST_WEBSOCKET_OPCODE_CLOSE) {
 		/* Make the payload available so the user can look at the reason code if they so desire */
-		if ((*payload_len) && (new_payload = ast_realloc(session->payload, *payload_len))) {
-			if (ws_safe_read(session, &buf[frame_size], (*payload_len), opcode)) {
+		if (*payload_len && (new_payload = ast_realloc(session->payload, *payload_len))) {
+			session->payload = new_payload;
+			if (ws_safe_read(session, &buf[frame_size], *payload_len, opcode)) {
 				return -1;
 			}
-			session->payload = new_payload;
 			memcpy(session->payload, &buf[frame_size], *payload_len);
 			*payload = session->payload;
-			frame_size += (*payload_len);
+			frame_size += *payload_len;
 		}
 
 		session->closing = 1;

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

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic449ea832bc81a1671c0e910c5fbe8c683e3da89
Gerrit-Change-Number: 8254
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180218/13acf905/attachment.html>


More information about the asterisk-code-review mailing list