* [EDT] [PATCH] [prelink-cross] realloc fix memory leak
@ 2015-05-06 5:07 Maninder Singh
2015-09-11 14:09 ` Mark Hatle
0 siblings, 1 reply; 2+ messages in thread
From: Maninder Singh @ 2015-05-06 5:07 UTC (permalink / raw)
To: mark.hatle; +Cc: v.narang, yocto, AKHILESH KUMAR
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;
--
1.7.1
Thanks and Regards,
Maninder Singh
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [EDT] [PATCH] [prelink-cross] realloc fix memory leak
2015-05-06 5:07 [EDT] [PATCH] [prelink-cross] realloc fix memory leak Maninder Singh
@ 2015-09-11 14:09 ` Mark Hatle
0 siblings, 0 replies; 2+ messages in thread
From: Mark Hatle @ 2015-09-11 14:09 UTC (permalink / raw)
To: maninder1.s; +Cc: v.narang, yocto, AKHILESH KUMAR
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;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-11 14:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06 5:07 [EDT] [PATCH] [prelink-cross] realloc fix memory leak Maninder Singh
2015-09-11 14:09 ` Mark Hatle
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.