You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/11/20 17:16:01 UTC

[incubator-nuttx] 06/10: drivers/misc/rwbuffer: destroy nxmutex/nxsem properly

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

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

commit 74cfa7ddb90b622eb3f475fe7ded175518175e87
Author: chao an <an...@xiaomi.com>
AuthorDate: Sun Nov 20 21:58:48 2022 +0800

    drivers/misc/rwbuffer: destroy nxmutex/nxsem properly
    
    Signed-off-by: chao an <an...@xiaomi.com>
---
 drivers/misc/rwbuffer.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/misc/rwbuffer.c b/drivers/misc/rwbuffer.c
index a1b19760f5..40355e8469 100644
--- a/drivers/misc/rwbuffer.c
+++ b/drivers/misc/rwbuffer.c
@@ -814,6 +814,7 @@ int rwb_initialize(FAR struct rwbuffer_s *rwb)
       if (!rwb->wrbuffer)
         {
           ferr("Write buffer kmm_malloc(%" PRIu32 ") failed\n", allocsize);
+          nxmutex_destroy(&rwb->wrlock);
           return -ENOMEM;
         }
 
@@ -842,6 +843,19 @@ int rwb_initialize(FAR struct rwbuffer_s *rwb)
         {
           ferr("Read-ahead buffer kmm_malloc(%" PRIu32 ") failed\n",
           allocsize);
+          nxmutex_destroy(&rwb->rhlock);
+#ifdef CONFIG_DRVR_WRITEBUFFER
+          if (rwb->wrmaxblocks > 0)
+            {
+              nxmutex_destroy(&rwb->wrlock);
+            }
+
+          if (rwb->wrbuffer != NULL)
+            {
+              kmm_free(rwb->wrbuffer);
+            }
+#endif
+
           return -ENOMEM;
         }