From: Mark Hatle <mark.hatle@windriver.com>
To: <maninder1.s@samsung.com>
Cc: "v.narang@samsung.com" <v.narang@samsung.com>,
yocto@yoctoproject.org, AKHILESH KUMAR <akhilesh.k@samsung.com>
Subject: Re: [EDT] [PATCH] [prelink-cross] realloc fix memory leak
Date: Fri, 11 Sep 2015 09:09:15 -0500 [thread overview]
Message-ID: <55F2E08B.1010206@windriver.com> (raw)
In-Reply-To: <205051265.113801430888822142.JavaMail.weblogic@epmlwas03a>
Merged to the staging branch.
On 5/6/15 12:07 AM, Maninder Singh wrote:
> EP-F6AA0618C49C4AEDA73BFF1B39950BAB
>
> Hi Mark,
>
> Free previously allocated memory if realloc fails.
>
> Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
> Signed-off-by: Vaneet narang <v.narang@samsung.com>
> Reviewed-by: Akhilesh Kumar <akhilesh.k@samsung.com>
> ---
> trunk/src/doit.c | 4 +++-
> trunk/src/gather.c | 4 +++-
> trunk/src/undoall.c | 4 +++-
> 3 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/trunk/src/doit.c b/trunk/src/doit.c
> index c94fc53..0995fce 100644
> --- a/trunk/src/doit.c
> +++ b/trunk/src/doit.c
> @@ -53,7 +53,7 @@ prelink_ent (struct prelink_entry *ent)
> DSO *dso;
> struct stat64 st;
> struct prelink_link *hardlink;
> - char *move = NULL;
> + char *move = NULL, *move_temp;
> size_t movelen = 0;
>
> for (i = 0; i < ent->ndepends; ++i)
> @@ -176,9 +176,11 @@ prelink_ent (struct prelink_entry *ent)
> if (len + sizeof (".#prelink#") > movelen)
> {
> movelen = len + sizeof (".#prelink#");
> + move_temp = move;
> move = realloc (move, movelen);
> if (move == NULL)
> {
> + free(move_temp);
> error (0, ENOMEM, "Could not hardlink %s to %s",
> hardlink->canon_filename, ent->canon_filename);
> movelen = 0;
> diff --git a/trunk/src/gather.c b/trunk/src/gather.c
> index c3d3128..733b49f 100644
> --- a/trunk/src/gather.c
> +++ b/trunk/src/gather.c
> @@ -64,7 +64,7 @@ gather_deps (DSO *dso, struct prelink_entry *ent)
> const char *argv[6];
> const char *envp[5];
> char *line = NULL, *p, *q = NULL;
> - const char **depends = NULL;
> + const char **depends = NULL, **depends_temp;
> size_t ndepends = 0, ndepends_alloced = 0;
> size_t len = 0;
> ssize_t n;
> @@ -261,11 +261,13 @@ gather_deps (DSO *dso, struct prelink_entry *ent)
> if (ndepends == ndepends_alloced)
> {
> ndepends_alloced += 10;
> + depends_temp = depends;
> depends =
> (const char **) realloc (depends,
> ndepends_alloced * sizeof (char *));
> if (depends == NULL)
> {
> + free(depends_temp);
> error (0, ENOMEM, "%s: Could not record dependencies",
> ent->filename);
> goto error_out;
> diff --git a/trunk/src/undoall.c b/trunk/src/undoall.c
> index 90e9240..6163da3 100644
> --- a/trunk/src/undoall.c
> +++ b/trunk/src/undoall.c
> @@ -33,7 +33,7 @@ undo_one (void **p, void *info)
> DSO *dso;
> struct stat64 st;
> struct prelink_link *hardlink;
> - char *move = NULL;
> + char *move = NULL, *move_temp;
> size_t movelen = 0;
>
> if (ent->done != 2)
> @@ -116,9 +116,11 @@ undo_one (void **p, void *info)
> if (len + sizeof (".#prelink#") > movelen)
> {
> movelen = len + sizeof (".#prelink#");
> + move_temp = move;
> move = realloc (move, movelen);
> if (move == NULL)
> {
> + free(move_temp);
> error (0, ENOMEM, "Could not hardlink %s to %s",
> hardlink->canon_filename, ent->canon_filename);
> movelen = 0;
>
prev parent reply other threads:[~2015-09-11 14:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 5:07 [EDT] [PATCH] [prelink-cross] realloc fix memory leak Maninder Singh
2015-09-11 14:09 ` Mark Hatle [this message]
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=55F2E08B.1010206@windriver.com \
--to=mark.hatle@windriver.com \
--cc=akhilesh.k@samsung.com \
--cc=maninder1.s@samsung.com \
--cc=v.narang@samsung.com \
--cc=yocto@yoctoproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.