Skip to contentSkip to conversation

affs: Fix resource leaks

PATCH In review Alec Brown 3 participants 3 messages Feb 3, 2022 – Feb 4, 2022

lore
Share & tools
lore

Alec Brown

author
#0 lore raw

PATCH 1/1 affs: Fix resource leaks

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
---
 grub-core/fs/affs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
grub-core/fs/affs.c +12 -3
index cafcd0fba..7b9e62064 100644
@@ -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;
 
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Alec,

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

Thanks,

Darren.

Quoted 53 lines · Alec Brown

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
---
 grub-core/fs/affs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
grub-core/fs/affs.c +12 -3
index cafcd0fba..7b9e62064 100644
@@ -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;
 
Signature · 1 line
2.27.0