tc_init is not thread-safe #289

Made the global sockaddr variables local and cleared them with a memset.
This commit is contained in:
Alex Lin 2016-08-29 13:10:10 -05:00
parent 60b09907a3
commit 0b91b1b163
3 changed files with 8 additions and 3 deletions

View File

@ -11,7 +11,6 @@
#include "dmtcpaware.h"
#endif
static struct sockaddr_in s_in;
int tc_accept_(TCDevice * listen_device, TCDevice * device, const char *file, int line)
{
@ -24,7 +23,9 @@ int tc_accept_(TCDevice * listen_device, TCDevice * device, const char *file, in
char *ptrL;
char client_str[TC_TAG_LENGTH + 256];
unsigned char byte_info[TC_BYTE_INFO_LENGTH];
struct sockaddr_in s_in;
memset(&s_in, 0, sizeof(struct sockaddr_in)) ;
/* Accept On Listen Device */
length = sizeof(s_in);
#if _DMTCP

View File

@ -11,7 +11,6 @@ int tc_init(TCDevice * listen_device) {
return tc_init_with_connection_info( listen_device, TRICKCOMM_SOCKET_FAMILY, SOCK_STREAM, NULL, listen_device->port ) ;
}
static struct sockaddr_in s_in;
int tc_init_with_connection_info( TCDevice * listen_device,
int domain,
@ -23,11 +22,14 @@ int tc_init_with_connection_info( TCDevice * listen_device,
int on = 1;
//struct sockaddr_in s_in;
struct hostent *ip_host ;
struct sockaddr_in s_in;
#ifdef __WIN32__
WSADATA wsaData;
#endif
memset(&s_in, 0, sizeof(struct sockaddr_in)) ;
if (!listen_device) {
TrickErrorHndlr *temp_error_hndlr = NULL;
trick_error_report(temp_error_hndlr, TRICK_ERROR_ALERT, __FILE__, __LINE__, "Listen device is null.");

View File

@ -16,7 +16,6 @@
#include "../include/tc.h"
#include "../include/tc_proto.h"
static struct sockaddr_in sockin;
#ifndef STAND_ALONE
extern int send_hs(FILE * fp, char *format, ...);
#endif
@ -30,6 +29,9 @@ int tc_init_udp_client(TCDevice * udp_client_device)
int on = 1;
struct hostent *h;
int the_socket;
struct sockaddr_in sockin;
memset(&sockin, 0 , sizeof(struct sockaddr_in)) ;
if (!udp_client_device) {
trick_error_report(udp_client_device->error_handler,