[PATCH libICE 04/13] check the return of malloc()
walter harms
wharms at bfs.de
Wed Oct 18 15:54:30 UTC 2017
check the return of malloc()
Signed-off-by: Walter Harms <wharms at bfs.de>
---
src/protosetup.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/protosetup.c b/src/protosetup.c
index b6aece8..dbc136e 100644
--- a/src/protosetup.c
+++ b/src/protosetup.c
@@ -110,11 +110,17 @@ IceProtocolSetup (
/*
* Generate the message.
*/
+ authCount = 0;
+ authIndices = NULL;
if (myProtocol->orig_client->auth_count > 0)
{
authIndices = malloc (
myProtocol->orig_client->auth_count * sizeof (int));
+ if (! authIndices) {
+ strncpy (errorStringRet,"out of memory",errorLength);
+ return (IceProtocolSetupFailure);
+ }
_IceGetPoValidAuthIndices (myProtocol->protocol_name,
iceConn->connection_string,
@@ -123,11 +129,6 @@ IceProtocolSetup (
&authCount, authIndices);
}
- else
- {
- authCount = 0;
- authIndices = NULL;
- }
extra = STRING_BYTES (myProtocol->protocol_name) +
STRING_BYTES (myProtocol->orig_client->vendor) +
@@ -183,6 +184,12 @@ IceProtocolSetup (
replyWait.reply = (IcePointer) &reply;
iceConn->protosetup_to_you = malloc (sizeof (_IceProtoSetupToYouInfo));
+ if (! iceConn->protosetup_to_you) {
+ free(authIndices);
+ strncpy (errorStringRet,"out of memory",errorLength);
+ return (IceProtocolSetupFailure);
+ }
+
iceConn->protosetup_to_you->my_opcode = myOpcode;
iceConn->protosetup_to_you->my_auth_count = authCount;
iceConn->protosetup_to_you->auth_active = 0;
@@ -199,6 +206,8 @@ IceProtocolSetup (
if (ioErrorOccured)
{
+ free(iceConn->protosetup_to_you);
+ free(authIndices);
strncpy (errorStringRet,
"IO error occured doing Protocol Setup on connection",
errorLength);
@@ -240,6 +249,7 @@ IceProtocolSetup (
free (iceConn->protosetup_to_you->my_auth_indices);
free (iceConn->protosetup_to_you);
iceConn->protosetup_to_you = NULL;
+ free(authIndices);
}
}
@@ -279,6 +289,5 @@ IceProtocolSetup (
versionRec->process_msg_proc;
return (IceProtocolSetupSuccess);
-
}
--
2.1.4
More information about the xorg-devel
mailing list