From 50e85c0312f790897032714212e445c5ba7ca95e Mon Sep 17 00:00:00 2001 From: daizihan Date: Mon, 21 Jul 2025 16:26:21 +0800 Subject: [PATCH] Fix memory leak bug Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICNQHF?from=project-issue Signed-off-by: daizihan --- .../test/ast/compiler/ets/memory_leak.ets | 20 +++++++++++++++++++ ets2panda/util/importPathManager.cpp | 2 +- ets2panda/util/importPathManager.h | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/memory_leak.ets diff --git a/ets2panda/test/ast/compiler/ets/memory_leak.ets b/ets2panda/test/ast/compiler/ets/memory_leak.ets new file mode 100644 index 0000000000..aaadb00d6e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/memory_leak.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { A } from "dynamic_import_tests" + +function main() {} + +/* @@? 16:19 Error TypeError: Cannot find import: dynamic_import_tests */ diff --git a/ets2panda/util/importPathManager.cpp b/ets2panda/util/importPathManager.cpp index 9b64cc0f4b..9aec650c18 100644 --- a/ets2panda/util/importPathManager.cpp +++ b/ets2panda/util/importPathManager.cpp @@ -75,7 +75,7 @@ void ImportPathManager::ProcessExternalModuleImport(ImportMetadata &importData) // process emptry "path" in dependencies, since in interop we allow imports without typecheck if (!Helpers::EndsWith(std::string(externalModuleImportData.Path()), ".abc")) { importData.importFlags |= ImportFlags::EXTERNAL_SOURCE_IMPORT; - importData.ohmUrl = externalModuleImportData.OhmUrl(); + importData.ohmUrl = UString(std::string(externalModuleImportData.OhmUrl()), allocator_).View().Utf8(); return; } diff --git a/ets2panda/util/importPathManager.h b/ets2panda/util/importPathManager.h index 04c4742836..7f3a4f5f31 100644 --- a/ets2panda/util/importPathManager.h +++ b/ets2panda/util/importPathManager.h @@ -83,7 +83,7 @@ public: Language::Id lang {Language::Id::COUNT}; std::string_view resolvedSource {}; std::string_view declPath {}; - std::string ohmUrl {}; + std::string_view ohmUrl {}; std::string declText {}; // NOLINTEND(misc-non-private-member-variables-in-classes) -- Gitee