Skip to contentSkip to conversation

scripts: small fixes

PATCH In review Maxim Zhukov 5 participants 7 messages Apr 12, 2016 – Apr 20, 2016 1 message not in the archive Device tree

lore
Share & tools
lore
#0 lore raw

v2 cover scripts: small fixes

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(-)
Signature · 1 line
2.7.1.1.g3617aa0
#1 lore raw

PATCH v2 1/2 scripts: genksyms: fix resource leak

This commit fixed resource leak at func main

---
 scripts/genksyms/genksyms.c | 3 +++
 1 file changed, 3 insertions(+)
scripts/genksyms/genksyms.c +3 -0
index dafaf96..06121ce 100644
@@ -873,5 +873,8 @@ int main(int argc, char **argv)
 			(double)nsyms / (double)HASH_BUCKETS);
 	}
 
+	if (dumpfile)
+		fclose(dumpfile);
+
 	return errors != 0;
 }
Signature · 1 line
2.7.1.1.g3617aa0
#2 lore raw

Re: [PATCH V2 1/2] scripts: genksyms: fix resource leak

Quoted 3 lines · Maxim Zhukov

This commit fixed resource leak at func main

Applied to kbuild.git#kbuild. Although the leak is harmless.

Michal

#3 lore raw

PATCH v2 2/2 scripts: dtc: fix memory leak after realloc

In reply to Maxim Zhukov

This commit fixed memory leak after errors realloc.

---
 scripts/dtc/fdtput.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
scripts/dtc/fdtput.c +7 -3
index f2197f5..1042319 100644
@@ -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;
Signature · 1 line
2.7.1.1.g3617aa0
#4 lore raw

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

Quoted 5 lines · Maxim Zhukov

This commit fixed memory leak after errors realloc.

---
 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

#5 lore raw

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

Quoted 11 lines · Rob Herring
Quoted 5 lines · Maxim Zhukov

This commit fixed memory leak after errors realloc.

---
 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.

Signature · 4 lines
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

A message that is not in the archive (sent off-list or not yet received): 1460494500-26922-3-git-send-email-mussitantesmortem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#7 lore raw

(unknown)

Subject: [PATCH RESEND 2/2] scripts: dtc: fix memory leak after realloc

This commit fixed memory leak after errors realloc.

---
 scripts/dtc/fdtput.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
scripts/dtc/fdtput.c +7 -3
index f2197f5..1042319 100644
@@ -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;
Signature · 1 line
2.7.1.1.g3617aa0