Commit d37f9f31 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Reconnect.c: simplify code by using strndup

Also abort reconnect on strndup failure.
parent e52799d5
...@@ -438,22 +438,14 @@ Bool nxagentReconnectSession(void) ...@@ -438,22 +438,14 @@ Bool nxagentReconnectSession(void)
if (nxagentKeyboard != NULL) if (nxagentKeyboard != NULL)
{ {
int size; nxagentOldKeyboard = strndup(nxagentKeyboard, strlen(nxagentKeyboard));
if (nxagentOldKeyboard == NULL)
size = strlen(nxagentKeyboard);
if ((nxagentOldKeyboard = malloc(size + 1)) != NULL)
{ {
strncpy(nxagentOldKeyboard, nxagentKeyboard, size); /* 0 means reconnection failed */
return 0;
nxagentOldKeyboard[size] = '\0';
} }
}
if (nxagentKeyboard)
{
free(nxagentKeyboard); free(nxagentKeyboard);
nxagentKeyboard = NULL; nxagentKeyboard = NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment