java/50729: java/jdk14: broken java.net.NetworkInterface calls (SIOCGIFCONF)

Larry Lansing lansil at fuzzynerd.com
Tue Apr 8 12:20:12 PDT 2003


The following reply was made to PR java/50729; it has been noted by GNATS.

From: Larry Lansing <lansil at fuzzynerd.com>
To: FreeBSD-gnats-submit at FreeBSD.org
Cc:  
Subject: Re: java/50729: java/jdk14: broken java.net.NetworkInterface calls (SIOCGIFCONF)
Date: Tue, 8 Apr 2003 15:11:00 -0400

 Oops.  Forgot to add a "free" to the first call to the SIOCGIFCONF
 ioctl.  Use this patch instead.
 
 +5 points for writing a useful patch in a PR.  -10 points for
 including a memory leak.
 
 --- NetworkInterface.c.orig     Sat Apr  5 12:30:32 2003
 +++ NetworkInterface.c  Tue Apr  8 15:04:32 2003
 @@ -488,14 +488,25 @@
      /* need to do a dummy SIOCGIFCONF to determine the buffer size.
       * SIOCGIFCOUNT doesn't work
       */
 -    ifc.ifc_buf = NULL;
 +    buf = (char *)malloc(32768);
 +    if (!buf) {
 +        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
 +        (void) close(sock);
 +        return ifs;
 +    }
 +
 +    ifc.ifc_buf = buf;
 +    ifc.ifc_len = 32768;
 +
      if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
          NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
                           "ioctl SIOCGIFCONF failed");
          close(sock);
 +        free(buf);
          return ifs;
      }
      bufsize = ifc.ifc_len;
 +    free(buf);
  #else
      if (ioctl(sock, SIOCGIFNUM, (char *)&numifs) < 0) {
          NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
 
 -- 
 Lawrence S. Lansing
 Project Links Technical Manager
 RPI Math Department
 http://links.math.rpi.edu/


More information about the freebsd-java mailing list