szaszm commented on code in PR #2121:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2121#discussion_r2854422795


##########
libminifi/src/core/extension/ExtensionManager.cpp:
##########
@@ -86,4 +87,14 @@ ExtensionManager::ExtensionManager(const 
std::shared_ptr<Configure>& config): lo
   }
 }
 
+ExtensionManager::~ExtensionManager() {
+  // Extensions must be destroyed before clearing the registry,
+  // because DLL static destructors (StaticClassType) may still reference
+  // the registry during DLL unload.
+  extensions_.clear();
+  // Clear the class description registry to avoid dangling pointers
+  // to validator objects that lived in the now-unloaded extension DLLs.
+  minifi::ClassDescriptionRegistry::clearClassDescriptions();

Review Comment:
   Maybe it would be better to swap these two, so dangling pointers are not 
even held in memory. Especially if another thread may try to read into the 
global class descriptions, and end up dereferencing them.
   
   Speaking of threads, that global std::map is not synchronized, so accessing 
it from multiple threads must be UB. Is it possible that C2 is doing that when 
generating a heartbeat?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to