Skip to content

Conversation

@0AnshuAditya0
Copy link

Fixes opencv/opencv#27971

Problem:
Double-free crash in std::vector<zxing::Refzxing::qrcode::Version>::~vector()
during process shutdown when using wechat_qrcode module. The crash occurred with
error "free(): double free detected in tcache 2" and SIGBUS signal.

Root Cause:
Static member variable VERSIONS was destroyed during shutdown while Ref
objects still held references, causing double-free due to static initialization
order fiasco.

Solution:
Converted static member variable to Meyer's singleton pattern with heap allocation.
The vector is intentionally never destroyed, preventing the double-free during
shutdown. This is a standard pattern for avoiding static destruction order issues.

Changes:

  • version.hpp: Changed VERSIONS declaration to getVersions() function
  • version.cpp: Implemented getVersions() with function-local static pointer
  • version.cpp: Updated all 15+ references to use getVersions() instead of VERSIONS

Testing:

  • Existing tests pass without crashes
  • No SIGBUS crash on shutdown
  • Small intentional memory "leak" (singleton pattern) is acceptable
Fixes opencv/opencv#27971 Problem: Double-free crash in std::vector<zxing::Ref<zxing::qrcode::Version>>::~vector() during process shutdown when using wechat_qrcode module. The crash occurred with error "free(): double free detected in tcache 2" and SIGBUS signal. Root Cause: Static member variable VERSIONS was destroyed during shutdown while Ref<Version> objects still held references, causing double-free due to static initialization order fiasco. Solution: Converted static member variable to Meyer's singleton pattern with heap allocation. The vector is intentionally never destroyed, preventing the double-free during shutdown. This is a standard pattern for avoiding static destruction order issues. Changes: - version.hpp: Changed VERSIONS declaration to getVersions() function - version.cpp: Implemented getVersions() with function-local static pointer - version.cpp: Updated all 15+ references to use getVersions() instead of VERSIONS Testing: - Existing tests pass without crashes - No SIGBUS crash on shutdown - Small intentional memory "leak" (singleton pattern) is acceptable
@0AnshuAditya0 0AnshuAditya0 changed the base branch from 4.x to 5.x November 21, 2025 10:41
@0AnshuAditya0 0AnshuAditya0 changed the base branch from 5.x to 4.x November 21, 2025 10:42
@0AnshuAditya0 0AnshuAditya0 changed the base branch from 4.x to 5.x November 21, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant