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
22 changes: 16 additions & 6 deletions include/class_loader/class_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ 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");
static bool create_instance_message = false;
if (!create_instance_message) {
CONSOLE_BRIDGE_logWarn(
"To createUniqueInstance() with a class_loader::ClassLoader "
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
"instance whose lifetime is not managed by an std::shared_ptr "
"is deprecated.");
create_instance_message = true;
}
return std::shared_ptr<Base>(
createRawInstance<Base>(derived_class_name, true),
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)
Expand Down Expand Up @@ -165,9 +170,14 @@ 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");
static bool create_unique_instance_message = false;
if (!create_unique_instance_message) {
CONSOLE_BRIDGE_logWarn(
"To createUniqueInstance() with a class_loader::ClassLoader "
"instance whose lifetime is not managed by an std::shared_ptr "
"is deprecated.");
create_unique_instance_message = true;
}
return std::unique_ptr<Base, DeleterType<Base>>(
raw,
std::bind(&ClassLoader::onPluginDeletion<Base>, this, std::placeholders::_1)
Expand Down