Skip to contentSkip to conversation

linux-user: Protect against allocation failure in load_symbols.

PATCH In review Richard Henderson 2 participants 2 messages Jul 29, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Protect against allocation failure in load_symbols.

---
 linux-user/elfload.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
linux-user/elfload.c +10 -0
index a53285a..33d776d 100644
@@ -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;
Signature · 1 line
1.7.2