Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1PnzAk-000854-Lv for mharc-grub-devel@gnu.org; Fri, 11 Feb 2011 15:00:54 -0500 Received: from [140.186.70.92] (port=54211 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnzAi-000840-3r for grub-devel@gnu.org; Fri, 11 Feb 2011 15:00:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PnzAh-0001EY-9X for grub-devel@gnu.org; Fri, 11 Feb 2011 15:00:52 -0500 Received: from rcsinet10.oracle.com ([148.87.113.121]:19763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PnzAg-0001Df-WB for grub-devel@gnu.org; Fri, 11 Feb 2011 15:00:51 -0500 Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id p1BK0hVR019708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Feb 2011 20:00:46 GMT Received: from acsmt353.oracle.com (acsmt353.oracle.com [141.146.40.153]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id p1BK0fTx030475 for ; Fri, 11 Feb 2011 20:00:42 GMT Received: from abhmt006.oracle.com by acsmt353.oracle.com with ESMTP id 1046709711297454440; Fri, 11 Feb 2011 12:00:40 -0800 Received: from rebs (/10.142.243.74) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 11 Feb 2011 12:00:40 -0800 Date: Fri, 11 Feb 2011 11:58:24 -0800 (PST) From: Seth Goldberg X-X-Sender: sethg@bergsoft To: grub-devel@gnu.org Message-ID: User-Agent: Alpine 2.00 (GSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Source-IP: acsmt353.oracle.com [141.146.40.153] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090203.4D55956B.0077:SCFMA4539814,ss=1,fgs=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 148.87.113.121 Subject: Patch for getroot.c X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Feb 2011 20:00:53 -0000 Hi, When testing with UMEM_DEBUG set to default on Solaris, I discovered that find_root_device_from_libzfs() was maintaining a pointer to state that was freed when zpool_close() was called (specifically, the device path string, retrieved from an nvlist). The path here fixes that and make this function a bit more bulletproof by testing for NULLs. (Note that this returns memory that is not freed by the util programs that use it, but that's not unique to this patch -- all strings from grub_guess_root_device() aren't freed after they're used.) === modified file 'grub-core/kern/emu/getroot.c' --- grub-core/kern/emu/getroot.c 2011-01-12 02:57:53 +0000 +++ grub-core/kern/emu/getroot.c 2011-02-11 19:48:23 +0000 @@ -185,7 +185,7 @@ static char * find_root_device_from_libzfs (const char *dir, struct stat *sbp) { - char *device; + char *device = NULL; char *poolname; char *poolfs; @@ -224,9 +224,13 @@ if (nvlist_lookup_string (children[i], "path", &device) != 0) error (1, errno, "nvlist_lookup_string (\"path\")"); + grub_dprintf("zfs", "device -> %s\n", device); + struct stat st; - if (stat (device, &st) == 0) + if (stat (device, &st) == 0) { + device = grub_strdup(device); break; + } device = NULL; } @@ -240,12 +244,15 @@ #if defined(__sun__) /* If the device is a /dev/dsk path, convert it into a /dev/rdsk one */ - if (strncmp(device, "/dev/dsk/", 9) == 0) { - device = xasprintf("/dev/rdsk/%s", device + 9); + if (device != NULL && strncmp(device, "/dev/dsk/", 9) == 0) { + char *newdevice = xasprintf("/dev/rdsk/%s", device + 9); + grub_free(device); + device = newdevice; } #endif - grub_util_info("zfs path = %s", device); + if (device != NULL) + grub_util_info("zfs path = %s", device); return device; }