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

@@ -191,14 +191,21 @@ BOOL APIENTRY DllMain( HMODULE hModule,
return TRUE;
}
// Pure constructor: every call allocates a brand-new ANSUtilities and writes it
// to *Handle. *Handle(in) is ignored completely -- LabVIEW's CLF Node marshalling
// reuses the same temp buffer per call site, so *Handle(in) often contains
// leftover bytes from the previous Create's output even when the actual LabVIEW
// wire is a different, freshly-allocated instance. Inspecting *Handle(in) for
// "is this live?" detection cannot distinguish that case from a genuine
// double-Create-on-same-wire, so we don't try -- we trust the caller.
//
// Trade-off: if a caller really does call Create twice on the same wire without
// Release, the first handle leaks. That is the caller's bug. The alternative
// (releasing live objects we "see" in the input) destroys legitimate parallel
// instances and is far worse. (Same reasoning as CreateANSAWSHandle.)
extern "C" ANSULT_API int CreateANSUtilityHandle(ANSCENTER::ANSUtilities** Handle, const char* licenseKey) {
if (Handle == nullptr || licenseKey == nullptr) return 0;
if (*Handle) {
if (UnregisterUtilHandle(*Handle)) {
delete *Handle;
}
*Handle = nullptr;
}
*Handle = nullptr;
try {
*Handle = new ANSCENTER::ANSUtilities();
if (*Handle == nullptr) return 0;