From 5d5c99300d91d67c3f70058d2431a633028e3a9e Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 29 Jul 2010 09:37:01 -0700 Subject: linux-user: Protect against allocation failure in load_symbols. Cc: malc Signed-off-by: Richard Henderson Signed-off-by: malc --- linux-user/elfload.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'linux-user/elfload.c') diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a53285ae39..33d776de41 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; -- cgit v1.2.1