From 18e9fd43fc2a5d034e5ff7a8f79e9c6a55e195cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20DAVID?= Date: Tue, 18 May 2021 09:53:15 +0200 Subject: [PATCH] * Bug 15330 fixed: spec.tst was crashing on Linux https://bugzilla.scilab.org/show_bug.cgi?id=15330 After lapack source code read, zgeev.f need rwork storage for detecting its work sizes. Other memory leaks have also been fixed in this commit. Change-Id: I8c90ce927caea264def831a484ab7a2173c3a46a --- scilab/CHANGES.md | 1 + .../linear_algebra/sci_gateway/cpp/sci_spec.cpp | 14 +++++++++++++- scilab/modules/linear_algebra/src/c/eigen.c | 5 +++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 3e7bdf5..b5c3edd 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -367,6 +367,7 @@ Bug Fixes * [#15163](https://bugzilla.scilab.org/15163): `getdate` page: The time referential was obscure: a) UTC for Unix Time Convention vs Coordinated Universal Time. b) unclear influence of the time zone. * [#15226](https://bugzilla.scilab.org/15226): The `get` page needed to be overhauled: `get(0)`, `get(0,prop)`, `get(tag)`, `get(tag,prop)` and other features were not documented. * [#15280](https://bugzilla.scilab.org/15280): `gsort` was unable to sort any hypermatrix along dimensions > "r"|"c". +* [#15330](https://bugzilla.scilab.org/15330): spec.tst was crashing on Linux. * [#15839](https://bugzilla.scilab.org/15839): `gsort`: the only sparse possible input were real or complex vectors, and only with the `g` method. * [#15841](https://bugzilla.scilab.org/15841): `intersect` did not support neither sparse boolean nor sparse numeric inputs. * [#15842](https://bugzilla.scilab.org/15842): `unique` could not process 2D sparse matrices. diff --git a/scilab/modules/linear_algebra/sci_gateway/cpp/sci_spec.cpp b/scilab/modules/linear_algebra/sci_gateway/cpp/sci_spec.cpp index 468e0c9..ca038ab 100644 --- a/scilab/modules/linear_algebra/sci_gateway/cpp/sci_spec.cpp +++ b/scilab/modules/linear_algebra/sci_gateway/cpp/sci_spec.cpp @@ -163,12 +163,12 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ if (_iRetCount == 2) { vGetPointerFromDoubleComplex((doublecomplex*)pDataA, pDblA->getSize(), pDblEigenVectors->getReal(), pDblEigenVectors->getImg()); - vFreeDoubleComplexFromPointer((doublecomplex*)pDataA); expandToDiagonalOfMatrix(pDblEigenValues->getReal(), pDblA->getCols()); out.push_back(pDblEigenVectors); } out.push_back(pDblEigenValues); pDblA->killMe(); + vFreeDoubleComplexFromPointer((doublecomplex*)pDataA); } else // not symmetric { @@ -228,6 +228,10 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ if (_iRetCount == 2) { + if (pDblEigenVectors) + { + pDblEigenVectors->killMe(); + } expandToDiagonalOfMatrix(pDblEigenValues->getReal(), pDblA->getCols()); out.push_back(pDblA); } @@ -245,6 +249,10 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ if (iRet < 0) { pDblA->killMe(); + if (pDblEigenVectors) + { + pDblEigenVectors->killMe(); + } Scierror(998, _("%s: On entry to ZHEEV parameter number 3 had an illegal value (lapack library problem).\n"), "spec"); return types::Function::Error; } @@ -252,6 +260,10 @@ types::Function::ReturnValue sci_spec(types::typed_list &in, int _iRetCount, typ if (iRet > 0) { pDblA->killMe(); + if (pDblEigenVectors) + { + pDblEigenVectors->killMe(); + } Scierror(24, _("%s: The QR algorithm failed to compute all the eigenvalues, and no eigenvectors have been computed. Elements and %d+1:N of WR and WI contain eigenvalues which have converged.\n"), "spec", iRet); return types::Function::Error; } diff --git a/scilab/modules/linear_algebra/src/c/eigen.c b/scilab/modules/linear_algebra/src/c/eigen.c index 9257722..1ff3816 100644 --- a/scilab/modules/linear_algebra/src/c/eigen.c +++ b/scilab/modules/linear_algebra/src/c/eigen.c @@ -98,8 +98,9 @@ static int zheevWorkSizes(int iCols, int* optWorkSize, int* minWorkSize) static int zgeevWorkSizes(int iCols, int lhs, int* optWorkSize, int* minWorkSize) { int info = 0, query = -1; + double rwork; doublecomplex opt; - C2F(zgeev)("N", (lhs == 1 ? "N" : "V"), &iCols, NULL, &iCols, NULL, NULL, &iCols, NULL, &iCols, &opt, &query, NULL, &info ); + C2F(zgeev)("N", (lhs == 1 ? "N" : "V"), &iCols, NULL, &iCols, NULL, NULL, &iCols, NULL, &iCols, &opt, &query, &rwork, &info ); *optWorkSize = (int)opt.r; *minWorkSize = Max(1, 2 * iCols); return info; @@ -119,7 +120,7 @@ static int dgeevWorkSizes(int iCols, int lhs, int* optWorkSize, int* minWorkSize { int info = 0, query = -1; double opt; - C2F(dgeev)("N", "N", &iCols, NULL, &iCols, NULL, NULL, NULL, &iCols, NULL, &iCols, &opt, &query, &info); + C2F(dgeev)("N", (lhs == 1 ? "N" : "V"), &iCols, NULL, &iCols, NULL, NULL, NULL, &iCols, NULL, &iCols, &opt, &query, &info); *optWorkSize = (int)opt; *minWorkSize = (lhs == 2) ? Max(1, 4 * iCols) : Max(1, 3 * iCols); -- 1.7.9.5