Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions xacc/service/xacc_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ using namespace cxxopts;
namespace xacc {
// class ServiceRegistry;
bool serviceAPIInitialized = false;
std::shared_ptr<ServiceRegistry> serviceRegistry =
std::make_shared<ServiceRegistry>();
std::unique_ptr<ServiceRegistry> serviceRegistry;

void addPluginSearchPath(const std::string path) {
serviceRegistry->appendSearchPath(path);
Expand All @@ -44,6 +43,7 @@ void ServiceAPI_Initialize(int argc, char **argv) {
rootPath = vm["xacc-root-path"].as<std::string>();
}

serviceRegistry = std::make_unique<ServiceRegistry>();
try {
serviceRegistry->initialize(rootPath);
} catch (std::exception &e) {
Expand All @@ -60,6 +60,7 @@ void ServiceAPI_Finalize() {
if (serviceAPIInitialized) {
serviceAPIInitialized = false;
serviceRegistry->finalize();
serviceRegistry.release();
Copy link
Member

Choose a reason for hiding this comment

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

release gives up the pointer for someone else to hold on to (in this case, it's leaking memory). I think you want reset or = {} or = nullptr.

Copy link
Author

@ausbin ausbin Dec 18, 2024

Choose a reason for hiding this comment

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

Thanks, will fix.

I also will look into why the tests are segfaulting. I wonder if something is accessing the service registry after finalize()

}
}

Expand Down
2 changes: 1 addition & 1 deletion xacc/service/xacc_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace xacc {

extern std::shared_ptr<ServiceRegistry> serviceRegistry;
extern std::unique_ptr<ServiceRegistry> serviceRegistry;
extern bool serviceAPIInitialized;

void ServiceAPI_Initialize(int argc, char **argv);
Expand Down
Loading