Opened 5 years ago

Last modified 5 months ago

#965 assigned defect

Static object destructors not called on Linux

Reported by: jng Owned by: jng
Priority: major Milestone: 4.2.0
Component: FDO API Version:
Severity: 3 Keywords:
Cc: External ID:

Description

I've noticed in running the various unit tests that static object destructors in various providers are not being called which results in the various teardown functions that are supposed to be called when the provider is being dlclose()'d are not being called.

Upon further reading, a better solution is to have a Linux-specific teardown function decorated with __attribute__((destructor)) like so:

//Various providers use this pattern for global data
class InitClass
{
public:
    InitClass()
    {
        //...provider-specific setup
    }
    ~InitClass()
    {
        //...provider-specific teardown
    }
}

static InitClass init; //Supposedly calls destructor when cleaned up, but doesn't on Linux when dlclose()'d

#ifndef _WIN32
void __attribute__((destructor)) Teardown()
{
    //...Call same provider-specific teardown as ~InitClass()
}
#endif

Such functions will be called when the provider is dlclose()'d

Change History (1)

comment:1 by jng, 5 months ago

Milestone: 4.2.0
Note: See TracTickets for help on using tickets.