From 3ed93d048066eed234d89c48f5b63d7258ee731a Mon Sep 17 00:00:00 2001 From: ut000593 Date: Tue, 21 Dec 2021 14:47:30 +0800 Subject: [PATCH] =?UTF-8?q?chore(CI):=20amd=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E9=9C=B2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 单元测试内存泄露问题修改 Log: 内存释放错误 Change-Id: Ib5a86ea12a21b044e4d4ee9f8d81ac403a32d156 --- src/tessocrutils/tessocrutils.cpp | 13 ++++++++----- tests/tessocrutils/test_tessocrutils.cpp | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tessocrutils/tessocrutils.cpp b/src/tessocrutils/tessocrutils.cpp index 02c9fc1..ba4ee8d 100644 --- a/src/tessocrutils/tessocrutils.cpp +++ b/src/tessocrutils/tessocrutils.cpp @@ -273,17 +273,20 @@ RecognitionResult TessOcrUtils::getRecognizeResult(Pix * image,ResultType result try { //识别图片 + char* resultString = nullptr; switch (resultType) { case ResultType::RESULT_HTML: - result = QString(t_Tesseract->GetHOCRText(0)); + resultString = t_Tesseract->GetHOCRText(0); break; case ResultType::RESULT_STRING: - result = QString(t_Tesseract->GetUTF8Text()); + resultString = t_Tesseract->GetUTF8Text(); break; default: - result = QString(t_Tesseract->GetUTF8Text()); + resultString = t_Tesseract->GetUTF8Text(); break; } + result = QString(resultString); + delete [] resultString; } catch (const std::logic_error &e) { //errorMesage = "识别图片失败!" + QString(qExc.what()); errorMessage = "Image recognition failed! " + QString(e.what()); @@ -293,12 +296,12 @@ RecognitionResult TessOcrUtils::getRecognizeResult(Pix * image,ResultType result return t_result; } t_Tesseract->End(); - pixDestroy(&image); + //pixDestroy(&image); t_result.flag = true; t_result.message = errorMessage; t_result.errorCode = ErrorCode::OK; t_result.resultType = resultType; - t_result.result = result; + t_result.result = result.remove(QRegExp(" ")); // 去除识别结果中的空格字符串 m_isRunning = false; return t_result; } diff --git a/tests/tessocrutils/test_tessocrutils.cpp b/tests/tessocrutils/test_tessocrutils.cpp index 9336312..fbad0b1 100644 --- a/tests/tessocrutils/test_tessocrutils.cpp +++ b/tests/tessocrutils/test_tessocrutils.cpp @@ -112,6 +112,7 @@ TEST_F(TessOcrUtilsTest, getRecogitionResultImageAndResultType) EXPECT_EQ("", recognitionResult.message); EXPECT_EQ(ErrorCode::OK, recognitionResult.errorCode); EXPECT_EQ(resultType, recognitionResult.resultType); + delete t_image; //EXPECT_NE("", recognitionResult.result); } @@ -124,6 +125,7 @@ TEST_F(TessOcrUtilsTest, getRecogitionResultImage) EXPECT_EQ("", recognitionResult.message); EXPECT_EQ(ErrorCode::OK, recognitionResult.errorCode); EXPECT_EQ(ResultType::RESULT_STRING, recognitionResult.resultType); + delete t_image; //EXPECT_NE("", recognitionResult.result); } @@ -162,6 +164,7 @@ TEST_F(TessOcrUtilsTest, getRecognizeResult) EXPECT_EQ("", recognitionResult.message); EXPECT_EQ(ErrorCode::OK, recognitionResult.errorCode); EXPECT_EQ(ResultType::RESULT_STRING, recognitionResult.resultType); + delete image; } TEST_F(TessOcrUtilsTest, setLanguagesPath)