Re: [PATCH 3/3] drivers/media/media-device: fix double free bug in _unregister()

From: Max Kellermann
Date: Wed Jun 15 2016 - 16:38:00 EST


On 2016/06/15 22:32, Shuah Khan <shuahkh@xxxxxxxxxxxxxxx> wrote:
> This change introduces memory leaks, since drivers are relying on
> media_device_unregister() to free interfaces.

This is what I thought, too, until I checked the code paths. Who adds
entries to that list? Only media_gobj_create() does, and only when
type==MEDIA_GRAPH_INTF_DEVNODE. That is called via
media_interface_init(), via media_devnode_create().

In the whole kernel, there are two calls to media_devnode_create():
one in dvbdev.c and another one in v4l2-dev.c. Both callers take care
for freeing their interface. Both would crash if somebody else would
free it for them before they get a chance to do it. Which is the very
thing my patch addresses.

Did I miss something?

Max