Patch for getroot.c
Hi,
When testing with UMEM_DEBUG set to default on Solaris, I discovered thatfind_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'
kern/emu/getroot.c +12 -5
@@ -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; }
Quoted 11 lines · Seth Goldberg
Hi,
When testing with
UMEM_DEBUGset to default on Solaris, I discovered
thatfind_root_device_from_libzfs()was maintaining a pointer to state that was freed whenzpool_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 fromgrub_guess_root_device()aren't freed after they're used.)
Applied with some changes. Patch for the parts we don't have is obviously skipped
Quoted 54 lines
=== modified file '
grub-core/kern/emu/getroot.c'kern/emu/getroot.c 2011-02-11 19:48:23 +0000 renamed from kern/emu/getroot.c 2011-01-12 02:57:53 +0000 +6
-2@@ -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/rdskone */
kern/emu/getroot.c 2011-02-11 19:48:23 +0000 renamed from kern/emu/getroot.c 2011-01-12 02:57:53 +0000 +6
-3- 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; }_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko