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

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

commit 85680134366118955daa7c00fffada10c9ef3208
Author: Nightt <[email protected]>
AuthorDate: Sat May 23 10:24:19 2026 +0800

    netutils/thttpd: Apply the same check to related allocation sites
    
    Extend the allocation-failure check to httpd_strdup(), the thttpd-local 
wrapper that has the same failure contract as strdup().
    
    This is logically separable from the direct strdup()/asprintf() fixes: it 
prevents using hs->hostname before checking whether the wrapped string 
allocation succeeded, and releases the partially allocated server state on 
failure.
    
    The scope intentionally does not extend to malloc(), calloc(), or other raw 
allocators because #1727 specifically calls out strdup()/asprintf(), and 
covering all allocation APIs would make this PR much broader.
    
    Signed-off-by: Nightt <[email protected]>
---
 netutils/thttpd/libhttpd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c
index 1a7d46c13..8be1c6ec9 100644
--- a/netutils/thttpd/libhttpd.c
+++ b/netutils/thttpd/libhttpd.c
@@ -2163,14 +2163,15 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr 
*sa)
 #else
   hs->hostname = httpd_strdup(httpd_ntoa(sa));
 #endif
-  ninfo("hostname: %s\n", hs->hostname);
-
   if (!hs->hostname)
     {
       nerr("ERROR: out of memory copying hostname\n");
+      free_httpd_server(hs);
       return NULL;
     }
 
+  ninfo("hostname: %s\n", hs->hostname);
+
   hs->cgi_count = 0;
 
   /* Initialize listen sockets */

Reply via email to