From 192e7b888f8cfcf4f02b0b5b6b502e679e91a4a1 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 29 Jun 2017 21:45:26 -0400 Subject: [PATCH] lib/commit: Fix a tmpfile fd leak in static delta processing I had thought `glnx_link_tmpfile_at()` actually consumed the tmpfile; it does consume the *path* but not the fd. In the non-delta path things were fine since we used the autocleanup. But the delta code had a tmpfile allocated in its struct that got reused, and hence leaked the fd. Fix this by making the commit API actually consume the tmpfile fully, just like the path path. Closes: #986 Approved by: jlebon --- src/libostree/ostree-repo-commit.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index ae3760c0..bc55fd6f 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -156,8 +156,12 @@ _ostree_repo_commit_tmpf_final (OstreeRepo *self, cancellable, error)) return FALSE; - return glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, - dest_dfd, tmpbuf, error); + if (!glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, + dest_dfd, tmpbuf, error)) + return FALSE; + /* We're done with the fd */ + glnx_tmpfile_clear (tmpf); + return TRUE; } /* Given a dfd+path combination (may be regular file or symlink),