From fe0e546c65accd2e9ca0fa5410fd88a9b64b36a4 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Tue, 8 Dec 2020 00:12:36 +0000 Subject: use fopencookie to avoid leaking FILE structs If we use fdopen for stdin/out/err we cannot close it to free the file struct without also closing the file descriptor. If fopencookie is available, use that to wrap the file descriptor, but allow closing without closing the fd. This is useful when embedding in long running programs. --- configure.ac | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 298da146..11b5d00a 100644 --- a/configure.ac +++ b/configure.ac @@ -406,6 +406,15 @@ AC_SUBST(EXTERNAL_COLM) AC_SUBST(EXTERNAL_INC) AC_SUBST(EXTERNAL_LIBS) +dnl Check for fopencookie. If available, we will use to avoid leaking FILE structs. +dnl The result of an fdopen cannot be closed without also closing the fd, so we +dnl make our own FILE type. +AC_CHECK_FUNC(fopencookie, + [AC_DEFINE([HAVE_FOPENCOOKIE], [1], [have fopencookie])], + [] +) + + dnl dnl Wrap up. dnl -- cgit v1.2.1