diff --git a/tests/libglnx-testlib.c b/tests/libglnx-testlib.c
index 5687d80706989cefdc6786fd05253234f3017a72..fd4fd653a7d19e116306a231602cab0b8aba1b8f 100644
--- a/tests/libglnx-testlib.c
+++ b/tests/libglnx-testlib.c
@@ -23,6 +23,8 @@
 
 #include <errno.h>
 
+#include <glib/gstdio.h>
+
 #include "libglnx.h"
 
 struct _GLnxTestAutoTempDir
@@ -63,4 +65,9 @@ _glnx_test_auto_temp_dir_leave (_GLnxTestAutoTempDir *dir)
 
   glnx_tmpdir_delete (&dir->temp_dir, NULL, &error);
   g_assert_no_error (error);
+
+  glnx_close_fd (&dir->old_cwd_fd);
+
+  g_free (dir->old_cwd);
+  g_free (dir);
 }