[PATCH libICE 04/13] check the return of malloc()
Emil Velikov
emil.l.velikov at gmail.com
Tue Oct 31 13:27:22 UTC 2017
On 18 October 2017 at 16:54, walter harms <wharms at bfs.de> wrote:
>
> 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) {
I know the existing coding style is iffy, but please don't diverge even more.
Namely - no space between ! and authIndices (same applies below).
> + strncpy (errorStringRet,"out of memory",errorLength);
Space after the comma.
...
> + 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);
> -
>
These seem to be unrelated memory leak/whitespace fixes.
Please keep that as separate commit.
-Emil
More information about the xorg-devel
mailing list