linux/drivers/media/dvb
Jesper Juhl 7e270941c8 [media] Zarlink zl10036 DVB-S: Fix mem leak in zl10036_attach
On Thu, 17 Feb 2011, Matthias Schwarzott wrote:

> On Sunday 06 February 2011, Jesper Juhl wrote:
> > If the memory allocation to 'state' succeeds but we jump to the 'error'
> > label before 'state' is assigned to fe->tuner_priv, then the call to
> > 'zl10036_release(fe)' at the 'error:' label will not free 'state', but
> > only what was previously assigned to 'tuner_priv', thus leaking the memory
> > allocated to 'state'.
> > There are may ways to fix this, including assigning the allocated memory
> > directly to 'fe->tuner_priv', but I did not go for that since the
> > additional pointer derefs are more expensive than the local variable, so I
> > just added a 'kfree(state)' call. I guess the call to 'zl10036_release'
> > might not even be needed in this case, but I wasn't sure, so I left it in.
> >
> Yeah, that call to zl10036_release can be completely eleminated.
> Another thing is: jumping to the error label only makes sense when memory was
> already allocated. So the jump in line 471 can be replaced by "return NULL",
> as the other error handling before allocation:
>         if (NULL == config) {
>                 printk(KERN_ERR "%s: no config specified", __func__);
>                 goto error;
>         }
>
> I suggest to improve the patch to clean the code up when changing that.
>
> But I am fine with commiting this patch also if you do not want to change it.
>

Thank you for your feedback. It makes a lot of sense.
Changing it is not a problem :)
How about the updated patch below?

If the memory allocation to 'state' succeeds but we jump to the 'error'
label before 'state' is assigned to fe->tuner_priv, then the call to
'zl10036_release(fe)' at the 'error:' label will not free 'state', but
only what was previously assigned to 'tuner_priv', thus leaking the memory
allocated to 'state'.
This patch fixes the leak and also does not jump to 'error:' before mem
has been allocated but instead just returns. Also some small style
cleanups.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-03-22 06:51:55 -03:00
..
b2c2 [media] i2c: Stop using I2C_CLASS_TV_DIGITAL 2010-10-21 07:54:26 -02:00
bt8xx Merge branch 'llseek' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/bkl 2010-10-22 10:52:56 -07:00
dm1105 [media] Rename all public generic RC functions from ir_ to rc_ 2010-12-29 08:16:50 -02:00
dvb-core [media] tuner-core: remove the legacy is_stereo() call 2011-03-21 20:32:00 -03:00
dvb-usb [media] af9015: reimplement firmware download 2011-03-22 04:54:58 -03:00
firewire [media] firedtv: drop obsolete backend abstraction 2011-03-21 20:32:21 -03:00
frontends [media] Zarlink zl10036 DVB-S: Fix mem leak in zl10036_attach 2011-03-22 06:51:55 -03:00
mantis [media] mantis_pci: remove asm/pgtable.h include 2011-03-03 10:15:35 -03:00
ngene [media] Move CI cxd2099 driver to staging 2011-03-21 20:31:47 -03:00
pluto2 [media] i2c: Stop using I2C_CLASS_TV_DIGITAL 2010-10-21 07:54:26 -02:00
pt1 [media] i2c: Stop using I2C_CLASS_TV_DIGITAL 2010-10-21 07:54:26 -02:00
siano [media] media: Remove unnecessary casts of usb_get_intfdata 2010-12-29 08:16:58 -02:00
ttpci [media] [v3,media] av7110: check for negative array offset 2011-01-19 11:45:54 -02:00
ttusb-budget [media] TTUSB DVB: ttusb_boot_dsp() needs to release_firmware() or it leaks memory 2011-03-21 20:32:22 -03:00
ttusb-dec USB: rename usb_buffer_alloc() and usb_buffer_free() users 2010-05-20 13:21:38 -07:00
Kconfig [media] firedtv: remove obsolete ieee1394 backend code 2011-03-21 20:32:12 -03:00
Makefile V4L/DVB: ngene: Driver compiles now 2010-02-26 15:10:53 -03:00