summaryrefslogtreecommitdiff
path: root/glnx-fdio.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-06-27 21:01:46 -0400
committerColin Walters <walters@verbum.org>2017-06-28 11:23:01 -0400
commitd4c5c02327cc3ac29e40848c53fd1bce392e8ae5 (patch)
tree036aecdf51552d2cf663a0e45a4f01d04874ef4e /glnx-fdio.c
parent5ab15ac175ca45fce1b63a910f8ae2c488b92cfe (diff)
downloadlibglnx-d4c5c02327cc3ac29e40848c53fd1bce392e8ae5.tar.gz
fdio: Be sure to unset tmpfile's initialized state on cleanup
I'm not aware of a problem in practice here, but we should do this on general principle. Writing this patch now because I hit a fd leak in the ostree static delta processing that was introduced in the tmpfile prep code, but fixed in the final port.
Diffstat (limited to 'glnx-fdio.c')
-rw-r--r--glnx-fdio.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c
index b5eaa9e..ad43e61 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -145,10 +145,16 @@ glnx_renameat2_exchange (int olddirfd, const char *oldpath,
return 0;
}
-/* Deallocate a tmpfile */
+/* Deallocate a tmpfile, closing the fd and deleting the path, if any. This is
+ * normally called by default by the autocleanup attribute, but you can also
+ * invoke this directly.
+ */
void
glnx_tmpfile_clear (GLnxTmpfile *tmpf)
{
+ /* Support being passed NULL so we work nicely in a GPtrArray */
+ if (!tmpf)
+ return;
if (!tmpf->initialized)
return;
if (tmpf->fd == -1)
@@ -160,6 +166,7 @@ glnx_tmpfile_clear (GLnxTmpfile *tmpf)
(void) unlinkat (tmpf->src_dfd, tmpf->path, 0);
g_free (tmpf->path);
}
+ tmpf->initialized = FALSE;
}
/* Allocate a temporary file, using Linux O_TMPFILE if available.