linux-user: Protect against allocation failure in load_symbols.

Submitted by Richard Henderson on July 29, 2010, 4:37 p.m.

Details

Message ID 1280421421-22883-1-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson July 29, 2010, 4:37 p.m.
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(-)

Comments

malc July 29, 2010, 4:55 p.m.
On Thu, 29 Jul 2010, Richard Henderson wrote:

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

Thanks. Applied.

Patch hide | download patch | download mbox

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;