mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] state: backend_bucket_circular: fix memory leak
@ 2018-10-08 17:45 Ulrich Ölmann
  2018-10-10  5:40 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Ölmann @ 2018-10-08 17:45 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 common/state/backend_bucket_circular.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c
index 0529421a2c2f..277b94d79737 100644
--- a/common/state/backend_bucket_circular.c
+++ b/common/state/backend_bucket_circular.c
@@ -480,7 +480,8 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
 	circ->fd = open(path, O_RDWR);
 	if (circ->fd < 0) {
 		pr_err("Failed to open circular bucket '%s'\n", path);
-		return -errno;
+		ret = -errno;
+		goto out_free;
 	}
 #endif
 
@@ -489,7 +490,7 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
 		dev_info(dev, "Not using eraseblock %u, it is marked as bad (%d)\n",
 			 circ->eraseblock, ret);
 		ret = -EIO;
-		goto out_free;
+		goto out_close;
 	}
 
 	circ->bucket.read = state_backend_bucket_circular_read;
@@ -499,13 +500,15 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
 
 	ret = state_backend_bucket_circular_init(*bucket);
 	if (ret)
-		goto out_free;
+		goto out_close;
 
 	return 0;
 
-out_free:
+out_close:
 #ifndef __BAREBOX__
 	close(circ->fd);
+out_free:
+	free(circ->mtd);
 #endif
 	free(circ);
 
-- 
2.19.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] state: backend_bucket_circular: fix memory leak
  2018-10-08 17:45 [PATCH] state: backend_bucket_circular: fix memory leak Ulrich Ölmann
@ 2018-10-10  5:40 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2018-10-10  5:40 UTC (permalink / raw)
  To: Ulrich Ölmann; +Cc: Barebox List

On Mon, Oct 08, 2018 at 07:45:23PM +0200, Ulrich Ölmann wrote:
> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
> ---
>  common/state/backend_bucket_circular.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c
> index 0529421a2c2f..277b94d79737 100644
> --- a/common/state/backend_bucket_circular.c
> +++ b/common/state/backend_bucket_circular.c
> @@ -480,7 +480,8 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
>  	circ->fd = open(path, O_RDWR);
>  	if (circ->fd < 0) {
>  		pr_err("Failed to open circular bucket '%s'\n", path);
> -		return -errno;
> +		ret = -errno;
> +		goto out_free;
>  	}
>  #endif
>  
> @@ -489,7 +490,7 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
>  		dev_info(dev, "Not using eraseblock %u, it is marked as bad (%d)\n",
>  			 circ->eraseblock, ret);
>  		ret = -EIO;
> -		goto out_free;
> +		goto out_close;
>  	}
>  
>  	circ->bucket.read = state_backend_bucket_circular_read;
> @@ -499,13 +500,15 @@ int state_backend_bucket_circular_create(struct device_d *dev, const char *path,
>  
>  	ret = state_backend_bucket_circular_init(*bucket);
>  	if (ret)
> -		goto out_free;
> +		goto out_close;
>  
>  	return 0;
>  
> -out_free:
> +out_close:
>  #ifndef __BAREBOX__
>  	close(circ->fd);
> +out_free:
> +	free(circ->mtd);
>  #endif
>  	free(circ);
>  
> -- 
> 2.19.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2018-10-10  5:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-08 17:45 [PATCH] state: backend_bucket_circular: fix memory leak Ulrich Ölmann
2018-10-10  5:40 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox