=== NYTProf.xs
==================================================================
--- NYTProf.xs	(revision 13295)
+++ NYTProf.xs	(local)
@@ -310,7 +310,7 @@
 static void DB_stmt(pTHX_ COP *cop, OP *op);
 static void set_option(pTHX_ const char*, const char*);
 static int enable_profile(pTHX_ char *file);
-static int disable_profile(pTHX);
+static int disable_profile(pTHX, int finalize);
 static void finish_profile(pTHX);
 static void open_output_file(pTHX_ char *);
 static int reinit_if_forked(pTHX);
@@ -1936,7 +1936,7 @@
         const char *hint = "";
         if (fopen_errno==EEXIST && !(profile_opts & NYTP_OPTf_ADDPID))
             hint = " (enable addpid option to protect against concurrent writes)";
-        disable_profile(aTHX);
+        disable_profile(aTHX, 0);
         croak("Failed to open output '%s': %s%s", filename, strerror(fopen_errno), hint);
     }
     if (trace_level)
@@ -2420,14 +2420,17 @@
 
 
 static int
-disable_profile(pTHX)
+disable_profile(pTHX, int finalize)
 {
     int prev_is_profiling = is_profiling;
     if (is_profiling) {
         if (use_db_sub)
             sv_setiv(PL_DBsingle, 0);
-        if (out)
+        if (out) {
             NYTP_flush(out);
+            if (finalize)
+                close_output_file(aTHX);
+        }
         is_profiling = 0;
     }
     if (trace_level)
@@ -2450,10 +2453,8 @@
     if (!profile_leave || use_db_sub)
         DB_stmt(aTHX_ NULL, NULL);
 
-    disable_profile(aTHX);
+    disable_profile(aTHX, 1);
 
-    close_output_file(aTHX);
-
     SETERRNO(saved_errno, 0);
 }
 
@@ -3916,9 +3917,9 @@
 
 
 int
-disable_profile()
+disable_profile(int finalize = 0)
     C_ARGS:
-    aTHX
+    aTHX_ finalize
 
 void
 finish_profile(...)
=== lib/Devel/NYTProf.pm
==================================================================
--- lib/Devel/NYTProf.pm	(revision 13295)
+++ lib/Devel/NYTProf.pm	(local)
@@ -431,7 +431,11 @@
 future profile data to that file. The current output file, if any, is closed.
 Any existing file with the new name will be deleted before being written to.
 When combined with DB::disable_profile() this lets you profile individual
-sections of code.
+sections of code.  Note that DB::disable_profile() does not finalize the output
+file, because you may still use enable_profile() to append to the current
+output.  You can pass a true value to disable_profile() to make it finalize
+upon disable, but you will need to make sure enable_profile() is called with a
+filename the next time.
 
 =head1 REPORTS
 
