qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols.
@ 2010-07-29 16:37 Richard Henderson
  2010-07-29 16:55 ` [Qemu-devel] " malc
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2010-07-29 16:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: edgar.iglesias

Cc: malc <av1474@comtv.ru>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 linux-user/elfload.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a53285a..33d776d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1546,7 +1546,17 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
         }
     }
 
+    /* Attempt to free the storage associated with the local symbols
+       that we threw away.  Whether or not this has any effect on the
+       memory allocation depends on the malloc implementation and how
+       many symbols we managed to discard.  */
     syms = realloc(syms, nsyms * sizeof(*syms));
+    if (syms == NULL) {
+        free(s);
+        free(strings);
+        return;
+    }
+
     qsort(syms, nsyms, sizeof(*syms), symcmp);
 
     s->disas_num_syms = nsyms;
-- 
1.7.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH] linux-user: Protect against allocation failure in load_symbols.
  2010-07-29 16:37 [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols Richard Henderson
@ 2010-07-29 16:55 ` malc
  0 siblings, 0 replies; 4+ messages in thread
From: malc @ 2010-07-29 16:55 UTC (permalink / raw)
  To: Richard Henderson; +Cc: edgar.iglesias, qemu-devel

On Thu, 29 Jul 2010, Richard Henderson wrote:

> Cc: malc <av1474@comtv.ru>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---

Thanks. Applied.

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols.
@ 2010-07-30 13:04 Jay Foad
  2010-07-30 13:42 ` malc
  0 siblings, 1 reply; 4+ messages in thread
From: Jay Foad @ 2010-07-30 13:04 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

> +    /* Attempt to free the storage associated with the local symbols
> +       that we threw away.  Whether or not this has any effect on the
> +       memory allocation depends on the malloc implementation and how
> +       many symbols we managed to discard.  */
>      syms = realloc(syms, nsyms * sizeof(*syms));
> +    if (syms == NULL) {
> +        free(s);
> +        free(strings);
> +        return;
> +    }

If realloc() fails it leaves the original object unchanged, so can't
you just write:

    t = realloc(syms, nsyms * sizeof(*syms));
    if (t != NULL) {
        syms = t;
    }

?

Jay.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols.
  2010-07-30 13:04 [Qemu-devel] " Jay Foad
@ 2010-07-30 13:42 ` malc
  0 siblings, 0 replies; 4+ messages in thread
From: malc @ 2010-07-30 13:42 UTC (permalink / raw)
  To: Jay Foad; +Cc: Richard Henderson, qemu-devel

On Fri, 30 Jul 2010, Jay Foad wrote:

> > +    /* Attempt to free the storage associated with the local symbols
> > +       that we threw away.  Whether or not this has any effect on the
> > +       memory allocation depends on the malloc implementation and how
> > +       many symbols we managed to discard.  */
> >      syms = realloc(syms, nsyms * sizeof(*syms));
> > +    if (syms == NULL) {
> > +        free(s);
> > +        free(strings);
> > +        return;
> > +    }
> 
> If realloc() fails it leaves the original object unchanged, so can't
> you just write:

Life is not as simple as one would like it to be.
http://www.mail-archive.com/qemu-devel@nongnu.org/msg22137.html

> 
>     t = realloc(syms, nsyms * sizeof(*syms));
>     if (t != NULL) {
>         syms = t;
>     }
> 
> ?
> 
> Jay.
> 

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-07-30 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-29 16:37 [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols Richard Henderson
2010-07-29 16:55 ` [Qemu-devel] " malc
  -- strict thread matches above, loose matches on Subject: below --
2010-07-30 13:04 [Qemu-devel] " Jay Foad
2010-07-30 13:42 ` malc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).