Browse code

milter: segv on error path

git-svn: trunk@4217

aCaB authored on 2008/10/02 02:02:52
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Oct  1 19:11:30 CEST 2008 (acab)
2
+------------------------------------
3
+  * clamav-milter/clamav-milter.c: fix error path segfault
4
+
1 5
 Tue Sep 30 18:28:28 CEST 2008 (acab)
2 6
 ------------------------------------
3 7
   * clamav-milter/clamav-milter.c: do not access _res when linking to a MT
... ...
@@ -2538,11 +2538,10 @@ findServer(void)
2538 2538
 
2539 2539
 		if(sock < 0) {
2540 2540
 			perror("socket");
2541
-			do {
2542
-				pthread_join(tids[i], NULL);
2541
+			while(i--) {
2543 2542
 				if(socks[i].sock >= 0)
2544 2543
 					close(socks[i].sock);
2545
-			} while(--i >= 0);
2544
+			}
2546 2545
 			free(socks);
2547 2546
 			free(servers);
2548 2547
 			free(tids);
... ...
@@ -2554,8 +2553,9 @@ findServer(void)
2554 2554
 
2555 2555
 		if(pthread_create(&tids[i], NULL, try_server, &socks[i]) != 0) {
2556 2556
 			perror("pthread_create");
2557
+			j = i;
2557 2558
 			do {
2558
-				pthread_join(tids[i], NULL);
2559
+				if (j!=i) pthread_join(tids[i], NULL);
2559 2560
 				if(socks[i].sock >= 0)
2560 2561
 					close(socks[i].sock);
2561 2562
 			} while(--i >= 0);