[libglnx] fdio: Be sure to unset tmpfile's initialized state on cleanup
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libglnx] fdio: Be sure to unset tmpfile's initialized state on cleanup
- Date: Wed, 28 Jun 2017 15:24:22 +0000 (UTC)
commit d4c5c02327cc3ac29e40848c53fd1bce392e8ae5
Author: Colin Walters <walters verbum org>
Date: Tue Jun 27 21:01:46 2017 -0400
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.
glnx-fdio.c | 9 ++++++++-
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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]