Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1377180 > unrolled thread

[PATCH V2 0/2] scripts: small fixes

Started byMaxim Zhukov <mussitantesmortem@gmail.com>
First post2016-04-12 23:00 +0200
Last post2016-04-12 23:00 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH V2 0/2] scripts: small fixes Maxim Zhukov <mussitantesmortem@gmail.com> - 2016-04-12 23:00 +0200
    [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc Maxim Zhukov <mussitantesmortem@gmail.com> - 2016-04-12 23:00 +0200
      Re: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc Rob Herring <robh+dt@kernel.org> - 2016-04-12 23:20 +0200
        Re: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc David Gibson <david@gibson.dropbear.id.au> - 2016-04-13 06:20 +0200
    [PATCH V2 1/2] scripts: genksyms: fix resource leak Maxim Zhukov <mussitantesmortem@gmail.com> - 2016-04-12 23:00 +0200

#1377180 — [PATCH V2 0/2] scripts: small fixes

FromMaxim Zhukov <mussitantesmortem@gmail.com>
Date2016-04-12 23:00 +0200
Subject[PATCH V2 0/2] scripts: small fixes
Message-ID<rndzH-5be-9@gated-at.bofh.it>
This patch series fixed small bugs intro scripts folder

Maxim Zhukov (2):
  scripts: genksyms: fix resource leak
  scripts: dtc: fix memory leak after realloc

 scripts/dtc/fdtput.c        | 10 +++++++---
 scripts/genksyms/genksyms.c |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)

-- 
2.7.1.1.g3617aa0

[toc] | [next] | [standalone]


#1377184 — [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc

FromMaxim Zhukov <mussitantesmortem@gmail.com>
Date2016-04-12 23:00 +0200
Subject[PATCH V2 2/2] scripts: dtc: fix memory leak after realloc
Message-ID<rndzI-5be-23@gated-at.bofh.it>
In reply to#1377180
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

[toc] | [prev] | [next] | [standalone]


#1377246 — Re: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc

FromRob Herring <robh+dt@kernel.org>
Date2016-04-12 23:20 +0200
SubjectRe: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc
Message-ID<rndT5-5HZ-7@gated-at.bofh.it>
In reply to#1377184
On Tue, Apr 12, 2016 at 3:55 PM, Maxim Zhukov
<mussitantesmortem@gmail.com> wrote:
> This commit fixed memory leak after errors realloc.
>
> Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
> ---
>  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

[toc] | [prev] | [next] | [standalone]


#1377499 — Re: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc

FromDavid Gibson <david@gibson.dropbear.id.au>
Date2016-04-13 06:20 +0200
SubjectRe: [PATCH V2 2/2] scripts: dtc: fix memory leak after realloc
Message-ID<rnkrv-3gi-1@gated-at.bofh.it>
In reply to#1377246

[Multipart message — attachments visible in raw view] — view raw

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@gmail.com> wrote:
> > This commit fixed memory leak after errors realloc.
> >
> > Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
> > ---
> >  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

[toc] | [prev] | [next] | [standalone]


#1377192 — [PATCH V2 1/2] scripts: genksyms: fix resource leak

FromMaxim Zhukov <mussitantesmortem@gmail.com>
Date2016-04-12 23:00 +0200
Subject[PATCH V2 1/2] scripts: genksyms: fix resource leak
Message-ID<rndzJ-5be-39@gated-at.bofh.it>
In reply to#1377180
This commit fixed resource leak at func main

Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
---
 scripts/genksyms/genksyms.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index dafaf96..06121ce 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -873,5 +873,8 @@ int main(int argc, char **argv)
 			(double)nsyms / (double)HASH_BUCKETS);
 	}
 
+	if (dumpfile)
+		fclose(dumpfile);
+
 	return errors != 0;
 }
-- 
2.7.1.1.g3617aa0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web