diff --git a/app/gui/oven_control/cookhistory.cpp b/app/gui/oven_control/cookhistory.cpp
index 518565c..5cf8843 100644
--- a/app/gui/oven_control/cookhistory.cpp
+++ b/app/gui/oven_control/cookhistory.cpp
@@ -1,5 +1,7 @@
 #include "cookhistory.h"
 
+#include "unistd.h"
+
 #include "autocookwindow.h"
 #include "manualcookwindow.h"
 #include "manualcooksettingwidget.h"
@@ -368,6 +370,9 @@ void writeCounts()
 
         stream << "\n";
     }
+
+    file.close();
+    sync();
 }
 
 void appendRecent(RecentsEntry e)
@@ -665,6 +670,9 @@ void writeRecents()
             break;
         }
     }
+
+    file.close();
+    sync();
 }
 
 void appendFavorite(FavoritesEntry e)
@@ -979,6 +987,9 @@ void writeFavorites()
             break;
         }
     }
+
+    file.close();
+    sync();
 }
 
 bool initialized = false;