* [PATCH] commands: of_property: do not free data in general
@ 2018-08-27 13:57 Oleg.Karfich
2018-08-27 14:57 ` Baeuerle, Florian
0 siblings, 1 reply; 3+ messages in thread
From: Oleg.Karfich @ 2018-08-27 13:57 UTC (permalink / raw)
To: barebox; +Cc: Oleg.Karfich
With commit 748d1b8 the function do_of_property_set_now is introduced. With this
commit an unwanted free(data) is added wich leads to that an free on the value
is done that is previously set to the property. As a consequence the command
of_dump reads freed data an printis the value as hex. Fix this by moving
free(data) to the right place like before the above commit.
Signed-off-by: Oleg Karfich <oleg.karfich@wago.com>
---
commands/of_property.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/commands/of_property.c b/commands/of_property.c
index 8ce12e5..ea32e51 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -275,10 +275,12 @@ static int do_of_property_set_now(struct device_node *root, const char *path,
pp->value_const = NULL;
/* limit property data to the actual size */
- if (len)
+ if (len) {
pp->value = xrealloc(data, len);
- else
+ } else {
pp->value = NULL;
+ free(data);
+ }
pp->length = len;
} else {
@@ -374,7 +376,6 @@ static int do_of_property(int argc, char *argv[])
free(data);
} else {
ret = do_of_property_set_now(NULL, path, propname, data, len);
- free(data);
}
return ret;
--
2.7.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] commands: of_property: do not free data in general
2018-08-27 13:57 [PATCH] commands: of_property: do not free data in general Oleg.Karfich
@ 2018-08-27 14:57 ` Baeuerle, Florian
2018-08-28 6:53 ` Oleg.Karfich
0 siblings, 1 reply; 3+ messages in thread
From: Baeuerle, Florian @ 2018-08-27 14:57 UTC (permalink / raw)
To: barebox, Oleg.Karfich
Hello Oleg,
(I wrote that patch.)
You are right, it works only if the property does not already exist.
In that case we'd probably also need a free() in the else-branch,
where of_new_property is called (otherwise we have a leak), because
that actually copies what is contained in data.
Sorry for that regression.
Best Regards
Florian
Am Montag, den 27.08.2018, 13:57 +0000 schrieb Oleg.Karfich@wago.com:
> With commit 748d1b8 the function do_of_property_set_now is introduced. With this
> commit an unwanted free(data) is added wich leads to that an free on the value
> is done that is previously set to the property. As a consequence the command
> of_dump reads freed data an printis the value as hex. Fix this by moving
> free(data) to the right place like before the above commit.
>
> Signed-off-by: Oleg Karfich <oleg.karfich@wago.com>
> ---
> commands/of_property.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/commands/of_property.c b/commands/of_property.c
> index 8ce12e5..ea32e51 100644
> --- a/commands/of_property.c
> +++ b/commands/of_property.c
> @@ -275,10 +275,12 @@ static int do_of_property_set_now(struct device_node *root, const char *path,
> pp->value_const = NULL;
>
> /* limit property data to the actual size */
> - if (len)
> + if (len) {
> pp->value = xrealloc(data, len);
> - else
> + } else {
> pp->value = NULL;
> + free(data);
> + }
>
> pp->length = len;
> } else {
> @@ -374,7 +376,6 @@ static int do_of_property(int argc, char *argv[])
> free(data);
> } else {
> ret = do_of_property_set_now(NULL, path, propname, data, len);
> - free(data);
> }
>
> return ret;
_______________________________________________
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] commands: of_property: do not free data in general
2018-08-27 14:57 ` Baeuerle, Florian
@ 2018-08-28 6:53 ` Oleg.Karfich
0 siblings, 0 replies; 3+ messages in thread
From: Oleg.Karfich @ 2018-08-28 6:53 UTC (permalink / raw)
To: Florian.Baeuerle, barebox
On 27.08.2018 16:57, Baeuerle, Florian wrote:
> Hello Oleg,
Hi Florian,
>
> You are right, it works only if the property does not already exist.
> In that case we'd probably also need a free() in the else-branch,
> where of_new_property is called (otherwise we have a leak), because
> that actually copies what is contained in data.
You are right, too. Sorry missed this path. V2 is comming soon...
>
> Sorry for that regression.
No problem :-)
> Best Regards
> Florian
Regards
Oleg
>
> Am Montag, den 27.08.2018, 13:57 +0000 schrieb Oleg.Karfich@wago.com:
>> With commit 748d1b8 the function do_of_property_set_now is introduced. With this
>> commit an unwanted free(data) is added wich leads to that an free on the value
>> is done that is previously set to the property. As a consequence the command
>> of_dump reads freed data an printis the value as hex. Fix this by moving
>> free(data) to the right place like before the above commit.
>>
>> Signed-off-by: Oleg Karfich <oleg.karfich@wago.com>
>> ---
>> commands/of_property.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/commands/of_property.c b/commands/of_property.c
>> index 8ce12e5..ea32e51 100644
>> --- a/commands/of_property.c
>> +++ b/commands/of_property.c
>> @@ -275,10 +275,12 @@ static int do_of_property_set_now(struct device_node *root, const char *path,
>> pp->value_const = NULL;
>>
>> /* limit property data to the actual size */
>> - if (len)
>> + if (len) {
>> pp->value = xrealloc(data, len);
>> - else
>> + } else {
>> pp->value = NULL;
>> + free(data);
>> + }
>>
>> pp->length = len;
>> } else {
>> @@ -374,7 +376,6 @@ static int do_of_property(int argc, char *argv[])
>> free(data);
>> } else {
>> ret = do_of_property_set_now(NULL, path, propname, data, len);
>> - free(data);
>> }
>>
>> return ret;
_______________________________________________
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:[~2018-08-28 6:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-27 13:57 [PATCH] commands: of_property: do not free data in general Oleg.Karfich
2018-08-27 14:57 ` Baeuerle, Florian
2018-08-28 6:53 ` Oleg.Karfich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox