From 707291ab683a3f113fb461cb8e863acbb2c3a835 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Fri, 19 Aug 2016 18:40:06 -0500 Subject: [PATCH] Fix SingletonPtr problems Check to see if ptr is NULL after acquiring the singleton lock to prevent initialization race conditions. Also explicitly call the constructor for type T. --- hal/api/SingletonPtr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hal/api/SingletonPtr.h b/hal/api/SingletonPtr.h index 998aff8245..820c8ed7d1 100644 --- a/hal/api/SingletonPtr.h +++ b/hal/api/SingletonPtr.h @@ -76,7 +76,9 @@ struct SingletonPtr { T* get() { if (NULL == _ptr) { singleton_lock(); - _ptr = new (_data) T; + if (NULL == _ptr) { + _ptr = new (_data) T(); + } singleton_unlock(); } // _ptr was not zero initialized or was