-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix factory map leak (#131) #179
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -57,8 +57,26 @@ std::recursive_mutex & getPluginBaseToFactoryMapMapMutex() | |||
|
||||
BaseToFactoryMapMap & getGlobalPluginBaseToFactoryMapMap() | ||||
{ | ||||
static BaseToFactoryMapMap instance; | ||||
return instance; | ||||
|
||||
static std::shared_ptr<BaseToFactoryMapMap> instance; | ||||
|
||||
// TODO: need lock? | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @y-okumura-isp perhaps, static initialization is not thread-safe either. |
||||
// TODO: we may use unique_ptr but use shared_ptr for PoC | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @y-okumura-isp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for comment. I have one confirmation.
What you say is to change
to
Right? The pointer
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Correct.
I presume you mean
|
||||
if(instance == nullptr) { | ||||
instance = std::shared_ptr<BaseToFactoryMapMap>( | ||||
new BaseToFactoryMapMap, | ||||
[](BaseToFactoryMapMap *p) mutable | ||||
{ | ||||
for(auto it_map: *p) { | ||||
for(auto it: it_map.second) { | ||||
if(it.second) { | ||||
delete(it.second); | ||||
} | ||||
} | ||||
} | ||||
}); | ||||
} | ||||
return *instance; | ||||
} | ||||
|
||||
FactoryMap & getFactoryMapForBaseClass(const std::string & typeid_base_class_name) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@y-okumura-isp meta: the comment is rather imprecise. Lacking
virtual
indeed breaks polymorphic destruction.