fjpanag commented on code in PR #7525:
URL: https://github.com/apache/nuttx/pull/7525#discussion_r1111041208


##########
net/usrsock/usrsock_conn.c:
##########
@@ -77,20 +78,30 @@ static dq_queue_t g_active_usrsock_connections;
 FAR struct usrsock_conn_s *usrsock_alloc(void)
 {
   FAR struct usrsock_conn_s *conn;
-#ifdef CONFIG_NET_ALLOC_CONNS
+#if CONFIG_NET_USRSOCK_ALLOC_CONNS > 0
   int i;
 #endif
 
   /* The free list is protected by a a mutex. */
 
   nxmutex_lock(&g_free_lock);
-#ifdef CONFIG_NET_ALLOC_CONNS
+#if CONFIG_NET_USRSOCK_ALLOC_CONNS > 0
   if (dq_peek(&g_free_usrsock_connections) == NULL)
     {
-      conn = kmm_zalloc(sizeof(*conn) * CONFIG_NET_USRSOCK_CONNS);
+#if CONFIG_NET_USRSOCK_MAX_CONNS > 0
+      if (dq_count(&g_active_usrsock_connections) +
+          CONFIG_NET_USRSOCK_ALLOC_CONNS >= CONFIG_NET_USRSOCK_MAX_CONNS)
+        {
+          nxmutex_unlock(&g_free_lock);
+          return NULL;
+        }
+#endif
+
+      conn = kmm_zalloc(sizeof(*conn) * CONFIG_NET_USRSOCK_ALLOC_CONNS);
+

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to