Fix: remove the leak protection entirely

This commit is contained in:
2026-04-18 20:51:50 +10:00
parent 247c91db50
commit 2de11c4b0c
6 changed files with 58 additions and 44 deletions

View File

@@ -322,13 +322,15 @@ namespace ANSCENTER
extern "C" ANSTRE_API int CreateANSTREHandle(ANSCENTER::ANSTRE** Handle, const char* licenseKey, const char* projectDirectory, const char* engineDirectory, const char* modelTemplateDirectory, const char* modelZipPassword, int trainingEngineType, int latestEngine) {
if (Handle == nullptr) return 0;
if (licenseKey == nullptr || projectDirectory == nullptr || engineDirectory == nullptr || modelTemplateDirectory == nullptr || modelZipPassword == nullptr) return 0;
// Release existing handle if called twice (prevents leak from LabVIEW)
if (*Handle) {
if (UnregisterTREHandle(*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;
try {
switch (trainingEngineType)
{