From ea64dc9a113a850334fbf47ca2cdc3b447945c25 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 15 Apr 2016 13:49:25 +0200 Subject: 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 --- src/corelib/io/qlockfile_unix.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index bcef84206e..f23a232fb8 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) -- cgit v1.2.3