projectbismark/bismark-measurement-server — Issue #3: Apply memleak.patch to DITG
Author: woodrow
Created: 2012-02-29 23:04:48+00:00
State: open

```diff
diff -crB /tmp/D-ITG-2.8.0-rc1/src//common/thread.cpp src//common/thread.cpp
*** /tmp/D-ITG-2.8.0-rc1/src//common/thread.cpp	2011-08-07 13:27:49.000000000 +0200
--- src//common/thread.cpp	2011-01-12 00:00:18.000000000 +0100
***************
*** 43,52 ****
int ret = 0;
#ifdef WIN32

!	void *pid;

idThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) nameFunction, argument,
!	(DWORD) NULL, (unsigned long *)&pid);
PRINTD(3,"createThread: Return value CreateThread (WIN32) %lu\n",(unsigned long int)idThread);
if (idThread == NULL) ret = -1;
PRINTD(3,"createThread: Return value CreateThread: %d\n",ret);
--- 43,52 ----
int ret = 0;
#ifdef WIN32

!	LPDWORD pid = 0;

idThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) nameFunction, argument,
!	(DWORD) NULL, pid);
PRINTD(3,"createThread: Return value CreateThread (WIN32) %lu\n",(unsigned long int)idThread);
if (idThread == NULL) ret = -1;
PRINTD(3,"createThread: Return value CreateThread: %d\n",ret);
***************
*** 57,62 ****
--- 57,63 ----

ret = pthread_create(&idThread, NULL, nameFunction, argument);
if (ret != 0) ret = -1;
+	pthread_detach(idThread);
PRINTD(3,"createThread: Return value pthread_create (LINUX) %lu\n",(unsigned long int)idThread);
PRINTD(3,"createThread: Return value createThread : %d\n",ret);
#endif
diff -crB /tmp/D-ITG-2.8.0-rc1/src//common/thread.h src//common/thread.h
*** /tmp/D-ITG-2.8.0-rc1/src//common/thread.h	2011-08-07 13:27:49.000000000 +0200
--- src//common/thread.h	2011-01-12 00:00:18.000000000 +0100
***************
*** 29,95 ****

#ifdef WIN32
! #include
! #include
! #include
!
! typedef HANDLE pthread_t;
! extern char nameProgram[];

#endif

#ifdef LINUX_OS
! #include
! #include
! #include
#endif

#ifdef WIN32

! #define MUTEX_THREAD_LOCK(a) \
!	mutexThreadLock(a)
!
!
! #define MUTEX_THREAD_UNLOCK(a) \
!	mutexThreadUnlock(a)
!
!
! #define MUTEX_THREAD_RELEASE(a) \
!	mutexThreadRelease(a)
!

- #define CREATE_THREAD(a,b,c,d) \
-	createThread(a,b,c,d)

! #define MUTEX_THREAD_INIT(a) \
!	mutexThreadInit(a)

#endif

#ifdef LINUX_OS

- #define MUTEX_THREAD_LOCK(a) \
-	mutexThreadLock(&a)
-
-
- #define MUTEX_THREAD_UNLOCK(a) \
-	mutexThreadUnlock(&a)
-
-
- #define MUTEX_THREAD_RELEASE(a) \
-	mutexThreadRelease(&a)
-
-
- #define CREATE_THREAD(a,b,c,d) \
-	createThread(a,b,c,d)

! #define MUTEX_THREAD_INIT(a) \
!	mutexThreadInit(&a)

#endif

--- 29,97 ----

#ifdef WIN32
! #	include
! #	include
! #	include
!
!	typedef HANDLE pthread_t;
!	extern char nameProgram[];

#endif

#ifdef LINUX_OS
! #	include
! #	include
! #	include
#endif

#ifdef WIN32
+
+ #	define MUTEX_THREAD_LOCK(a) \
+	mutexThreadLock(a)

!
! #	define MUTEX_THREAD_UNLOCK(a) \
!	mutexThreadUnlock(a)

+ #	define MUTEX_THREAD_RELEASE(a) \
+	mutexThreadRelease(a)

!
! #	define CREATE_THREAD(a,b,c,d) \
!	createThread(a,b,c,d)
!
!
! #	define MUTEX_THREAD_INIT(a) \
!	mutexThreadInit(a)

+
+ #	define pthread_cleanup_push(a,b)
+ #	define pthread_cleanup_pop(a)
#endif

#ifdef LINUX_OS
+
+ #	define MUTEX_THREAD_LOCK(a) \
+	mutexThreadLock(&a)

+ #	define MUTEX_THREAD_UNLOCK(a) \
+	mutexThreadUnlock(&a)

!
! #	define MUTEX_THREAD_RELEASE(a) \
!	mutexThreadRelease(&a)

+
+ #	define CREATE_THREAD(a,b,c,d) \
+	createThread(a,b,c,d)
+
+
+ #	define MUTEX_THREAD_INIT(a) \
+	mutexThreadInit(&a)
#endif

diff -crB /tmp/D-ITG-2.8.0-rc1/src//ITGRecv/data.cpp src//ITGRecv/data.cpp
*** /tmp/D-ITG-2.8.0-rc1/src//ITGRecv/data.cpp	2011-08-07 13:27:49.000000000 +0200
--- src//ITGRecv/data.cpp	2011-01-12 00:00:18.000000000 +0100
***************
*** 74,80 ****

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) malloc(DIM * sizeof(info));

struct addrinfo SrcAddress;

--- 74,80 ----

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) calloc(DIM, sizeof(info));

struct addrinfo SrcAddress;

***************
*** 108,118 ****

paraThread->count = 0;

!	if (strcmp(paraThread->serial,"noSerial")!=0) {
hComm = serialUp(paraThread->serial);
! if (hComm == INVALID_HANDLE_VALUE)
! printf("Error opening interface %s \n", paraThread->serial);
! }

sock = socket(paraThread->destHost.ai_family, SOCK_RAW,
--- 108,118 ----

paraThread->count = 0;

!	if (strcmp(paraThread->serial, "noSerial") != 0) {
hComm = serialUp(paraThread->serial);
!	if (hComm == INVALID_HANDLE_VALUE)
!	printf("Error opening interface %s \n", paraThread->serial);
!	}

sock = socket(paraThread->destHost.ai_family, SOCK_RAW,
***************
*** 187,192 ****
--- 187,194 ----
dimheader = sizeof(icmpv6);
}

+	pthread_cleanup_push(free, SrcAddress.ai_addr);
+
int firstpacket = 1;
char HelpSrcAddress[INET6_ADDRSTRLEN];
char HelpDstAddress[INET6_ADDRSTRLEN];
***************
*** 219,225 ****

memcpy(&payload, ptr, size_r);

!	if (hComm != INVALID_HANDLE_VALUE){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
--- 221,227 ----

memcpy(&payload, ptr, size_r);

!	if (hComm > 0){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
***************
*** 291,296 ****
--- 293,300 ----
}
}
}
+
+	pthread_cleanup_pop(1);
return NULL;
}

***************
*** 316,322 ****

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) malloc(DIM * sizeof(info));

struct addrinfo SrcAddress;

--- 320,326 ----

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) calloc(DIM, sizeof(info));

struct addrinfo SrcAddress;

***************
*** 348,355 ****

if (strcmp(paraThread->serial,"noSerial")!=0) {
hComm = serialUp(paraThread->serial);
! if (hComm == INVALID_HANDLE_VALUE)
! printf("Error opening interface %s \n", paraThread->serial);
}

bool socketAlreadyOpen = false;
--- 352,359 ----

if (strcmp(paraThread->serial,"noSerial")!=0) {
hComm = serialUp(paraThread->serial);
!	if (hComm == INVALID_HANDLE_VALUE)
!	printf("Error opening interface %s \n", paraThread->serial);
}

bool socketAlreadyOpen = false;
***************
*** 534,540 ****
SrcAddress.ai_addrlen = sizeof(struct sockaddr_in6);
}

!

int firstpacket = 1;
char HelpSrcAddress[INET6_ADDRSTRLEN];
--- 538,544 ----
SrcAddress.ai_addrlen = sizeof(struct sockaddr_in6);
}

!	pthread_cleanup_push(free, SrcAddress.ai_addr);

int firstpacket = 1;
char HelpSrcAddress[INET6_ADDRSTRLEN];
***************
*** 563,569 ****
reportErrorAndExit("udpSock","recvfrom","Cannot receive UDP packets");
}

!	if (hComm != INVALID_HANDLE_VALUE){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
--- 567,573 ----
reportErrorAndExit("udpSock","recvfrom","Cannot receive UDP packets");
}

!	if (hComm > 0){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
***************
*** 664,669 ****
--- 668,674 ----
PRINTD(2,"udpSock: Sent RTTM message\n");
}
}
+	pthread_cleanup_pop(1);
return NULL;
}

***************
*** 691,697 ****

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) malloc(DIM * sizeof(info));

struct addrinfo SrcAddress;

--- 696,702 ----

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) calloc(DIM, sizeof(info));

struct addrinfo SrcAddress;

***************
*** 847,852 ****
--- 852,859 ----
SrcAddress.ai_addrlen = sizeof(struct sockaddr_in6);
}

+	pthread_cleanup_push(free, SrcAddress.ai_addr);
+
if (passiveMode == false){

***************
*** 937,979 ****
PRINTD(1,"tcpSock: main loop\n");

while (1) {
!
PRINTD(2, "tcpSock: preambleSize = %d \n",paraThread->preambleSize);
! size=TCPrecvPacket((unsigned char*)payload,newSock,paraThread->preambleSize,paraThread->payloadLogType);

!
! if (size <= 0){
!	PRINTD(1,"tcpSock: TCPrecvPacket() = %d\n",size);
!
!	if (size < 0){
!
!	struct pipeMsg msg;
!
!	if(passiveMode==false){
!	GET_PORT((&(paraThread->destHost)), tmpPort_DstPort);
!	}else{
!	GET_PORT((&SrcAddress), tmpPort_DstPort);
!	}
!	printf("Error on TCP port : %d\n", ntohs(tmpPort_DstPort));
!	printf("Finish on TCP port : %d\n\n", ntohs(tmpPort_DstPort));
!	fflush(stdout);
!
!	msg.code = MSG_FT_ERR_SOCK;
!	msg.flowId = paraThread->flowId;
!	if (sendPipeMsg(paraThread->rPipe, &msg) < 0) {
!	printf(" sending msg error");
!	}
!	}
!	sleep(INFINITE);
! }
!
! if (hComm != INVALID_HANDLE_VALUE){
! DTR_Disable(hComm);
! DTR_Enable(hComm);
! }

!
! GET_TIME_OF_DAY(&RcvTime, _tend, _tstart, secs, msecs, 0, RECEIVER);

--- 944,986 ----
PRINTD(1,"tcpSock: main loop\n");

while (1) {
!
PRINTD(2, "tcpSock: preambleSize = %d \n",paraThread->preambleSize);
!	size=TCPrecvPacket((unsigned char*)payload,newSock,paraThread->preambleSize,paraThread->payloadLogType);

!
!	if (size <= 0){
!	PRINTD(1,"tcpSock: TCPrecvPacket() = %d\n",size);
!
!	if (size < 0){
!
!	struct pipeMsg msg;
!
!	if(passiveMode==false){
!	GET_PORT((&(paraThread->destHost)), tmpPort_DstPort);
!	}else{
!	GET_PORT((&SrcAddress), tmpPort_DstPort);
!	}
!	printf("Error on TCP port : %d\n", ntohs(tmpPort_DstPort));
!	printf("Finish on TCP port : %d\n\n", ntohs(tmpPort_DstPort));
!	fflush(stdout);
!
!	msg.code = MSG_FT_ERR_SOCK;
!	msg.flowId = paraThread->flowId;
!	if (sendPipeMsg(paraThread->rPipe, &msg) < 0) {
!	printf(" sending msg error");
!	}
!	}
!	sleep(INFINITE);
!	}
!
!	if (hComm > 0){
!	DTR_Disable(hComm);
!	DTR_Enable(hComm);
!	}

!
!	GET_TIME_OF_DAY(&RcvTime, _tend, _tstart, secs, msecs, 0, RECEIVER);

***************
*** 1062,1067 ****
--- 1069,1075 ----
PRINTD(2,"tcpSock: Sent RTTM infos\n");
}
}
+	pthread_cleanup_pop(1);
return NULL;
}

***************
*** 1075,1081 ****
int first = 1;
#endif

! HANDLE hComm;

paramThread *paraThread;
--- 1083,1089 ----
int first = 1;
#endif

! HANDLE hComm = 0;

paramThread *paraThread;
***************
*** 1089,1095 ****

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) malloc(DIM * sizeof(info));

struct addrinfo SrcAddress;

--- 1097,1103 ----

unsigned char payload[MAX_PAYLOAD_SIZE];

!	struct info *infos = (struct info *) calloc(DIM, sizeof(info));

struct addrinfo SrcAddress;

***************
*** 1232,1237 ****
--- 1240,1247 ----
SrcAddress.ai_addrlen = sizeof(struct sockaddr_in6);
}

+	pthread_cleanup_push(free, SrcAddress.ai_addr);
+

if ((newSock = accept(sock, SrcAddress.ai_addr, (socklen_t *) & SrcAddress.ai_addrlen)) < 0)
***************
*** 1265,1271 ****
size = SCTPrecvPacket ((unsigned char*)payload, newSock, sctpId, paraThread->preambleSize, paraThread->payloadLogType);
PRINTD(2,"sctpSock: Received SCTP data. Size of the received data chinck: %d\n",size);

! if (hComm != INVALID_HANDLE_VALUE){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
--- 1275,1281 ----
size = SCTPrecvPacket ((unsigned char*)payload, newSock, sctpId, paraThread->preambleSize, paraThread->payloadLogType);
PRINTD(2,"sctpSock: Received SCTP data. Size of the received data chinck: %d\n",size);

! if (hComm > 0){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
***************
*** 1348,1353 ****
--- 1358,1365 ----
PRINTD(2,"sctpSock: Sent RTTM infos\n");
}
}
+
+	pthread_cleanup_pop(1);
return NULL;
}
#endif
***************
*** 1356,1366 ****
void *dccpSock(void *param)
{
PRINTD(1,"dccpSock: dccpSock started\n");
!	HANDLE hComm;
int sock = 0;
int sendCheck = 0;
unsigned char payload[MAX_PAYLOAD_SIZE];
!	struct info *infos = (struct info *) malloc(DIM * sizeof(info));
struct addrinfo SrcAddress;
in_port_t tmpPort = 0;
int newSock = 0;
--- 1368,1378 ----
void *dccpSock(void *param)
{
PRINTD(1,"dccpSock: dccpSock started\n");
!	HANDLE hComm = 0;
int sock = 0;
int sendCheck = 0;
unsigned char payload[MAX_PAYLOAD_SIZE];
!	struct info *infos = (struct info *) calloc(DIM, sizeof(info));
struct addrinfo SrcAddress;
in_port_t tmpPort = 0;
int newSock = 0;
***************
*** 1430,1436 ****
} else if (SrcAddress.ai_family == PF_INET6) {
SrcAddress.ai_addr = (struct sockaddr *) malloc(sizeof(struct sockaddr_in6));
SrcAddress.ai_addrlen = sizeof(struct sockaddr_in6);
!	}
if ((newSock = accept(sock, SrcAddress.ai_addr, (socklen_t *) & SrcAddress.ai_addrlen)) < 0)
reportErrorAndExit("dccpSock","accept","Cannot accept connection");
if ( closeSock(sock) == -1)
--- 1442,1451 ----
} else if (SrcAddress.ai_family == PF_INET6) {
SrcAddress.ai_addr = (struct sockaddr *) malloc(sizeof(struct sockaddr_in6));
SrcAddress.ai_addrlen = sizeof(struct sockaddr_in6);
!	}
!
!	pthread_cleanup_push(free, SrcAddress.ai_addr);
!
if ((newSock = accept(sock, SrcAddress.ai_addr, (socklen_t *) & SrcAddress.ai_addrlen)) < 0)
reportErrorAndExit("dccpSock","accept","Cannot accept connection");
if ( closeSock(sock) == -1)
***************
*** 1449,1455 ****
reportErrorAndExit("udpSock","recvfrom","Cannot receive UDP packets");
else if (size>0) {
PRINTD(2,"dccpSock: Received DCCP packet, size %d\n", size);
!	if (hComm != INVALID_HANDLE_VALUE){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
--- 1464,1470 ----
reportErrorAndExit("udpSock","recvfrom","Cannot receive UDP packets");
else if (size>0) {
PRINTD(2,"dccpSock: Received DCCP packet, size %d\n", size);
!	if (hComm > 0){
DTR_Disable(hComm);
DTR_Enable(hComm);
}
***************
*** 1525,1530 ****
--- 1540,1546 ----
}
}
}
+	pthread_cleanup_pop(1);
return NULL;
}
#endif
diff -crB /tmp/D-ITG-2.8.0-rc1/src//ITGRecv/ITGRecv.cpp src//ITGRecv/ITGRecv.cpp
*** /tmp/D-ITG-2.8.0-rc1/src//ITGRecv/ITGRecv.cpp	2011-08-07 13:27:49.000000000 +0200
--- src//ITGRecv/ITGRecv.cpp	2011-01-12 00:00:18.000000000 +0100
***************
*** 1640,1648 ****

numFlow++;
} else
reportErrorAndExit("typeParser", "flowPosition", "Too many thread");
!
} else if (type == TSP_CLOSED_FLOW) {

PRINTD(1,"typeParser: Received TSP_CLOSED_FLOW(4) message\n");
--- 1640,1649 ----

numFlow++;
+	free(ptrIP);
} else
reportErrorAndExit("typeParser", "flowPosition", "Too many thread");
!
} else if (type == TSP_CLOSED_FLOW) {

PRINTD(1,"typeParser: Received TSP_CLOSED_FLOW(4) message\n");
***************
*** 1800,1805 ****
--- 1801,1807 ----

free(paraThread[k].addressInfos);
+	free(paraThread[k].destHost.ai_addr);
paraThread[k].addressInfos = NULL;

flowIdNum[k].flowId = -1;
```