From: Maxim Zhukov <mussitantesmortem@gmail.com>
To: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>,
Grant Likely <grant.likely@linaro.org>,
linux-kernel@vger.kernel.org,
Maxim Zhukov <mussitantesmortem@gmail.com>
Subject: [PATCH 2/2] scripts: dtc: fix memory leak after realloc
Date: Tue, 12 Apr 2016 17:03:28 +0300 [thread overview]
Message-ID: <1460469808-31227-2-git-send-email-mussitantesmortem@gmail.com> (raw)
In-Reply-To: <1460469808-31227-1-git-send-email-mussitantesmortem@gmail.com>
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
next prev parent reply other threads:[~2016-04-12 14:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-12 14:03 [PATCH 1/2] scripts: genksyms: fix resource leak Maxim Zhukov
2016-04-12 14:03 ` Maxim Zhukov [this message]
2016-04-12 14:31 ` kbuild test robot
2016-04-12 14:39 ` kbuild test robot
2016-04-12 14:39 ` kbuild test robot
2016-04-12 15:18 [RESEND PATCH 0/2] scripts: small fixes Maxim Zhukov
2016-04-12 15:18 ` [PATCH 2/2] scripts: dtc: fix memory leak after realloc Maxim Zhukov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460469808-31227-2-git-send-email-mussitantesmortem@gmail.com \
--to=mussitantesmortem@gmail.com \
--cc=frowand.list@gmail.com \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome