diff options
author | Michael Vogt <mvo@debian.org> | 2013-07-25 20:26:11 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2013-07-25 20:26:11 +0200 |
commit | 3d165906327828990bec2c58a3c1f4ee77467523 (patch) | |
tree | 277afa2511cd7b3d79672fee71b0e52da6cd89e7 /apt-pkg | |
parent | fe0036dd7e3bbd808fa526e2e142fdb89105caae (diff) | |
download | apt-3d165906327828990bec2c58a3c1f4ee77467523.tar.gz |
fix resource leak (thanks coverity)
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index edf612810..398830ff5 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -244,17 +244,21 @@ int GetLock(string File,bool Errors) fl.l_len = 0; if (fcntl(FD,F_SETLK,&fl) == -1) { + // always close to not leak resources + int Tmp = errno; + close(FD); + errno = Tmp; + if (errno == ENOLCK) { + _error->Warning(_("Not using locking for nfs mounted lock file %s"),File.c_str()); return dup(0); // Need something for the caller to close - } + } + if (Errors == true) _error->Errno("open",_("Could not get lock %s"),File.c_str()); - int Tmp = errno; - close(FD); - errno = Tmp; return -1; } |