Re: [PATCH] disk/ieee1275 : Add a fix for memory leaks in ofdisk

Daniel Kiper <[email protected]> Thu, 18 Dec 2025 20:09:34 +0100
Newsgroups org.gnu.grub-devel
Message-ID <[email protected]>
On Mon, Dec 01, 2025 at 10:34:29PM +0000, Alec Brown via Grub-devel wrote:
> On Mon, December 1, 2025 at 4:41 AM, Avnish Chouhan <[email protected]> wrote:
> > Adding a fix for memory leaks. In case of overflow check fails, not freeing 'p' and 'p-
> > >grub_devpath' will result in memory leaks.
> >
> > Signed-off-by: Avnish Chouhan <[email protected]>
> > ---
> >  grub-core/disk/ieee1275/ofdisk.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
> > index dbc0f1a..3a90a71 100644
> > --- a/grub-core/disk/ieee1275/ofdisk.c
> > +++ b/grub-core/disk/ieee1275/ofdisk.c
> > @@ -93,6 +93,7 @@ ofdisk_hash_add_real (char *devpath)
> >        grub_add (sz, sizeof ("ieee1275/"), &sz))
> >      {
> >        grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device
> > path"));
> > +      grub_free (p);
> >        return NULL;
> >      }
> >
> > @@ -108,8 +109,10 @@ ofdisk_hash_add_real (char *devpath)
> >      {
> >        if (grub_add (grub_strlen (p->devpath), 3, &sz))
> >  	{
> > -	  grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open
> > path"));
> > -	  return NULL;
> > +          grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an
> > open path"));
> > +          grub_free (p->grub_devpath);
> > +          grub_free (p);
> > +          return NULL;
> >  	}
> >
> >        p->open_path = grub_malloc (sz);
> > --
> > 2.52.0
>
> LGTM! Thanks!
>
> Reviewed-by: Alec Brown <[email protected]>

Reviewed-by: Daniel Kiper <[email protected]>

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel