From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 1F00A1392EF for ; Tue, 11 Mar 2014 04:54:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ABD49E09C5; Tue, 11 Mar 2014 04:54:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 408DEE09C5 for ; Tue, 11 Mar 2014 04:54:01 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 699B833FAE3 for ; Tue, 11 Mar 2014 04:54:00 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 1EB2A183B3 for ; Tue, 11 Mar 2014 04:53:54 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1394512379.b0280f87242535cc0e4861c5671c1fa05a6ef141.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/vdb.c X-VCS-Directories: libq/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: b0280f87242535cc0e4861c5671c1fa05a6ef141 X-VCS-Branch: master Date: Tue, 11 Mar 2014 04:53:54 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: fdc735af-ab8f-4af0-b526-2af39346cb16 X-Archives-Hash: 58f4217cea5d140f75bc2281f11a5a1a commit: b0280f87242535cc0e4861c5671c1fa05a6ef141 Author: Mike Frysinger gentoo org> AuthorDate: Tue Mar 11 04:32:59 2014 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Tue Mar 11 04:32:59 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=b0280f87 vdb: fix fd leaks Make sure we only open the pkg dir when we don't yet have an fd. Make sure we close out the fd when we've finished eating a file. Reported-by: Tim Harder gentoo.org> --- libq/vdb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libq/vdb.c b/libq/vdb.c index 44ebf9e..4b7d911 100644 --- a/libq/vdb.c +++ b/libq/vdb.c @@ -227,9 +227,11 @@ _q_static q_vdb_pkg_ctx *q_vdb_next_pkg(q_vdb_cat_ctx *cat_ctx) _q_static int q_vdb_pkg_openat(q_vdb_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode) { - pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name, O_RDONLY|O_CLOEXEC|O_PATH); - if (pkg_ctx->fd == -1) - return -1; + if (pkg_ctx->fd == -1) { + pkg_ctx->fd = openat(pkg_ctx->cat_ctx->fd, pkg_ctx->name, O_RDONLY|O_CLOEXEC|O_PATH); + if (pkg_ctx->fd == -1) + return -1; + } return openat(pkg_ctx->fd, file, flags|O_CLOEXEC, mode); } @@ -259,6 +261,8 @@ q_vdb_pkg_eat(q_vdb_pkg_ctx *pkg_ctx, const char *file, char **bufptr, size_t *b int fd = q_vdb_pkg_openat(pkg_ctx, file, O_RDONLY, 0); bool ret = eat_file_fd(fd, bufptr, buflen); rmspace(*bufptr); + if (fd != -1) + close(fd); return ret; }