Skip to content

Commit

Permalink
Use std::unique_ptr for storing temp script code in JavaVMTest::run i…
Browse files Browse the repository at this point in the history
…n order to avoid memory leak if exception in SWIGVMContainers::JavaVMImpl::JavaVMImpl() occurs.
  • Loading branch information
tomuben committed Oct 21, 2024
1 parent 8bd7b72 commit 1691e48
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions exaudfclient/base/javacontainer/test/cpp/javavm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ JavaVMTest::JavaVMTest(std::string scriptCode, std::unique_ptr<SwigFactoryTestIm
}

void JavaVMTest::run(std::string scriptCode, std::unique_ptr<SwigFactoryTestImpl> swigFactory) {
char* script_code = ::strdup(scriptCode.c_str());
SWIGVMContainers::SWIGVM_params->script_code = script_code;
std::unique_ptr<char*> script_code = ::strdup(scriptCode.c_str());
SWIGVMContainers::SWIGVM_params->script_code = script_code.get();
#ifndef USE_CTPG_PARSER
std::unique_ptr<SWIGVMContainers::JavaScriptOptions::ScriptOptionLinesParserLegacy> parser =
std::make_unique<SWIGVMContainers::JavaScriptOptions::ScriptOptionLinesParserLegacy>(std::move(swigFactory));
Expand All @@ -35,6 +35,5 @@ void JavaVMTest::run(std::string scriptCode, std::unique_ptr<SwigFactoryTestImpl
javaVMInternalStatus.m_classpath = javaVMImpl.m_classpath;
javaVMInternalStatus.m_jvmOptions = javaVMImpl.m_jvmOptions;
javaVMInternalStatus.m_needsCompilation = javaVMImpl.m_needsCompilation;
::free(script_code);
}

0 comments on commit 1691e48

Please sign in to comment.