Nmap Development mailing list archives

[checker] nmap: possible memory leak in nsi_new2


From: Ted Kremenek <kremenek () cs stanford edu>
Date: Tue, 2 May 2006 01:25:26 -0700

Hello again,

My tool flagged another potential memory leak in nsi_new2 when the  
call to dup() fails:

file: nsock/src/nsock_iod.c
function: nsi_new2

Suggested fix: check to see if nsi has been allocated (use an  
additional pointer or flag?) and then free it on the error path of  
calling dup.

nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {

[ SNIP]

==> nsi allocated memory (LINE 89)

   if (!nsi) nsi = (msiod * ) safe_malloc(sizeof(msiod));

   memset(nsi, 0, sizeof(*nsi));

   if (sd == -1) {
     nsi->sd = -1;
     nsi->state = NSIOD_STATE_INITIAL;
   } else {
     nsi->sd = dup(sd);

==> call to dup fails, the allocated block for nsi is leaked

     if (nsi->sd == -1) return NULL;
     nsock_unblock_socket(nsi->sd);
     nsi->state = NSIOD_STATE_UNKNOWN;
   }



_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev


Current thread: