On Tue, Mar 03, 2020 at 05:44:54PM +0100, Daniel Kiper wrote: > On Tue, Mar 03, 2020 at 04:06:34PM +0100, Julian Andres Klode wrote: > > @@ -261,6 +279,7 @@ grub_cmd_smbios (grub_extcmd_context_t ctxt, > > > > const grub_uint8_t *structure; > > const char *value; > > + char *modified_value = NULL; > > grub_int32_t option; > > grub_int8_t field_type = -1; > > grub_uint8_t i; > > @@ -334,12 +353,17 @@ grub_cmd_smbios (grub_extcmd_context_t ctxt, > > return grub_error (GRUB_ERR_IO, > > N_("failed to retrieve the structure field")); > > > > + if (state[LINUX_OPT].set) > > + value = modified_value = linux_string (value); > > + > > /* Store or print the formatted value. */ > > if (state[SETTER_OPT].set) > > grub_env_set (state[SETTER_OPT].arg, value); > > else > > grub_printf ("%s\n", value); > > > > + grub_free(modified_value); > > I am not sure why we need modified_value if you free it immediately here...
Because `value` is `const char *` that might point to static buffers or other buffers, so we need to store this dynamically allocated string somewhere else we can free later. I guess we could also store the buffer statically with a size and realloc it if it's too small, thus reusing it and not having to free it, but this approach seemed slightly easier. -- debian developer - deb.li/jak | jak-linux.org - free software dev ubuntu core developer i speak de, en _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel