[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/3] qdev: Refactor device_set_realized to avoid
From: |
Gonglei (Arei) |
Subject: |
Re: [Qemu-devel] [PATCH 2/3] qdev: Refactor device_set_realized to avoid resource leak |
Date: |
Wed, 20 Aug 2014 02:36:30 +0000 |
> -----Original Message-----
> From: address@hidden
> On Tue, Aug 19, 2014 at 7:41 PM, <address@hidden> wrote:
> > From: Gonglei <address@hidden>
> >
> > At present, the local variable local_err is reused at multi-places,
> > Which will cause resource leak in some scenarios.
> >
>
> The problem isn't really the local_err reusage. It's the fact that
> this function doesn't have partial cleanup implemented (the
> dc->unrealize call you add here is needed but not in original code at
> all). Doing a fuller audit of the function, it seems to have outgrown
> the simplistic if (!local_err) approach to error handling. I think the
> goto-fallthrough system might be a cleaner alternative. Perhaps finish
> the fn with:
>
> dev->realized = value;
> return;
>
> post_realize_fail:
> if (dc->unrealize) {
> dc->unrealize(dev, NULL);
> }
> fail:
> if (local_err != NULL) {
> error_propagate(errp, local_err);
> return;
> }
>
> }
>
> Then goto the appropriate error label as local_err population is
> detected as each relevant point.
>
Hi, Peter. I know your mean. vmstate_unregister() also should be called,
beside dc->unrealized().
I will re-realize as your suggestion. Thanks!
Best regards,
-Gonglei