Skip to content
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

Remove memory leaks #186

Open
wants to merge 8 commits into
base: rolling
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/class_loader/class_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ std::string systemLibraryFormat(const std::string & library_name);
* @brief This class allows loading and unloading of dynamically linked libraries which contain class
* definitions from which objects can be created/destroyed during runtime (i.e. class_loader).
* Libraries loaded by a ClassLoader are only accessible within scope of that ClassLoader object.
* This class inherit from enable_shared_from_this which means we must used smart pointers,
* otherwise the code might work but it may run into a leak.
Comment on lines +78 to +79
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahcorde nit:

Suggested change
* This class inherit from enable_shared_from_this which means we must used smart pointers,
* otherwise the code might work but it may run into a leak.
* This class inherits from `std::enable_shared_from_this`. It should be instantiated using an `std::shared_ptr`.
* Code will otherwise work but memory may be leaked.

*/
class ClassLoader : public std::enable_shared_from_this<ClassLoader>
{
Expand Down Expand Up @@ -130,6 +132,8 @@ class ClassLoader : public std::enable_shared_from_this<ClassLoader>
std::bind(&ClassLoader::onPluginDeletion<Base>, shared_from_this(), std::placeholders::_1)
);
} catch (std::bad_weak_ptr & e) { // This is not a shared_ptr
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance "
"This class must be used with smart pointer");
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
return std::shared_ptr<Base>(
createRawInstance<Base>(derived_class_name, true),
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)
Expand Down Expand Up @@ -160,6 +164,8 @@ class ClassLoader : public std::enable_shared_from_this<ClassLoader>
std::bind(&ClassLoader::onPluginDeletion<Base>, shared_from_this(), std::placeholders::_1)
);
} catch (std::bad_weak_ptr & e) { // This is not a shared_ptr
CONSOLE_BRIDGE_logWarn("class_loader::ClassLoader::createUniqueInstance "
"This class must be used with smart pointer");
return std::unique_ptr<Base, DeleterType<Base>>(
raw,
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)
Expand Down