diff mbox series

[1/1] diskpart: fix context memory leak in hybrid mode

Message ID 20211029050956.59817-1-james.hilliard1@gmail.com
State Accepted
Headers show
Series [1/1] diskpart: fix context memory leak in hybrid mode | expand

Commit Message

James Hilliard Oct. 29, 2021, 5:09 a.m. UTC
It appears that fdisk_unref_context doesn't automatically free
the parent context, so we need to do so explicitely.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 handlers/diskpart_handler.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Stefano Babic Oct. 29, 2021, 8:41 a.m. UTC | #1
On 29.10.21 07:09, James Hilliard wrote:
> It appears that fdisk_unref_context doesn't automatically free
> the parent context, so we need to do so explicitely.
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>   handlers/diskpart_handler.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
> index f9327b5..e08c10e 100644
> --- a/handlers/diskpart_handler.c
> +++ b/handlers/diskpart_handler.c
> @@ -739,6 +739,13 @@ static int diskpart_write_table(struct fdisk_context *cxt, struct create_table *
>   	return ret;
>   }
>   
> +static void diskpart_unref_context(struct fdisk_context *cxt)
> +{
> +	if (IS_HYBRID(cxt))
> +		fdisk_unref_context(PARENT(cxt));
> +	fdisk_unref_context(cxt);
> +}
> +
>   static int diskpart(struct img_type *img,
>   	void __attribute__ ((__unused__)) *data)
>   {
> @@ -945,7 +952,7 @@ handler_exit:
>   			WARN("Error deassign device %s", img->device);
>   
>   handler_release:
> -	fdisk_unref_context(cxt);
> +	diskpart_unref_context(cxt);
>   
>   	/*
>   	 * Kernel rereads the partition table and add just a delay to be sure
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index f9327b5..e08c10e 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -739,6 +739,13 @@  static int diskpart_write_table(struct fdisk_context *cxt, struct create_table *
 	return ret;
 }
 
+static void diskpart_unref_context(struct fdisk_context *cxt)
+{
+	if (IS_HYBRID(cxt))
+		fdisk_unref_context(PARENT(cxt));
+	fdisk_unref_context(cxt);
+}
+
 static int diskpart(struct img_type *img,
 	void __attribute__ ((__unused__)) *data)
 {
@@ -945,7 +952,7 @@  handler_exit:
 			WARN("Error deassign device %s", img->device);
 
 handler_release:
-	fdisk_unref_context(cxt);
+	diskpart_unref_context(cxt);
 
 	/*
 	 * Kernel rereads the partition table and add just a delay to be sure