From ea64dc9a113a850334fbf47ca2cdc3b447945c25 Mon Sep 17 00:00:00 2001
From: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Date: Fri, 15 Apr 2016 13:49:25 +0200
Subject: [PATCH] qlockfile_unix - code cleanup

Coverity's CID 157687: QCache::insert, indeed, can delete (immediately)
the object we're trying to insert. While this never happens actually in
qlockfile_unix since we have max cost 10 and insert with cost 1, the
code does not look good and Coverity is not happy.

Change-Id: I16a428017bf86e151afe5256906e4cab1ef4044a
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
---
 src/corelib/io/qlockfile_unix.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index bcef84206e8..f23a232fb8c 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -139,12 +139,14 @@ static bool fcntlWorksAfterFlock(const QString &fn)
     if (fcntlOK.isDestroyed())
         return QLockFilePrivate::checkFcntlWorksAfterFlock(fn);
     bool *worksPtr = fcntlOK->object(fn);
-    if (!worksPtr) {
-        worksPtr = new bool(QLockFilePrivate::checkFcntlWorksAfterFlock(fn));
-        fcntlOK->insert(fn, worksPtr);
-    }
+    if (worksPtr)
+        return *worksPtr;
+
+    const bool val = QLockFilePrivate::checkFcntlWorksAfterFlock(fn);
+    worksPtr = new bool(val);
+    fcntlOK->insert(fn, worksPtr);
 
-    return *worksPtr;
+    return val;
 }
 
 static bool setNativeLocks(const QString &fileName, int fd)
-- 
GitLab