Merge pull request #394 from pjd/fixes

Plug memory leak in case of an empty file and terminate string with '\0'.
This commit is contained in:
Marc-André Moreau 2012-02-03 07:49:38 -08:00
commit d0730c42e3
2 changed files with 15 additions and 10 deletions

View File

@ -610,13 +610,17 @@ int certificate_data_match(rdpCertificateStore* certificate_store, rdpCertificat
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
data = (char*) xmalloc(size + 1);
length = fread(data, size, 1, fp);
if (size < 1)
return match;
data = (char*) xmalloc(size + 2);
if (fread(data, size, 1, fp) != 1) {
xfree(data);
return match;
}
data[size] = '\n';
data[size + 1] = '\0';
pline = strtok(data, "\n");
while (pline != NULL)

View File

@ -185,7 +185,12 @@ int tcp_read(rdpTcp* tcp, uint8* data, int length)
status = recv(tcp->sockfd, data, length, 0);
if (status <= 0)
if (status == 0)
{
/* Peer disconnected. */
return -1;
}
else if (status < 0)
{
#ifdef _WIN32
int wsa_error = WSAGetLastError();
@ -194,17 +199,13 @@ int tcp_read(rdpTcp* tcp, uint8* data, int length)
if (wsa_error == WSAEWOULDBLOCK)
return 0;
/* When peer disconnects we get status 0 with no error. */
if (status < 0)
printf("recv() error: %d\n", wsa_error);
printf("recv() error: %d\n", wsa_error);
#else
/* No data available */
if (errno == EAGAIN || errno == EWOULDBLOCK)
return 0;
/* When peer disconnects we get status 0 with no error. */
if (status < 0)
perror("recv");
perror("recv");
#endif
return -1;
}