Skip to content
Snippets Groups Projects
Commit b03088c3 authored by Stefan Weil's avatar Stefan Weil Committed by Aurelien Jarno
Browse files

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: default avatarStefan Weil <weil@mail.berlios.de>
Signed-off-by: default avatarRiku Voipio <riku.voipio@nokia.com>
(cherry picked from commit 8d79de6e)
parent 23e4cff9
No related branches found
No related tags found
No related merge requests found
...@@ -1481,7 +1481,7 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) ...@@ -1481,7 +1481,7 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
struct elf_shdr *shdr; struct elf_shdr *shdr;
char *strings; char *strings;
struct syminfo *s; struct syminfo *s;
struct elf_sym *syms; struct elf_sym *syms, *new_syms;
shnum = hdr->e_shnum; shnum = hdr->e_shnum;
i = shnum * sizeof(struct elf_shdr); i = shnum * sizeof(struct elf_shdr);
...@@ -1550,12 +1550,14 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) ...@@ -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 that we threw away. Whether or not this has any effect on the
memory allocation depends on the malloc implementation and how memory allocation depends on the malloc implementation and how
many symbols we managed to discard. */ many symbols we managed to discard. */
syms = realloc(syms, nsyms * sizeof(*syms)); new_syms = realloc(syms, nsyms * sizeof(*syms));
if (syms == NULL) { if (new_syms == NULL) {
free(s); free(s);
free(syms);
free(strings); free(strings);
return; return;
} }
syms = new_syms;
qsort(syms, nsyms, sizeof(*syms), symcmp); qsort(syms, nsyms, sizeof(*syms), symcmp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment