aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorStefan Weil <weil@mail.berlios.de>2011-01-17 21:36:06 +0100
committerRiku Voipio <riku.voipio@nokia.com>2011-02-09 09:05:48 +0200
commiteee37d310c1e53698e317e76db53c63f6bf62af0 (patch)
treeb720c3aea6d4625ad705ee5f6f4fb266f4126a98 /linux-user
parent28637533d655b1427d3ebfc1dc3ac4f1b16dfa86 (diff)
linux-user: Fix possible realloc memory leak
Extract from "man realloc": "If realloc() fails the original block is left untouched; it is not freed or moved." Fix a possible memory leak (reported by cppcheck). Cc: Riku Voipio <riku.voipio@iki.fi> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/elfload.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 33d776de41..08c44d8933 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1481,7 +1481,7 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
struct elf_shdr *shdr;
char *strings;
struct syminfo *s;
- struct elf_sym *syms;
+ struct elf_sym *syms, *new_syms;
shnum = hdr->e_shnum;
i = shnum * sizeof(struct elf_shdr);
@@ -1550,12 +1550,14 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
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) {
+ new_syms = realloc(syms, nsyms * sizeof(*syms));
+ if (new_syms == NULL) {
free(s);
+ free(syms);
free(strings);
return;
}
+ syms = new_syms;
qsort(syms, nsyms, sizeof(*syms), symcmp);