opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

Fix SIGBUS crash in wechat_qrcode during process shutdown

Open 0AnshuAditya0 opened this issue 3 weeks ago • 0 comments

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<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 avatar Nov 21 '25 10:11 0AnshuAditya0