Add --kati_heapprofile flag
diff --git a/log.go b/log.go
index 78060b1..2117a0e 100644
--- a/log.go
+++ b/log.go
@@ -31,6 +31,7 @@
 
 func Error(filename string, lineno int, f string, a ...interface{}) {
 	f = fmt.Sprintf("%s:%d: %s", filename, lineno, f)
+	maybeWriteHeapProfile()
 	ErrorNoLocation(f, a...)
 }
 
@@ -40,5 +41,6 @@
 	if cpuprofile != "" {
 		pprof.StopCPUProfile()
 	}
+	maybeWriteHeapProfile()
 	os.Exit(2)
 }