Forráskód Böngészése

Fix memory leak (#2348)

* Fix memory leak

* Fix flaky errors
yhirose 1 hónapja
szülő
commit
4e14bc8948
4 módosított fájl, 11 hozzáadás és 3 törlés
  1. 4 0
      .github/workflows/test.yaml
  2. 1 1
      test/Makefile
  3. 3 0
      test/lsan_suppressions.txt
  4. 3 2
      test/test.cc

+ 4 - 0
.github/workflows/test.yaml

@@ -95,6 +95,8 @@ jobs:
       - name: build and run tests (OpenSSL)
         if: matrix.tls_backend == 'openssl'
         run: cd test && make
+        env:
+          LSAN_OPTIONS: suppressions=lsan_suppressions.txt
       - name: build and run tests (Mbed TLS)
         if: matrix.tls_backend == 'mbedtls'
         run: cd test && make test_split_mbedtls && make test_mbedtls && ./test_mbedtls
@@ -122,6 +124,8 @@ jobs:
       - name: build and run tests (OpenSSL)
         if: matrix.tls_backend == 'openssl'
         run: cd test && make
+        env:
+          LSAN_OPTIONS: suppressions=lsan_suppressions.txt
       - name: build and run tests (Mbed TLS)
         if: matrix.tls_backend == 'mbedtls'
         run: cd test && make test_split_mbedtls && make test_mbedtls && ./test_mbedtls

+ 1 - 1
test/Makefile

@@ -54,7 +54,7 @@ STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \
 	$(wildcard example/*.h example/*.cc fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h))
 
 all : test test_split
-	./test
+	LSAN_OPTIONS=suppressions=lsan_suppressions.txt ./test
 
 proxy : test_proxy
 	@echo "Starting proxy server..."

+ 3 - 0
test/lsan_suppressions.txt

@@ -0,0 +1,3 @@
+# OpenSSL 3.x internal caches (provider, cipher, keymgmt) are allocated
+# lazily and intentionally kept until process exit. These are not real leaks.
+leak:libcrypto

+ 3 - 2
test/test.cc

@@ -4428,7 +4428,7 @@ TEST_F(ServerTest, TooLongRequest) {
 
   ASSERT_TRUE(res);
   EXPECT_EQ(StatusCode::UriTooLong_414, res->status);
-  EXPECT_LE(elapsed, 100);
+  EXPECT_LE(elapsed, 1000);
   EXPECT_EQ("close", res->get_header_value("Connection"));
   EXPECT_FALSE(cli_.is_socket_open());
 }
@@ -4513,7 +4513,7 @@ TEST_F(ServerTest, LongQueryValue) {
 
   ASSERT_TRUE(res);
   EXPECT_EQ(StatusCode::UriTooLong_414, res->status);
-  EXPECT_LE(elapsed, 100);
+  EXPECT_LE(elapsed, 1000);
   EXPECT_EQ("close", res->get_header_value("Connection"));
   EXPECT_FALSE(cli_.is_socket_open());
 }
@@ -15106,6 +15106,7 @@ TEST(BindServerTest, UpdateCerts) {
   ASSERT_TRUE(svr.is_valid());
   svr.stop();
 
+  X509_STORE_free(cert_store);
   X509_free(cert);
   X509_free(ca_cert);
   EVP_PKEY_free(key);