Commit 43a1bd6751fae35828714699cc20f11d27165023
Committed by
David Gräff
1 parent
7ed6776a
Fixes a segfault on startup. The previous code assumed that ModelRegistry::insta…
…nce would be initialized before being used by other static initializers. However, static initialization order is undefined. Plus, at least unter C++11 and according to 6.7[stmt.decl] p.4, this initialization of get():inst is thread-safe.
Showing
2 changed files
with
4 additions
and
4 deletions
openhantek/src/hantekdso/modelregistry.cpp
| ... | ... | @@ -2,9 +2,10 @@ |
| 2 | 2 | |
| 3 | 3 | #include "modelregistry.h" |
| 4 | 4 | |
| 5 | -ModelRegistry *ModelRegistry::instance = new ModelRegistry(); | |
| 6 | - | |
| 7 | -ModelRegistry *ModelRegistry::get() { return instance; } | |
| 5 | +ModelRegistry *ModelRegistry::get() { | |
| 6 | + static ModelRegistry inst; | |
| 7 | + return &inst; | |
| 8 | +} | |
| 8 | 9 | |
| 9 | 10 | void ModelRegistry::add(DSOModel *model) { supportedModels.push_back(model); } |
| 10 | 11 | ... | ... |