mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] parameter: fix memory leak
@ 2012-10-10 10:42 Jan Luebbe
  2012-10-10 10:42 ` [PATCH 2/2] parameter: support removing named parameters Jan Luebbe
  2012-10-12  8:03 ` [PATCH 1/2] parameter: fix memory leak Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Luebbe @ 2012-10-10 10:42 UTC (permalink / raw)
  To: barebox

In __dev_add_param, the name string is allocated using strdup.
Free it when removing the parameter.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 lib/parameter.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/parameter.c b/lib/parameter.c
index 3ecb480..b33ad17 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -224,6 +224,7 @@ void dev_remove_parameters(struct device_d *dev)
 	list_for_each_entry_safe(p, n, &dev->parameters, list) {
 		p->set(dev, p, NULL);
 		list_del(&p->list);
+		free(p->name);
 		free(p);
 	}
 }
-- 
1.7.10.4


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

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

* [PATCH 2/2] parameter: support removing named parameters
  2012-10-10 10:42 [PATCH 1/2] parameter: fix memory leak Jan Luebbe
@ 2012-10-10 10:42 ` Jan Luebbe
  2012-10-12  8:03 ` [PATCH 1/2] parameter: fix memory leak Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Luebbe @ 2012-10-10 10:42 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 include/param.h |    4 ++++
 lib/parameter.c |   18 ++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/param.h b/include/param.h
index e0c415d..21f4f7d 100644
--- a/include/param.h
+++ b/include/param.h
@@ -30,6 +30,8 @@ int dev_add_param(struct device_d *dev, const char *name,
 
 int dev_add_param_fixed(struct device_d *dev, char *name, char *value);
 
+void dev_remove_param(struct device_d *dev, char *name);
+
 void dev_remove_parameters(struct device_d *dev);
 
 int dev_param_set_generic(struct device_d *dev, struct param_d *p,
@@ -67,6 +69,8 @@ static inline int dev_add_param_fixed(struct device_d *dev, char *name, char *va
 	return 0;
 }
 
+static inline void dev_remove_param(struct device_d *dev, char *name) {}
+
 static inline void dev_remove_parameters(struct device_d *dev) {}
 
 static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p,
diff --git a/lib/parameter.c b/lib/parameter.c
index b33ad17..c00b824 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -213,6 +213,24 @@ int dev_add_param_fixed(struct device_d *dev, char *name, char *value)
 }
 
 /**
+ * dev_remove_param - remove a parameter from a device and free its
+ * memory
+ * @param dev	The device
+ * @param name	The name of the parameter
+ */
+void dev_remove_param(struct device_d *dev, char *name)
+{
+	struct param_d *p = get_param_by_name(dev, name);
+
+	if (p) {
+		p->set(dev, p, NULL);
+		list_del(&p->list);
+		free(p->name);
+		free(p);
+	}
+}
+
+/**
  * dev_remove_parameters - remove all parameters from a device and free their
  * memory
  * @param dev	The device
-- 
1.7.10.4


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

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

* Re: [PATCH 1/2] parameter: fix memory leak
  2012-10-10 10:42 [PATCH 1/2] parameter: fix memory leak Jan Luebbe
  2012-10-10 10:42 ` [PATCH 2/2] parameter: support removing named parameters Jan Luebbe
@ 2012-10-12  8:03 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2012-10-12  8:03 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: barebox

On Wed, Oct 10, 2012 at 12:42:50PM +0200, Jan Luebbe wrote:
> In __dev_add_param, the name string is allocated using strdup.
> Free it when removing the parameter.
> 
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>

Applied, thanks

Sascha

> ---
>  lib/parameter.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/lib/parameter.c b/lib/parameter.c
> index 3ecb480..b33ad17 100644
> --- a/lib/parameter.c
> +++ b/lib/parameter.c
> @@ -224,6 +224,7 @@ void dev_remove_parameters(struct device_d *dev)
>  	list_for_each_entry_safe(p, n, &dev->parameters, list) {
>  		p->set(dev, p, NULL);
>  		list_del(&p->list);
> +		free(p->name);
>  		free(p);
>  	}
>  }
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> 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] 3+ messages in thread

end of thread, other threads:[~2012-10-12  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-10 10:42 [PATCH 1/2] parameter: fix memory leak Jan Luebbe
2012-10-10 10:42 ` [PATCH 2/2] parameter: support removing named parameters Jan Luebbe
2012-10-12  8:03 ` [PATCH 1/2] parameter: fix memory leak Sascha Hauer

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