Fix: remove the leak protection entirely
This commit is contained in:
@@ -107,13 +107,15 @@ static int CopyToLStrHandle(LStrHandle handle, const std::string& str) noexcept
|
||||
extern "C" ANSLLM_API int CreateANSLLMHandle(ANSCENTER::ANSLLM** Handle, const char* licenseKey, int localLLM) {
|
||||
if (Handle == nullptr || licenseKey == nullptr) return 0;
|
||||
try {
|
||||
// Release existing handle if called twice (prevents leak from LabVIEW)
|
||||
if (*Handle) {
|
||||
if (UnregisterLLMHandle(*Handle)) {
|
||||
delete *Handle;
|
||||
}
|
||||
*Handle = nullptr;
|
||||
}
|
||||
// Pure constructor: ignore *Handle(in). LabVIEW's CLF Node marshalling
|
||||
// reuses the same temp buffer per call site, so *Handle(in) often holds
|
||||
// leftover bytes from the previous Create's output even when the actual
|
||||
// LabVIEW wire is a different, freshly-allocated instance. Inspecting
|
||||
// *Handle(in) and destroying what we "see" tears down legitimate
|
||||
// parallel instances. (Same reasoning as CreateANSAWSHandle.)
|
||||
// Trade-off: a true double-Create on the same wire leaks the prior
|
||||
// handle -- caller's bug; the alternative is far worse.
|
||||
*Handle = nullptr;
|
||||
|
||||
// std::unique_ptr ensures automatic cleanup on any failure path
|
||||
auto ptr = std::make_unique<ANSCENTER::ANSLLM>();
|
||||
|
||||
Reference in New Issue
Block a user