diff options
author | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2021-02-23 09:28:52 +0100 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2021-02-23 10:10:44 +0100 |
commit | 681dd7a93356581d01b118d60e628b04a1c6457a (patch) | |
tree | dc3a40a9ad294dc31086b2bfc9a0170336e14c81 | |
parent | 1961e65358d70db5d23931f20b60f6cd95471201 (diff) | |
download | v4l-utils-681dd7a93356581d01b118d60e628b04a1c6457a.tar.gz |
libdvbv5: dvb-dev-local: better handle realloc()
The realloc() call assumes that, when realloc() succeeds,
the return pointer is identical.
This should always be the case here, as the code is reducing
the size of the struct. Yet, an assumption like that can
be dangerous, if used with a library different than the
standard glibc.
So, let's store the returned pointer.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
-rw-r--r-- | lib/libdvbv5/dvb-dev-local.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c index 71f1a0b6..a5e3979f 100644 --- a/lib/libdvbv5/dvb-dev-local.c +++ b/lib/libdvbv5/dvb-dev-local.c @@ -78,7 +78,7 @@ static int handle_device_change(struct dvb_device_priv *dvb, struct dvb_v5_fe_parms_priv *parms = (void *)dvb->d.fe_parms; struct udev_device *parent = NULL; struct dvb_dev_list dev_list = { 0 }; - struct dvb_dev_list *dvb_dev = &dev_list; + struct dvb_dev_list *d, *dvb_dev = &dev_list; enum dvb_dev_change_type type; const char *bus_type, *p, *sysname; char *buf; @@ -105,12 +105,13 @@ static int handle_device_change(struct dvb_device_priv *dvb, free(dvb->d.devices); dvb->d.devices = NULL; } else { - p = realloc(dvb->d.devices, - sizeof(*dvb->d.devices) * dvb->d.num_devices); - if (!p) { + d = realloc(dvb->d.devices, + sizeof(*dvb->d.devices) * dvb->d.num_devices); + if (!d) { dvb_logerr(_("Can't remove a device from the list of DVB devices")); return -ENODEV; } + dvb->d.devices = d; } break; } |