From: Sangyoon Jang Date: Mon, 10 Feb 2020 06:24:00 +0000 (+0900) Subject: Fix double close issue X-Git-Tag: submit/tizen/20200214.080724~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F224364%2F1;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Fix double close issue fd passed to fdopendir is used internally by the implementation, and should not otherwise be used by the application. Change-Id: Ib8de3e9782f8e2455329acaecaeb43d2646c3a6d Signed-off-by: Sangyoon Jang --- diff --git a/src/pkg_getsize.c b/src/pkg_getsize.c index 94ebd66..b459c2c 100644 --- a/src/pkg_getsize.c +++ b/src/pkg_getsize.c @@ -157,6 +157,16 @@ static long long __calculate_directory_size(int dfd, bool include_itself) size += __stat_size(&st); } + /* fd passed to fdopendir is used internally by the implementation, + * and should not otherwise be used by the application. + * So we need to pass duplicated fd to fdopendir. + */ + dfd = dup(dfd); + if (dfd == -1) { + LOGE("failed to duplicate fd, errno: %d (%s)", errno, + strerror_r(errno, buf, sizeof(buf))); + return -1; + } dir = fdopendir(dfd); if (dir == NULL) { LOGE("fdopendir() failed, errno: %d (%s)", errno,