* [PATCH] lib: parameter: Free previous string value in param_string_set
@ 2022-06-16 12:50 Robin van der Gracht
2022-06-16 13:50 ` Sascha Hauer
0 siblings, 1 reply; 3+ messages in thread
From: Robin van der Gracht @ 2022-06-16 12:50 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox, Robin van der Gracht
When the parameter has no set function the previous (saved_value) is not
freed up on completion.
Signed-off-by: Robin van der Gracht <robin@protonic.nl>
---
lib/parameter.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/parameter.c b/lib/parameter.c
index adc3c7cdea..fe7e7b1ba4 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -262,8 +262,10 @@ static int param_string_set(struct device_d *dev, struct param_d *p, const char
value_new = strim(value_new);
*ps->value = value_new;
- if (!ps->set)
+ if (!ps->set) {
+ free(value_save);
return 0;
+ }
ret = ps->set(p, p->driver_priv);
if (ret) {
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lib: parameter: Free previous string value in param_string_set
2022-06-16 12:50 [PATCH] lib: parameter: Free previous string value in param_string_set Robin van der Gracht
@ 2022-06-16 13:50 ` Sascha Hauer
2022-06-16 15:02 ` Robin van der Gracht
0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2022-06-16 13:50 UTC (permalink / raw)
To: Robin van der Gracht; +Cc: barebox
On Thu, Jun 16, 2022 at 02:50:40PM +0200, Robin van der Gracht wrote:
> When the parameter has no set function the previous (saved_value) is not
> freed up on completion.
>
> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
> ---
> lib/parameter.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/parameter.c b/lib/parameter.c
> index adc3c7cdea..fe7e7b1ba4 100644
> --- a/lib/parameter.c
> +++ b/lib/parameter.c
> @@ -262,8 +262,10 @@ static int param_string_set(struct device_d *dev, struct param_d *p, const char
> value_new = strim(value_new);
> *ps->value = value_new;
>
> - if (!ps->set)
> + if (!ps->set) {
> + free(value_save);
> return 0;
> + }
Fixing this bug reveals another one. We do a:
value_new = xstrdup(val);
value_new = strim(value_new);
When 'val' has whitespaces at the beginning we no longer free the
pointer originally returned from xstrdup, but the pointer with
whitespaces stripped. I'll queue a fix for this before this patch.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lib: parameter: Free previous string value in param_string_set
2022-06-16 13:50 ` Sascha Hauer
@ 2022-06-16 15:02 ` Robin van der Gracht
0 siblings, 0 replies; 3+ messages in thread
From: Robin van der Gracht @ 2022-06-16 15:02 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 2022-06-16 15:50, Sascha Hauer wrote:
> On Thu, Jun 16, 2022 at 02:50:40PM +0200, Robin van der Gracht wrote:
>> When the parameter has no set function the previous (saved_value) is not
>> freed up on completion.
>>
>> Signed-off-by: Robin van der Gracht <robin@protonic.nl>
>> ---
>> lib/parameter.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/parameter.c b/lib/parameter.c
>> index adc3c7cdea..fe7e7b1ba4 100644
>> --- a/lib/parameter.c
>> +++ b/lib/parameter.c
>> @@ -262,8 +262,10 @@ static int param_string_set(struct device_d *dev,
>> struct param_d *p, const char
>> value_new = strim(value_new);
>> *ps->value = value_new;
>>
>> - if (!ps->set)
>> + if (!ps->set) {
>> + free(value_save);
>> return 0;
>> + }
>
> Fixing this bug reveals another one. We do a:
>
> value_new = xstrdup(val);
> value_new = strim(value_new);
>
> When 'val' has whitespaces at the beginning we no longer free the
> pointer originally returned from xstrdup, but the pointer with
> whitespaces stripped. I'll queue a fix for this before this patch.
Good catch.
ACK
- Robin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-16 15:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 12:50 [PATCH] lib: parameter: Free previous string value in param_string_set Robin van der Gracht
2022-06-16 13:50 ` Sascha Hauer
2022-06-16 15:02 ` Robin van der Gracht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox