* [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc
[not found] <1460494500-26922-1-git-send-email-mussitantesmortem@gmail.com>
@ 2016-04-12 20:55 ` Maxim Zhukov
[not found] ` <1460494500-26922-3-git-send-email-mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Maxim Zhukov @ 2016-04-12 20:55 UTC (permalink / raw)
To: linux-kernel
Cc: Michal Marek, Rob Herring, Frank Rowand, Grant Likely,
Maxim Zhukov, devicetree-compiler
This commit fixed memory leak after errors realloc.
Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
---
scripts/dtc/fdtput.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/scripts/dtc/fdtput.c b/scripts/dtc/fdtput.c
index f2197f5..1042319 100644
--- a/scripts/dtc/fdtput.c
+++ b/scripts/dtc/fdtput.c
@@ -75,8 +75,9 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
char *ptr; /* pointer to current value position */
int len; /* length of this cell/string/byte */
int ival;
- int upto; /* the number of bytes we have written to buf */
+ int upto; /* the number of bytes we have written to buf */
char fmt[3];
+ void *save_ptr = NULL; /* save pointer to realloc */
upto = 0;
@@ -96,12 +97,15 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
/* enlarge our value buffer by a suitable margin if needed */
if (upto + len > value_size) {
value_size = (upto + len) + 500;
- value = realloc(value, value_size);
- if (!value) {
+ void *save_ptr = realloc(value, value_size);
+
+ if (!save_ptr) {
+ free(value);
fprintf(stderr, "Out of mmory: cannot alloc "
"%d bytes\n", value_size);
return -1;
}
+ value = save_ptr;
}
ptr = value + upto;
--
2.7.1.1.g3617aa0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc
[not found] ` <1460494500-26922-3-git-send-email-mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-04-12 21:11 ` Rob Herring
[not found] ` <CAL_JsqKqbj+FmD2SwSsmdBW6SPoJzsP5an1o_XZAozo86ssPCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-12 21:29 ` (unknown), Maxim Zhukov
1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring @ 2016-04-12 21:11 UTC (permalink / raw)
To: Maxim Zhukov
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Michal Marek, Frank Rowand, Grant Likely,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA
On Tue, Apr 12, 2016 at 3:55 PM, Maxim Zhukov
<mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> This commit fixed memory leak after errors realloc.
>
> Signed-off-by: Maxim Zhukov <mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
> scripts/dtc/fdtput.c | 10 +++++++---
Again, your patch is against the kernel copy of dtc. It needs to be
against upstream dtc and then I can update the kernel copy once this
lands.
Rob
^ permalink raw reply [flat|nested] 4+ messages in thread
* (unknown),
[not found] ` <1460494500-26922-3-git-send-email-mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-12 21:11 ` Rob Herring
@ 2016-04-12 21:29 ` Maxim Zhukov
1 sibling, 0 replies; 4+ messages in thread
From: Maxim Zhukov @ 2016-04-12 21:29 UTC (permalink / raw)
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA
Cc: Maxim Zhukov, Rob Herring, Michal Marek, Frank Rowand,
Grant Likely
Subject: [PATCH RESEND 2/2] scripts: dtc: fix memory leak after realloc
This commit fixed memory leak after errors realloc.
Signed-off-by: Maxim Zhukov <mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
scripts/dtc/fdtput.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/scripts/dtc/fdtput.c b/scripts/dtc/fdtput.c
index f2197f5..1042319 100644
--- a/scripts/dtc/fdtput.c
+++ b/scripts/dtc/fdtput.c
@@ -75,8 +75,9 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
char *ptr; /* pointer to current value position */
int len; /* length of this cell/string/byte */
int ival;
- int upto; /* the number of bytes we have written to buf */
+ int upto; /* the number of bytes we have written to buf */
char fmt[3];
+ void *save_ptr = NULL; /* save pointer to realloc */
upto = 0;
@@ -96,12 +97,15 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
/* enlarge our value buffer by a suitable margin if needed */
if (upto + len > value_size) {
value_size = (upto + len) + 500;
- value = realloc(value, value_size);
- if (!value) {
+ void *save_ptr = realloc(value, value_size);
+
+ if (!save_ptr) {
+ free(value);
fprintf(stderr, "Out of mmory: cannot alloc "
"%d bytes\n", value_size);
return -1;
}
+ value = save_ptr;
}
ptr = value + upto;
--
2.7.1.1.g3617aa0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc
[not found] ` <CAL_JsqKqbj+FmD2SwSsmdBW6SPoJzsP5an1o_XZAozo86ssPCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-04-13 4:17 ` David Gibson
0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2016-04-13 4:17 UTC (permalink / raw)
To: Rob Herring
Cc: Maxim Zhukov,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Michal Marek, Frank Rowand, Grant Likely,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 902 bytes --]
On Tue, Apr 12, 2016 at 04:11:17PM -0500, Rob Herring wrote:
> On Tue, Apr 12, 2016 at 3:55 PM, Maxim Zhukov
> <mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > This commit fixed memory leak after errors realloc.
> >
> > Signed-off-by: Maxim Zhukov <mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > ---
> > scripts/dtc/fdtput.c | 10 +++++++---
>
> Again, your patch is against the kernel copy of dtc. It needs to be
> against upstream dtc and then I can update the kernel copy once this
> lands.
Right. TBH, I'm not particularly concerned about the leak anyway.
The memory will be freed when fdtput exits moments later, so it's
really not a big deal.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-04-13 4:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1460494500-26922-1-git-send-email-mussitantesmortem@gmail.com>
2016-04-12 20:55 ` [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc Maxim Zhukov
[not found] ` <1460494500-26922-3-git-send-email-mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-12 21:11 ` Rob Herring
[not found] ` <CAL_JsqKqbj+FmD2SwSsmdBW6SPoJzsP5an1o_XZAozo86ssPCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-13 4:17 ` David Gibson
2016-04-12 21:29 ` (unknown), Maxim Zhukov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).