Bug 753709

Summary: Fix fd leak in KLockFile
Product: [Fedora] Fedora Reporter: Andreas Schwab <schwab>
Component: kdelibsAssignee: Than Ngo <than>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 15CC: cwickert, jreznik, kevin, ltinkl, rdieter, rnovacek, ry, smparrish, than
Target Milestone: ---Keywords: Patch, Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: kdelibs-4.6.5-8.fc14 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-11-17 23:27:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 754405    

Description Andreas Schwab 2011-11-14 09:04:01 UTC
From 865e5fa4108bb3f470b9424ec34dc573d97e2473 Mon Sep 17 00:00:00 2001
From: David Faure <faure>
Date: Wed, 24 Aug 2011 10:29:09 +0200
Subject: [PATCH] Fix fd leak in KLockFile

Didn't expect that after open(fd), QFile::close doesn't close the fd :)
---
 kdecore/io/klockfile_unix.cpp |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/kdecore/io/klockfile_unix.cpp b/kdecore/io/klockfile_unix.cpp
index fa2eda4..93e92e2 100644
--- a/kdecore/io/klockfile_unix.cpp
+++ b/kdecore/io/klockfile_unix.cpp
@@ -78,6 +78,7 @@ public:
         : staleTime(30), // 30 seconds
           isLocked(false),
           linkCountSupport(true),
+          mustCloseFd(false),
           m_pid(-1),
           m_componentData(c)
     {
@@ -102,6 +103,7 @@ public:
     int staleTime;
     bool isLocked;
     bool linkCountSupport;
+    bool mustCloseFd;
     QTime staleTimer;
     KDE_struct_stat statBuf;
     int m_pid;
@@ -285,7 +287,10 @@ KLockFile::LockResult KLockFile::Private::lockFileOExcl(KDE_struct_stat &st_buf)
     if (!m_file.open(fd, QIODevice::WriteOnly)) {
         return LockError;
     }
+    mustCloseFd = true;
     writeIntoLockFile(m_file, m_componentData);
+
+    // stat to get the modification time
     const int result = KDE_lstat(QFile::encodeName(m_fileName), &st_buf);
     if (result != 0)
         return KLockFile::LockError;
@@ -476,6 +481,10 @@ void KLockFile::unlock()
   if (d->isLocked)
   {
      ::unlink(QFile::encodeName(d->m_fileName));
+      if (d->mustCloseFd) {
+         close(d->m_file.handle());
+         d->mustCloseFd = false;
+     }
      d->m_file.close();
      d->m_pid = -1;
      d->isLocked = false;
-- 
1.7.6.4

Comment 1 Fedora Update System 2011-11-16 15:58:56 UTC
kdelibs-4.6.5-8.fc15 has been submitted as an update for Fedora 15.
https://admin.fedoraproject.org/updates/kdelibs-4.6.5-8.fc15

Comment 2 Fedora Update System 2011-11-16 15:59:46 UTC
kdelibs-4.6.5-8.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/kdelibs-4.6.5-8.fc14

Comment 3 Kevin Kofler 2011-11-17 15:20:38 UTC
*** Bug 754405 has been marked as a duplicate of this bug. ***

Comment 4 Fedora Update System 2011-11-17 23:27:31 UTC
kdelibs-4.6.5-8.fc15 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 5 Fedora Update System 2011-11-17 23:39:43 UTC
kdelibs-4.6.5-8.fc14 has been pushed to the Fedora 14 stable repository.  If problems still persist, please make note of it in this bug report.