"Fix" the crash at startup on MSVC
authorOlivier Goffart <olivier.goffart@nokia.com>
Fri, 15 Jul 2011 15:51:07 +0000 (17:51 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 15 Jul 2011 16:46:50 +0000 (18:46 +0200)
The problem is that for some reasons, QByteArray::shared_null (and
probably shared_empty, and the ones for QString) are not in the .rodata
anymore, and they are initialized by code.
programs like QMake, which has others global objects (like global
QFiles) that uses QByteArray crashes, because they reference and
dereference shared_null (and try to destroy shared_null)
That happens before shared_null's refcount is initialized to -1

The solution here is not to ref() the objects that have a refcount of 0
(that is what the refcount is before it is initialized to -1)

The real fix to this problem would be to understand why it is not in the
proper section, and make sure it is.

Change-Id: I5b7e966ed4c460b90dba70855f4dc50685dff97f
Reviewed-on: http://codereview.qt.nokia.com/1712
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/corelib/tools/qrefcount.h

index 9223cfe..e72ddf6 100644 (file)
@@ -57,12 +57,12 @@ class RefCount
 {
 public:
    inline void ref() {
-        if (atomic >= 0)
+        if (atomic > 0)
             atomic.ref();
     }
 
     inline bool deref() {
-        if (atomic < 0)
+        if (atomic <= 0)
             return true;
         return atomic.deref();
     }