diff --git a/src/main.c b/src/main.c
index 509253fa..ba44fd67 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1182,6 +1182,11 @@ main (int argc, char **argv, char **envp)
   /* Useful for attaching debuggers, etc.  */
   SPIN ("main-entry");
 
+  /* Don't die if our stdout sends us SIGPIPE.  */
+#ifdef SIGPIPE
+  bsd_signal (SIGPIPE, SIG_IGN);
+#endif
+
 #ifdef HAVE_ATEXIT
   if (ANY_SET (check_io_state (), IO_STDOUT_OK))
     atexit (close_stdout);
diff --git a/src/posixos.c b/src/posixos.c
index a48116db..fca31927 100644
--- a/src/posixos.c
+++ b/src/posixos.c
@@ -699,6 +699,7 @@ osync_clear ()
       int r;
 
       EINTRLOOP (r, unlink (osync_tmpfile));
+      free (osync_tmpfile);
       osync_tmpfile = NULL;
     }
 }