qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] linux-user: Protect against allocation failure


From: Jay Foad
Subject: Re: [Qemu-devel] [PATCH] linux-user: Protect against allocation failure in load_symbols.
Date: Fri, 30 Jul 2010 14:04:38 +0100

> +    /* 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]