poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] libpoke: free the buffer of stream device only in read mode


From: Mohammad-Reza Nabipoor
Subject: [PATCH v2] libpoke: free the buffer of stream device only in read mode
Date: Sun, 18 Oct 2020 19:14:15 +0330

2020-10-18  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>

        * libpoke/ios-dev-stream.c (ios_dev_stream_close): Free buffer only
        in read mode.
        * libpoke/ios-buffer.c (ios_buffer_free): Add assertion.
---
 ChangeLog                | 6 ++++++
 libpoke/ios-buffer.c     | 3 +++
 libpoke/ios-dev-stream.c | 3 ++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e481d90b..161442ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-10-18  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>
+
+       * libpoke/ios-dev-stream.c (ios_dev_stream_close): Free buffer only
+       in read mode.
+       * libpoke/ios-buffer.c (ios_buffer_free): Add assertion.
+
 2020-10-12  Egeyar Bagcioglu  <egeyar@gmail.com>
 
        * libpoke/Makefile.am (libpoke_la_SOURCES): Add ios-buffer.h,
diff --git a/libpoke/ios-buffer.c b/libpoke/ios-buffer.c
index f3e1ad63..a2bdbb99 100644
--- a/libpoke/ios-buffer.c
+++ b/libpoke/ios-buffer.c
@@ -76,6 +76,9 @@ int
 ios_buffer_free (struct ios_buffer *buffer)
 {
   struct ios_buffer_chunk *chunk, *chunk_next;
+
+  assert(buffer != NULL);
+
   for (int i = 0; i < IOB_BUCKET_COUNT; i++)
     {
       chunk = buffer->chunks[i];
diff --git a/libpoke/ios-dev-stream.c b/libpoke/ios-dev-stream.c
index 1258bfe5..0832011c 100644
--- a/libpoke/ios-dev-stream.c
+++ b/libpoke/ios-dev-stream.c
@@ -118,7 +118,8 @@ ios_dev_stream_close (void *iod)
 {
   struct ios_dev_stream *sio = iod;
 
-  ios_buffer_free (sio->buffer);
+  if (sio->flags & IOS_F_READ)
+    ios_buffer_free (sio->buffer);
   free (sio);
 
   return 1;
-- 
2.28.0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]