From owner-freebsd-java@FreeBSD.ORG Tue Apr 8 12:20:12 2003 Return-Path: Delivered-To: freebsd-java@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9500237B401 for ; Tue, 8 Apr 2003 12:20:12 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3ACB843F93 for ; Tue, 8 Apr 2003 12:20:12 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h38JKBUp047209 for ; Tue, 8 Apr 2003 12:20:11 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h38JKBfF047208; Tue, 8 Apr 2003 12:20:11 -0700 (PDT) Date: Tue, 8 Apr 2003 12:20:11 -0700 (PDT) Message-Id: <200304081920.h38JKBfF047208@freefall.freebsd.org> To: freebsd-java@FreeBSD.org From: Larry Lansing Subject: Re: java/50729: java/jdk14: broken java.net.NetworkInterface calls (SIOCGIFCONF) X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Larry Lansing List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Apr 2003 19:20:12 -0000 The following reply was made to PR java/50729; it has been noted by GNATS. From: Larry Lansing To: FreeBSD-gnats-submit@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/