This is an automated email from the ASF dual-hosted git repository.

jiuzhudong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 95cf3b3aa9c1e49cc1eb17299c9b88265e7b4d0f
Author: buxiasen <buxia...@xiaomi.com>
AuthorDate: Thu Jan 9 22:33:11 2025 +0800

    blk/mtdoutstream: should flush before free
    
    to avoid losing the data in the buffer
    
    Signed-off-by: buxiasen <buxia...@xiaomi.com>
---
 libs/libc/stream/lib_blkoutstream.c | 12 ++++++------
 libs/libc/stream/lib_mtdoutstream.c | 12 ++++++------
 libs/libc/stream/lib_mtdsostream.c  | 12 ++++++------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/libs/libc/stream/lib_blkoutstream.c 
b/libs/libc/stream/lib_blkoutstream.c
index ee973481bb..793a0fe1d8 100644
--- a/libs/libc/stream/lib_blkoutstream.c
+++ b/libs/libc/stream/lib_blkoutstream.c
@@ -239,18 +239,18 @@ void lib_blkoutstream_close(FAR struct lib_blkoutstream_s 
*stream)
 {
   if (stream != NULL)
     {
-      if (stream->inode != NULL)
-        {
-          close_blockdriver(stream->inode);
-          stream->inode = NULL;
-        }
-
       if (stream->cache != NULL)
         {
           blkoutstream_flush(&stream->common);
           lib_free(stream->cache);
           stream->cache = NULL;
         }
+
+      if (stream->inode != NULL)
+        {
+          close_blockdriver(stream->inode);
+          stream->inode = NULL;
+        }
     }
 }
 
diff --git a/libs/libc/stream/lib_mtdoutstream.c 
b/libs/libc/stream/lib_mtdoutstream.c
index 138e9f985e..c9a42a687c 100644
--- a/libs/libc/stream/lib_mtdoutstream.c
+++ b/libs/libc/stream/lib_mtdoutstream.c
@@ -267,18 +267,18 @@ void lib_mtdoutstream_close(FAR struct lib_mtdoutstream_s 
*stream)
 {
   if (stream != NULL)
     {
-      if (stream->inode != NULL)
-        {
-          close_mtddriver(stream->inode);
-          stream->inode = NULL;
-        }
-
       if (stream->cache != NULL)
         {
           mtdoutstream_flush(&stream->common);
           lib_free(stream->cache);
           stream->cache = NULL;
         }
+
+      if (stream->inode != NULL)
+        {
+          close_mtddriver(stream->inode);
+          stream->inode = NULL;
+        }
     }
 }
 
diff --git a/libs/libc/stream/lib_mtdsostream.c 
b/libs/libc/stream/lib_mtdsostream.c
index 262fdd70e1..52e2221aa8 100644
--- a/libs/libc/stream/lib_mtdsostream.c
+++ b/libs/libc/stream/lib_mtdsostream.c
@@ -277,18 +277,18 @@ void lib_mtdsostream_close(FAR struct lib_mtdsostream_s 
*stream)
 {
   if (stream != NULL)
     {
-      if (stream->inode != NULL)
-        {
-          close_mtddriver(stream->inode);
-          stream->inode = NULL;
-        }
-
       if (stream->cache != NULL)
         {
           mtdsostream_flush(&stream->common);
           lib_free(stream->cache);
           stream->cache = NULL;
         }
+
+      if (stream->inode != NULL)
+        {
+          close_mtddriver(stream->inode);
+          stream->inode = NULL;
+        }
     }
 }
 

Reply via email to