MX 2 лет назад
Родитель
Сommit
cd4e09f685
2 измененных файлов с 18 добавлено и 0 удалено
  1. 8 0
      Sensors.c
  2. 10 0
      unitemp.c

+ 8 - 0
Sensors.c

@@ -292,6 +292,8 @@ bool unitemp_sensors_load(void) {
     //Открытие потока к файлу с датчиками
     if(!file_stream_open(
            app->file_stream, furi_string_get_cstr(filepath), FSAM_READ_WRITE, FSOM_OPEN_EXISTING)) {
+        // Free file path string if we got an error
+        furi_string_free(filepath);
         if(file_stream_get_error(app->file_stream) == FSE_NOT_EXIST) {
             FURI_LOG_W(APP_NAME, "Missing sensors file");
             //Закрытие потока и освобождение памяти
@@ -309,6 +311,8 @@ bool unitemp_sensors_load(void) {
             return false;
         }
     }
+    // Free file path string if we successfully opened the file
+    furi_string_free(filepath);
 
     //Вычисление размера файла
     uint16_t file_size = stream_size(app->file_stream);
@@ -402,6 +406,8 @@ bool unitemp_sensors_save(void) {
     //Открытие потока
     if(!file_stream_open(
            app->file_stream, furi_string_get_cstr(filepath), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS)) {
+        // Free file path string if we got an error
+        furi_string_free(filepath);
         FURI_LOG_E(
             APP_NAME,
             "An error occurred while saving the sensors file: %d",
@@ -411,6 +417,8 @@ bool unitemp_sensors_save(void) {
         stream_free(app->file_stream);
         return false;
     }
+    // Free file path string if we successfully opened the file
+    furi_string_free(filepath);
 
     //Сохранение датчиков
     for(uint8_t i = 0; i < unitemp_sensors_getActiveCount(); i++) {

+ 10 - 0
unitemp.c

@@ -79,6 +79,8 @@ bool unitemp_saveSettings(void) {
     //Открытие потока
     if(!file_stream_open(
            app->file_stream, furi_string_get_cstr(filepath), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS)) {
+        // Free file path string if we got an error
+        furi_string_free(filepath);
         FURI_LOG_E(
             APP_NAME,
             "An error occurred while saving the settings file: %d",
@@ -99,6 +101,8 @@ bool unitemp_saveSettings(void) {
     //Закрытие потока и освобождение памяти
     file_stream_close(app->file_stream);
     stream_free(app->file_stream);
+    // Free file path string if we successfully opened the file
+    furi_string_free(filepath);
 
     FURI_LOG_I(APP_NAME, "Settings have been successfully saved");
     return true;
@@ -124,6 +128,8 @@ bool unitemp_loadSettings(void) {
             //Закрытие потока и освобождение памяти
             file_stream_close(app->file_stream);
             stream_free(app->file_stream);
+            // Free file path string if we got an error
+            furi_string_free(filepath);
             //Сохранение стандартного конфига
             unitemp_saveSettings();
             return false;
@@ -135,9 +141,13 @@ bool unitemp_loadSettings(void) {
             //Закрытие потока и освобождение памяти
             file_stream_close(app->file_stream);
             stream_free(app->file_stream);
+            // Free file path string if we got an error
+            furi_string_free(filepath);
             return false;
         }
     }
+    // Free file path string if we successfully opened the file
+    furi_string_free(filepath);
 
     //Вычисление размера файла
     uint8_t file_size = stream_size(app->file_stream);