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:
commit
d0730c42e3
@ -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)
|
||||
|
@ -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,16 +199,12 @@ 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);
|
||||
#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");
|
||||
#endif
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user