Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #27 from nemomobile-packages/fd-leak
[qmf] Close messageserver lock fd if lock can't be acquired.
  • Loading branch information
VDVsx committed Mar 13, 2014
2 parents 7fce667 + 1a95363 commit bffde67
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions qmf/src/libraries/qmfclient/support/qmailnamespace.cpp
Expand Up @@ -155,8 +155,10 @@ int QMail::fileLock(const QString& lockFile)
if((fdlock = ::open(path.toLatin1(), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
return -1;

if(::fcntl(fdlock, F_SETLK, &fl) == -1)
if(::fcntl(fdlock, F_SETLK, &fl) == -1) {
::close(fdlock);
return -1;
}

return fdlock;
#endif
Expand Down Expand Up @@ -188,19 +190,9 @@ bool QMail::fileUnlock(int id)

return false;
#else
struct flock fl;

fl.l_type = F_UNLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;

int result = -1;

result = ::fcntl(id,F_SETLK, &fl);
if (result == -1)
return false;

result = ::close(id);
if (result == -1)
return false;
Expand Down

0 comments on commit bffde67

Please sign in to comment.