aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenjiro Nakayama <nakayamakenjiro@gmail.com>2026-05-04 13:27:54 +0900
committerKenjiro Nakayama <nakayamakenjiro@gmail.com>2026-05-04 13:36:54 +0900
commit374b05d111979d32e18cf7326463b69282966d1c (patch)
tree23ee439462d5f2a29053e16f54685673bc4a0740
parentb56b582a049d194a14064b36212f81645deeec22 (diff)
downloadportable-374b05d111979d32e18cf7326463b69282966d1c.tar.gz
portable-374b05d111979d32e18cf7326463b69282966d1c.tar.bz2
portable-374b05d111979d32e18cf7326463b69282966d1c.zip
clean up speed alarm from timer stop on Windows
The Windows speed alarm implementation owns thread and handle state that must be released after a benchmark run. Doing this from print_result() misses speed tests that report their results directly, which led to the leak reported in #1245. Release the Windows alarm resources from speed_timer_stop() after recording the elapsed time, so the cleanup follows the benchmark timer lifetime without affecting the measured result. Fix #1245
-rw-r--r--patches/speed.c.patch52
1 files changed, 30 insertions, 22 deletions
diff --git a/patches/speed.c.patch b/patches/speed.c.patch
index 8e79f5c..1c3b1bf 100644
--- a/patches/speed.c.patch
+++ b/patches/speed.c.patch
@@ -1,9 +1,9 @@
1--- apps/openssl/speed.c.orig 2026-04-12 11:09:28 1--- apps/openssl/speed.c.orig 2026-05-04 13:18:12
2+++ apps/openssl/speed.c 2026-04-12 11:11:18 2+++ apps/openssl/speed.c 2026-05-04 13:29:58
3@@ -156,7 +156,16 @@ static void print_result(int alg, int run_no, int coun 3@@ -158,7 +158,16 @@ static double speed_timer_stop(void);
4 pkey_print_message(const char *str, const char *str2,
5 int bits, int sec);
6 static void print_result(int alg, int run_no, int count, double time_used); 4 static void print_result(int alg, int run_no, int count, double time_used);
5 static void speed_timer_start(int seconds);
6 static double speed_timer_stop(void);
7+#ifndef _WIN32 7+#ifndef _WIN32
8 static int do_multi(int multi); 8 static int do_multi(int multi);
9+#else 9+#else
@@ -17,7 +17,23 @@
17 17
18 #define SIZE_NUM 5 18 #define SIZE_NUM 5
19 #define MAX_ECDH_SIZE 256 19 #define MAX_ECDH_SIZE 256
20@@ -1110,8 +1119,10 @@ speed_main(int argc, char **argv) 20@@ -1008,7 +1017,15 @@ speed_timer_stop(void)
21 static double
22 speed_timer_stop(void)
23 {
24+#ifndef _WIN32
25 return time_f(STOP);
26+#else
27+ double elapsed;
28+
29+ elapsed = time_f(STOP);
30+ speed_alarm_free(run);
31+ return elapsed;
32+#endif
33 }
34
35 static const int KDF1_SHA1_len = 20;
36@@ -1126,8 +1143,10 @@ speed_main(int argc, char **argv)
21 const EVP_CIPHER *evp_cipher = NULL; 37 const EVP_CIPHER *evp_cipher = NULL;
22 const EVP_MD *evp_md = NULL; 38 const EVP_MD *evp_md = NULL;
23 int decrypt = 0; 39 int decrypt = 0;
@@ -28,7 +44,7 @@
28 const char *errstr = NULL; 44 const char *errstr = NULL;
29 45
30 if (pledge("stdio proc", NULL) == -1) { 46 if (pledge("stdio proc", NULL) == -1) {
31@@ -1187,6 +1198,7 @@ speed_main(int argc, char **argv) 47@@ -1203,6 +1222,7 @@ speed_main(int argc, char **argv)
32 decrypt = 1; 48 decrypt = 1;
33 j--; /* Otherwise, -decrypt gets confused with an 49 j--; /* Otherwise, -decrypt gets confused with an
34 * algorithm. */ 50 * algorithm. */
@@ -36,7 +52,7 @@
36 } else if (argc > 0 && strcmp(*argv, "-multi") == 0) { 52 } else if (argc > 0 && strcmp(*argv, "-multi") == 0) {
37 argc--; 53 argc--;
38 argv++; 54 argv++;
39@@ -1201,6 +1213,7 @@ speed_main(int argc, char **argv) 55@@ -1217,6 +1237,7 @@ speed_main(int argc, char **argv)
40 } 56 }
41 j--; /* Otherwise, -multi gets confused with an 57 j--; /* Otherwise, -multi gets confused with an
42 * algorithm. */ 58 * algorithm. */
@@ -44,7 +60,7 @@
44 } else if (argc > 0 && strcmp(*argv, "-unaligned") == 0) { 60 } else if (argc > 0 && strcmp(*argv, "-unaligned") == 0) {
45 argc--; 61 argc--;
46 argv++; 62 argv++;
47@@ -1524,7 +1537,9 @@ speed_main(int argc, char **argv) 63@@ -1540,7 +1561,9 @@ speed_main(int argc, char **argv)
48 BIO_printf(bio_err, "-evp e use EVP e.\n"); 64 BIO_printf(bio_err, "-evp e use EVP e.\n");
49 BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n"); 65 BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n");
50 BIO_printf(bio_err, "-mr produce machine readable output.\n"); 66 BIO_printf(bio_err, "-mr produce machine readable output.\n");
@@ -54,7 +70,7 @@
54 BIO_printf(bio_err, "-unaligned n use buffers with offset n from proper alignment.\n"); 70 BIO_printf(bio_err, "-unaligned n use buffers with offset n from proper alignment.\n");
55 goto end; 71 goto end;
56 } 72 }
57@@ -1533,8 +1548,10 @@ speed_main(int argc, char **argv) 73@@ -1549,8 +1572,10 @@ speed_main(int argc, char **argv)
58 j++; 74 j++;
59 } 75 }
60 76
@@ -65,7 +81,7 @@
65 81
66 if (j == 0) { 82 if (j == 0) {
67 for (i = 0; i < ALGOR_NUM; i++) { 83 for (i = 0; i < ALGOR_NUM; i++) {
68@@ -1607,11 +1624,15 @@ speed_main(int argc, char **argv) 84@@ -1623,11 +1648,15 @@ speed_main(int argc, char **argv)
69 #define COND (run && count<0x7fffffff) 85 #define COND (run && count<0x7fffffff)
70 #define COUNT(d) (count) 86 #define COUNT(d) (count)
71 87
@@ -81,7 +97,7 @@
81 97
82 #ifndef OPENSSL_NO_MD4 98 #ifndef OPENSSL_NO_MD4
83 if (doit[D_MD4]) { 99 if (doit[D_MD4]) {
84@@ -2513,7 +2534,9 @@ speed_main(int argc, char **argv) 100@@ -2529,7 +2558,9 @@ speed_main(int argc, char **argv)
85 free(ss); 101 free(ss);
86 } 102 }
87 103
@@ -91,15 +107,7 @@
91 if (!mr) { 107 if (!mr) {
92 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION)); 108 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
93 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON)); 109 fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
94@@ -2695,11 +2718,15 @@ print_result(int alg, int run_no, int count, double ti 110@@ -2714,6 +2745,7 @@ print_result(int alg, int run_no, int count, double ti
95 static void
96 print_result(int alg, int run_no, int count, double time_used)
97 {
98+#ifdef _WIN32
99+ speed_alarm_free(run);
100+#endif
101 BIO_printf(bio_err, mr ? "+R:%d:%s:%f\n"
102 : "%d %s in %.2fs\n", count, names[alg], time_used);
103 results[alg][run_no] = ((double) count) / time_used * lengths[run_no]; 111 results[alg][run_no] = ((double) count) / time_used * lengths[run_no];
104 } 112 }
105 113
@@ -107,7 +115,7 @@
107 static char * 115 static char *
108 sstrsep(char **string, const char *delim) 116 sstrsep(char **string, const char *delim)
109 { 117 {
110@@ -2900,5 +2927,6 @@ do_multi(int multi) 118@@ -2914,5 +2946,6 @@ do_multi(int multi)
111 free(fds); 119 free(fds);
112 return 1; 120 return 1;
113 } 121 }