Merge "adjusted sad_per_bit to correlate with quantizer"
diff --git a/vpxenc.c b/vpxenc.c
index 5e4fe3f..cb911be 100755
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -186,11 +186,11 @@
 }
 
 
-void stats_close(stats_io_t *stats)
+void stats_close(stats_io_t *stats, int last_pass)
 {
     if (stats->file)
     {
-        if (stats->pass == 1)
+        if (stats->pass == last_pass)
         {
 #if 0
 #elif USE_POSIX_MMAP
@@ -205,7 +205,7 @@
     }
     else
     {
-        if (stats->pass == 1)
+        if (stats->pass == last_pass)
             free(stats->buf.buf);
     }
 }
@@ -1692,7 +1692,7 @@
         }
 
         fclose(outfile);
-        stats_close(&stats);
+        stats_close(&stats, arg_passes-1);
         fprintf(stderr, "\n");
 
         if (one_pass_only)