From 471a393ac972187f90a742c62f9a1e73991ac36f Mon Sep 17 00:00:00 2001 From: Roman Ellerbrock Date: Wed, 31 May 2023 18:19:34 +0200 Subject: [PATCH 1/2] Added check on whether buffer is null in simplified fock routine that can lead to memory leaks. --- tests/hartree-fock/hartree-fock.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/hartree-fock/hartree-fock.cc b/tests/hartree-fock/hartree-fock.cc index 8fa4ec19d..800cec4a1 100644 --- a/tests/hartree-fock/hartree-fock.cc +++ b/tests/hartree-fock/hartree-fock.cc @@ -651,6 +651,9 @@ Matrix compute_2body_fock_simple(const std::vector& shells, // exchange contribution to the Fock matrix is from {s1,s3,s2,s4} integrals engine.compute(shells[s1], shells[s3], shells[s2], shells[s4]); const auto* buf_1324 = buf[0]; + if (buf_1234 == nullptr) + continue; // if all integrals screened out, skip to next quartet + for(auto f1=0, f1324=0; f1!=n1; ++f1) { const auto bf1 = f1 + bf1_first; From 56d2bf73860268c522793ebb177e491a360cb2c0 Mon Sep 17 00:00:00 2001 From: Roman Ellerbrock Date: Wed, 31 May 2023 18:25:58 +0200 Subject: [PATCH 2/2] Added check buffer in simplified fock routine to avoid memory leaks. buffer_1324 can be null and the loop after it can crash. Using the simplified fock routine for benzene in reference geometry in sto-3G can reproduce the bug. --- tests/hartree-fock/hartree-fock.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hartree-fock/hartree-fock.cc b/tests/hartree-fock/hartree-fock.cc index 800cec4a1..0229fd866 100644 --- a/tests/hartree-fock/hartree-fock.cc +++ b/tests/hartree-fock/hartree-fock.cc @@ -651,7 +651,7 @@ Matrix compute_2body_fock_simple(const std::vector& shells, // exchange contribution to the Fock matrix is from {s1,s3,s2,s4} integrals engine.compute(shells[s1], shells[s3], shells[s2], shells[s4]); const auto* buf_1324 = buf[0]; - if (buf_1234 == nullptr) + if (buf_1324 == nullptr) continue; // if all integrals screened out, skip to next quartet