All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] affs: Fix resource leaks
@ 2022-02-03  0:08 Alec Brown
  2022-02-03 11:58 ` Darren Kenny
  0 siblings, 1 reply; 3+ messages in thread
From: Alec Brown @ 2022-02-03  0:08 UTC (permalink / raw)
  To: grub-devel; +Cc: daniel.kiper, darren.kenny

In commit 178ac5107389 (affs: Fix memory leaks), fixes were made to
grub_affs_iterate_dir() to prevent memory leaks from occuring after it returns
without freeing node. However, there were still some instances where node was
causing a memory leak when the function returns after calling
grub_affs_create_node(). In this function, new memory is allocated to node but
doesn't get freed until the hook() function is called near the end. Before
hook() is called, node should be freed in grub_affs_create_node() before
returning out of it.

Fixes: 178ac5107389 (affs: Fix memory leaks)
Fixes: CID 73759

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
---
 grub-core/fs/affs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c
index cafcd0fba..7b9e62064 100644
--- a/grub-core/fs/affs.c
+++ b/grub-core/fs/affs.c
@@ -370,17 +370,26 @@ grub_affs_create_node (grub_fshelp_node_t dir,
 				  GRUB_DISK_SECTOR_SIZE - GRUB_AFFS_FILE_LOCATION,
 				  sizeof ((*node)->di), (char *) &(*node)->di);
 	    if (err)
-	      return 1;
+	      {
+		grub_free (*node);
+		return 1;
+	      }
 	    continue;
 	  }
 	default:
-	  return 0;
+	  {
+	    grub_free (*node);
+	    return 0;
+	  }
 	}
       break;
     }
 
   if (nest == 8)
-    return 0;
+    {
+      grub_free (*node);
+      return 0;
+    }
 
   type |= GRUB_FSHELP_CASE_INSENSITIVE;
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] affs: Fix resource leaks
  2022-02-03  0:08 [PATCH] affs: Fix resource leaks Alec Brown
@ 2022-02-03 11:58 ` Darren Kenny
  2022-02-04 14:34   ` Daniel Kiper
  0 siblings, 1 reply; 3+ messages in thread
From: Darren Kenny @ 2022-02-03 11:58 UTC (permalink / raw)
  To: Alec Brown, grub-devel; +Cc: daniel.kiper

Hi Alec,

Don't know how I ended up missing this originally, but thanks for fixing
it, so:

Reviewed-by: Darren Kenny <darren.kenny@oracle.com>

Thanks,

Darren.

On Wednesday, 2022-02-02 at 19:08:21 -05, Alec Brown wrote:
> In commit 178ac5107389 (affs: Fix memory leaks), fixes were made to
> grub_affs_iterate_dir() to prevent memory leaks from occuring after it returns
> without freeing node. However, there were still some instances where node was
> causing a memory leak when the function returns after calling
> grub_affs_create_node(). In this function, new memory is allocated to node but
> doesn't get freed until the hook() function is called near the end. Before
> hook() is called, node should be freed in grub_affs_create_node() before
> returning out of it.
>
> Fixes: 178ac5107389 (affs: Fix memory leaks)
> Fixes: CID 73759
>
> Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
> ---
>  grub-core/fs/affs.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c
> index cafcd0fba..7b9e62064 100644
> --- a/grub-core/fs/affs.c
> +++ b/grub-core/fs/affs.c
> @@ -370,17 +370,26 @@ grub_affs_create_node (grub_fshelp_node_t dir,
>  				  GRUB_DISK_SECTOR_SIZE - GRUB_AFFS_FILE_LOCATION,
>  				  sizeof ((*node)->di), (char *) &(*node)->di);
>  	    if (err)
> -	      return 1;
> +	      {
> +		grub_free (*node);
> +		return 1;
> +	      }
>  	    continue;
>  	  }
>  	default:
> -	  return 0;
> +	  {
> +	    grub_free (*node);
> +	    return 0;
> +	  }
>  	}
>        break;
>      }
>  
>    if (nest == 8)
> -    return 0;
> +    {
> +      grub_free (*node);
> +      return 0;
> +    }
>  
>    type |= GRUB_FSHELP_CASE_INSENSITIVE;
>  
> -- 
> 2.27.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] affs: Fix resource leaks
  2022-02-03 11:58 ` Darren Kenny
@ 2022-02-04 14:34   ` Daniel Kiper
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Kiper @ 2022-02-04 14:34 UTC (permalink / raw)
  To: Darren Kenny; +Cc: Alec Brown, grub-devel

On Thu, Feb 03, 2022 at 11:58:42AM +0000, Darren Kenny wrote:
> Hi Alec,
>
> Don't know how I ended up missing this originally, but thanks for fixing
> it, so:
>
> Reviewed-by: Darren Kenny <darren.kenny@oracle.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-04 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03  0:08 [PATCH] affs: Fix resource leaks Alec Brown
2022-02-03 11:58 ` Darren Kenny
2022-02-04 14:34   ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.