Skip to content

Possible UB in DeleteLock() function #18824

@hebasto

Description

@hebasto

Since #15233 has been merged, the lockdata becomes a static local variable with a well-defined initialization order:

bitcoin/src/sync.cpp

Lines 93 to 96 in 36c0abd

LockData& GetLockData() {
static LockData lockdata;
return lockdata;
}

Its destructor ~LockData() is called at program exit.

At the same time, "if a function-local ... static object was destroyed and then that function is called from the destructor..., the behavior is undefined."

It seems possible that at program exit the lockdata object is destroyed before a global RecursiveMutex destructor calls DeleteLock(), which in turn calls GetLockData() with UB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions