You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/07/28 07:46:20 UTC

[incubator-nuttx-apps] branch master updated: wireless/gs2200m: Fix freeing uninitialized memory

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f8354b0  wireless/gs2200m: Fix freeing uninitialized memory
f8354b0 is described below

commit f8354b0c036aaadc6c757d462e259c28256af0d7
Author: SPRESENSE <41...@users.noreply.github.com>
AuthorDate: Tue Jul 28 11:04:10 2020 +0900

    wireless/gs2200m: Fix freeing uninitialized memory
    
    Add initialize local variable and check the buffer is allocated before free().
---
 wireless/gs2200m/gs2200m_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/wireless/gs2200m/gs2200m_main.c b/wireless/gs2200m/gs2200m_main.c
index 01f7000..08cfc01 100644
--- a/wireless/gs2200m/gs2200m_main.c
+++ b/wireless/gs2200m/gs2200m_main.c
@@ -846,6 +846,8 @@ static int recvfrom_request(int fd, FAR struct gs2200m_s *priv,
   gs2200m_printf("%s: start (req->max_buflen=%d) \n",
                  __func__, req->max_buflen);
 
+  memset(&rmsg, 0, sizeof(rmsg));
+
   /* Check if this socket exists. */
 
   usock = gs2200m_socket_get(priv, req->usockid);
@@ -864,7 +866,6 @@ static int recvfrom_request(int fd, FAR struct gs2200m_s *priv,
       goto prepare;
     }
 
-  memset(&rmsg, 0, sizeof(rmsg));
   rmsg.buf = calloc(1, req->max_buflen);
   ASSERT(rmsg.buf);
 
@@ -953,7 +954,10 @@ err_out:
 
   gs2200m_printf("%s: *** end ret=%d \n", __func__, ret);
 
-  free(rmsg.buf);
+  if (rmsg.buf)
+    {
+      free(rmsg.buf);
+    }
 
   return ret;
 }