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

static ServiceTracker object crashes in ServiceTracker::Close() #281

Closed
jeffdiclemente opened this issue Jun 20, 2018 · 0 comments
Closed
Assignees
Labels

Comments

@jeffdiclemente
Copy link
Member

Maintaining a static ServiceTracker object can cause the program to crash on termination in ServiceTracker::Close().

The seg fault is caused by accessing the a nullptr CoreBundleContext pointer in BundleContext::GetLogSink()

test case:

#include "cppmicroservices/Framework.h"
#include "cppmicroservices/FrameworkEvent.h"
#include "cppmicroservices/FrameworkFactory.h"
#include <cppmicroservices/ServiceInterface.h>
#include "cppmicroservices/ServiceTracker.h"

#include <memory>

// A dummy interface to use with the service tracker
namespace {
    class Foo {
    public:
        virtual ~Foo() = default;
    };
}
CPPMICROSERVICES_DECLARE_SERVICE_INTERFACE(Foo, "org.cppmicroservices.test.servicetracker.Foo");

int main()
{
    auto f = cppmicroservices::FrameworkFactory().NewFramework();
    ASSERT_TRUE(f);
    f.Start();

    static std::shared_ptr<cppmicroservices::ServiceTracker<Foo>> globalTracker(std::make_shared<cppmicroservices::ServiceTracker<Foo>>(f.GetBundleContext()));
    globalTracker->Open();

    f.Stop();
    f.WaitForStop(std::chrono::milliseconds::zero());
}
// seg fault access violation when this process destroys static objects...

Minimally ServiceTracker::Close() shouldn't crash if the Framework has been destroyed.

@jeffdiclemente jeffdiclemente self-assigned this Jun 20, 2018
jeffdiclemente added a commit that referenced this issue Jul 2, 2018
Fixes #281 
Prevent a crash when destroying a global ServiceTracker
Fixed documentation for exceptions
arcadien pushed a commit to pollen-metrology/CppMicroServices that referenced this issue May 20, 2019
…icroServices#283)

Fixes CppMicroServices#281 
Prevent a crash when destroying a global ServiceTracker
Fixed documentation for exceptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant