* Re: [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols.
@ 2010-07-30 13:04 Jay Foad
2010-07-30 13:42 ` malc
0 siblings, 1 reply; 3+ messages in thread
From: Jay Foad @ 2010-07-30 13:04 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
> + /* 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;
> + }
If realloc() fails it leaves the original object unchanged, so can't
you just write:
t = realloc(syms, nsyms * sizeof(*syms));
if (t != NULL) {
syms = t;
}
?
Jay.
^ permalink raw reply [flat|nested] 3+ messages in thread* [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols.
@ 2010-07-29 16:37 Richard Henderson
0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2010-07-29 16:37 UTC (permalink / raw)
To: qemu-devel; +Cc: edgar.iglesias
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(-)
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;
--
1.7.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-30 13:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-30 13:04 [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols Jay Foad
2010-07-30 13:42 ` malc
-- strict thread matches above, loose matches on Subject: below --
2010-07-29 16:37 Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).