[Asterisk-code-review] tcptls.c: Add some missing allocation failure checks. (asterisk[13])

Anonymous Coward asteriskteam at digium.com
Mon Feb 20 21:30:28 CST 2017


Anonymous Coward #1000019 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5001 )

Change subject: tcptls.c: Add some missing allocation failure checks.
......................................................................


tcptls.c: Add some missing allocation failure checks.

Change-Id: I0ddf01cd3c10d3b6666d7bf68d4e206a37f4fbdb
---
M main/tcptls.c
1 file changed, 12 insertions(+), 8 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/tcptls.c b/main/tcptls.c
index 4d110cd..c46b8df 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -773,14 +773,16 @@
 		}
 		tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor);
 		if (!tcptls_session) {
-			ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno));
-			if (close(fd)) {
-				ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno));
-			}
+			close(fd);
 			continue;
 		}
 
 		tcptls_session->overflow_buf = ast_str_create(128);
+		if (!tcptls_session->overflow_buf) {
+			ao2_ref(tcptls_session, -1);
+			close(fd);
+			continue;
+		}
 		flags = fcntl(fd, F_GETFL);
 		fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
 		tcptls_session->fd = fd;
@@ -1059,11 +1061,15 @@
 		}
 	}
 
-	if (!(tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor))) {
+	tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor);
+	if (!tcptls_session) {
 		goto error;
 	}
 
 	tcptls_session->overflow_buf = ast_str_create(128);
+	if (!tcptls_session->overflow_buf) {
+		goto error;
+	}
 	tcptls_session->client = 1;
 	tcptls_session->fd = desc->accept_fd;
 	tcptls_session->parent = desc;
@@ -1078,9 +1084,7 @@
 error:
 	close(desc->accept_fd);
 	desc->accept_fd = -1;
-	if (tcptls_session) {
-		ao2_ref(tcptls_session, -1);
-	}
+	ao2_cleanup(tcptls_session);
 	return NULL;
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0ddf01cd3c10d3b6666d7bf68d4e206a37f4fbdb
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list